~pragmatic-core/pragmatic/scaling_optimisation_openmp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#  Copyright (C) 2010 Imperial College London and others.
#
#  Please see the AUTHORS file in the main source directory for a
#  full list of copyright holders.
#
#  Gerard Gorman
#  Applied Modelling and Computation Group
#  Department of Earth Science and Engineering
#  Imperial College London
#
#  g.gorman@imperial.ac.uk
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions
#  are met:
#  1. Redistributions of source code must retain the above copyright
#  notice, this list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above
#  copyright notice, this list of conditions and the following
#  disclaimer in the documentation and/or other materials provided
#  with the distribution.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
#  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
#  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
#  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
#  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
#  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
#  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
#  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#  SUCH DAMAGE.

dnl Process this file with autoconf to produce a configure script.

AC_INIT(Makefile.in)

LT_INIT
AC_SUBST([LIBTOOL_DEPS])

AC_CONFIG_MACRO_DIR([m4])

# Check system type
AC_CANONICAL_HOST

AC_LANG_PUSH([C++])

# Override autoconf defaults for ...FLAGS before searching for compiler
FCFLAGS="${FCFLAGS:-}"
CXXFLAGS="${CXXFLAGS:-}"
CFLAGS="${CFLAGS:-}"
CPPFLAGS="${CPPFLAGS:-}"

if test -z "$FC" && test -n "$MPIFC"; then
    FC="$MPIFC"
fi

if test -z "$CXX" && test -n "$MPICXX"; then
    CXX="$MPICXX"
fi

if test -z "$CC" && test -n "$MPICC"; then
    CC="$MPICC"
fi

AC_PROG_CXX([icpc FCC g++])
LX_FIND_MPI
# AX_MPI
CXX="$MPICXX"
LIBS="$LIBS $MPI_CXXLDFLAGS"

LINKER_CXX=$CXX

AC_LANG_PUSH([C])
AC_PROG_FC([icc fc gcc])
AX_MPI
CC="$MPICC"
LIBS="$MPILIBS $LIBS"
AC_LANG_POP()

AC_LANG_PUSH([Fortran])
AC_PROG_FC([ifort frt gfortran])
AX_MPI
FC="$MPIFC"
LIBS="$MPILIBS $LIBS"
AC_LANG_POP()

LINKER_FC=$FC

# autoconf sets GCC=yes for icc/icpc. Therefore we need an additional
# check to determine if this is the intel compiler.
AC_CHECK_DEFINED(__INTEL_COMPILER, [ICPC="yes"], [])

# Check for Fujitsu compiler
AC_CHECK_DEFINED(__FCC_VERSION, [FCC="yes"], [])

AC_PROG_CPP

AC_OPENMP()

AC_LANG_PUSH([C])
AC_OPENMP()
AC_LANG_POP()

AC_LANG_PUSH([Fortran])
AC_OPENMP()
AC_LANG_POP()

AC_SUBST(OPENMP_CXXFLAGS)

AC_PROG_INSTALL
AC_CHECK_PROG(AR, ar, ar, ,$PATH)
test -n "$ARFLAGS" || ARFLAGS="cr"

AC_CHECK_PROG(MAKE, gmake, gmake, make, $PATH)

AC_ARG_ENABLE(fortran,
    [AC_HELP_STRING([--enable-fortran],
	    [enable Fortran interface (default)])])
USING_FORTRAN="yes"
if test "x$enable_fortran" = "xno" ; then
   USING_FORTRAN="no"
fi
AC_SUBST(USING_FORTRAN)

AC_ARG_ENABLE(debugging,
    [AC_HELP_STRING([--enable-debugging],
	    [turns on debugging flags])])

if test "x$ICPC" = "xyes" ; then
    if test "$enable_debugging" = "yes" ; then
        CXXFLAGS="-g -O0 -Wall $CXXFLAGS"
        CFLAGS="-g -O0 -Wall $CFLAGS"
        FCFLAGS="-g -O0 -Wall $FCFLAGS"
        LDFLAGS="-g $LDFLAGS"
    else
        CXXFLAGS="-O2 $CXXFLAGS -diag-disable all -w -vec-report0 -openmp-report0"
        CFLAGS="-O2 $CFLAGS -diag-disable all -w -vec-report0 -openmp-report0"
        FCFLAGS="-O2 $FCFLAGS -diag-disable all -w -vec-report0 -openmp-report0"
        CPPFLAGS="$CPPFLAGS -DNDEBUG"
    fi
elif test "x$FCC" = "xyes" ; then
    AC_DEFINE([COMPILER_FUJITSU])

    CXXFLAGS="$CXXFLAGS -w"
    CFLAGS="$CFLAGS -w"
    FCFLAGS="$FCFLAGS"
    LINKER_FC="$LINKER_CXX --linkfortran"
    if test "$enable_debugging" = "yes" ; then
        CXXFLAGS="-g -O0 $CXXFLAGS"
        CFLAGS="-g -O0 $CFLAGS"
        FCFLAGS="-g -O0 $FCFLAGS"
        LDFLAGS="-g $LDFLAGS"
    else
        CXXFLAGS="-O3 $CXXFLAGS"
        CFLAGS="-O3 $CFLAGS"
        FCFLAGS="-O3 $FCFLAGS"
        CPPFLAGS="$CPPFLAGS -DNDEBUG"
    fi
elif test "x$GCC" = "xyes" ; then
    CXXFLAGS="$CXXFLAGS -Wall -Wno-deprecated"
    if test "$enable_debugging" = "yes" ; then
        CXXFLAGS="-g -O0 $CXXFLAGS"
        CFLAGS="-g -O0 $CFLAGS"
        FCFLAGS="-g -O0 $FCFLAGS"
        LDFLAGS="-g $LDFLAGS"
    else
        CXXFLAGS="-O3 -fexpensive-optimizations -funsafe-math-optimizations -fno-rounding-math $CXXFLAGS"
        CPPFLAGS="$CPPFLAGS -DNDEBUG"
    fi
fi

AC_CHECK_LIB(stdc++,fclose,,) 
AC_CHECK_LIB(m,sin,,)
AC_CHECK_LIB(numa,numa_alloc,,AC_MSG_WARN([No NUMA support available.]))

AC_CHECK_LIB(tcmalloc,malloc,,AC_MSG_WARN([No tcmalloc support available.]))
# AC_CHECK_LIB(tbbmalloc,malloc,,AC_MSG_WARN([No TBB malloc support available.]))

AC_ARG_WITH(metis, [AS_HELP_STRING([--with-metis=METIS_ROOT], [root installation of METIS])])
if test -n "$with_metis" ; then
  LIBS="$LIBS -L$with_metis/lib"
  CPPFLAGS="$CPPFLAGS -I$with_metis/include"
fi
AC_CHECK_LIB(metis,METIS_NodeND,,AC_MSG_ERROR([No METIS support available.]))

AC_ARG_WITH(parmetis, [AS_HELP_STRING([--with-parmetis=PARMETIS_ROOT], [root installation of PARMETIS])])
if test -n "$with_parmetis" ; then
  LIBS="$LIBS -L$with_parmetis/lib"
  CPPFLAGS="$CPPFLAGS -I$with_parmetis/include"
fi
AC_CHECK_LIB(parmetis,ParMETIS_V3_PartKway,,AC_MSG_WARN([No ParMETIS support available.]))

# Detect VTK
AC_CHECK_LIB(dl, dlopen)

if test -n "$VTK_LIBS" ; then
    LIBS="$LIBS -L$VTK_LIBS"
fi
for i in $VTK_INCLUDE $(ls -d /usr/include/vtk*); do
    if test -r $i/vtkCellData.h; then
        CPPFLAGS="-I$i $CPPFLAGS"
    fi
done

AC_CHECK_HEADER(vtkVersion.h,
    [AC_DEFINE([HAVE_VTK])])

AC_MSG_CHECKING([for libvtksys])
old_libs="$LIBS"
LIBS="-lvtksys $LIBS"
AC_LINK_IFELSE([
        AC_LANG_PROGRAM(
            [[
#include "vtksys/Directory.hxx"
                    ]],
            [[      
                    vtksys::Directory dir;
                    ]])
        ],
    [AC_MSG_RESULT([yes])],
    [LIBS="$old_libs" ; AC_MSG_RESULT([no])])

AC_MSG_CHECKING([for libvtkCommon])
old_libs="$LIBS"
LIBS="-lvtkCommon $LIBS"
AC_LINK_IFELSE([
        AC_LANG_PROGRAM(
            [[
#include <vtkQuadric.h>
                    ]],
            [[
                    vtkQuadric *q=vtkQuadric::New();
                    ]])
        ],
    [AC_MSG_RESULT([yes])],
    [LIBS="$old_libs" ; AC_MSG_RESULT([no])])

AC_MSG_CHECKING([for libvtkFiltering])
old_libs="$LIBS"

LIBS="-lvtkFiltering $LIBS"
AC_LINK_IFELSE([
        AC_LANG_PROGRAM(
            [[
#include <vtkVersion.h>
#include <vtkUnstructuredGrid.h>
                    ]],
            [[
                    vtkVersion::GetVTKMajorVersion();
                    vtkUnstructuredGrid *ug=vtkUnstructuredGrid::New();
                    ]])
        ],
    [AC_MSG_RESULT([yes])],
    [LIBS="$old_libs" ; AC_MSG_RESULT([no])])

AC_MSG_CHECKING([for libvtkGraphics])
old_libs="$LIBS"
LIBS="-lvtkGraphics $LIBS"
AC_LINK_IFELSE([
        AC_LANG_PROGRAM(
            [[
#include <vtkCellDataToPointData.h>
                    ]],
            [[
                    vtkCellDataToPointData *c=vtkCellDataToPointData::New();
                    ]])
        ],
    [AC_MSG_RESULT([yes])],
    [LIBS="$old_libs" ; AC_MSG_RESULT([no])])

AC_CHECK_LIB(vtkzlib, vtk_zlib_gzopen,,)
AC_CHECK_LIB(vtkexpat, vtk_expat_XML_ExpatVersion)

AC_MSG_CHECKING([for libvtkIO])
old_libs="$LIBS"
LIBS="-lvtkIO $LIBS"
AC_LINK_IFELSE([
        AC_LANG_PROGRAM(
            [[
#include <vtkXMLUnstructuredGridWriter.h>
                    ]],
            [[
                    vtkXMLUnstructuredGridWriter *c=vtkXMLUnstructuredGridWriter::New();
                    ]])
        ],
    [AC_MSG_RESULT([yes])],
    [LIBS="$old_libs" ; AC_MSG_RESULT([no])])

# CUDA support
############################################
# NVIDIA Cuda Compiler detection and setup #
############################################
AC_ARG_ENABLE(cuda, 
        AS_HELP_STRING([--enable-cuda=ARCH], [Enable cuda based modules for architecture ARCH (see nvcc option -arch).]),[

        # Search nvcc compiler
        AC_PATH_PROG(NVCC, nvcc, "no")
        AS_IF([test "x$NVCC" = "xno"],[
                        AC_MSG_ERROR([NVCC compiler not found!])
        ])

        # Check nvcc version, should be 4.x
        AS_IF([nvcc --version | grep -q "release 4"],
                        [],
                        [AC_MSG_WARN([NVCC compiler version is NOT 3.0!])
        ])

        # If $with_cuda is not empty, set to CUDA_ARCH to
        # supplied value, else set to value sm_11
        AS_IF([test "x$enableval" = "xyes"],[
                        CUDA_ARCH=" -arch=sm_11"
        ],[
                CUDA_ARCH=" -arch=$enableval"
        ])

                # Set CUDA_CFLAGS to $NVCC, where substring "bin/nvcc"
                # is substituted by "include".
                CUDA_CFLAGS=" -I${NVCC/'bin/nvcc'/include}"

                #Set CUDA_CFLAGS to $NVCC, where substring "bin/nvcc"
                #is substituted by "lib".
                CUDA_LIBS=" -L${NVCC/'bin/nvcc'/lib}"

                # If $build_cpu contains "_64", append "64" to CUDA_LIBS
        AS_IF([echo $build_cpu | grep -q "_64"],
                [CUDA_LIBS+="64"])

                # Append " -lcudart" to CUDA_LIBS
                CUDA_LIBS+=" -lcudart"

        # Symbolize that cuda is wanted
        with_cuda=$enableval

        # Make variables available in Makefile.am
        AC_SUBST(CUDA_CFLAGS)
        AC_SUBST(CUDA_LIBS)
        AC_SUBST(NVCC)
])
# Set this conditional if cuda is wanted
if test -n "$with_cuda" ; then
    ENABLE_CUDA=yes
    AC_SUBST(ENABLE_CUDA)
fi

# Set up compilation flags for cuda compiler nvcc, if with_cuda is set
AS_IF([test -n "$with_cuda"],[

        # If debug flag is set apply debugging compilation flags, otherwise build compilation flags
        AS_IF([test "x$DEBUG" = "xtrue"],
                [NVCCFLAGS="-g --compiler-options -fno-strict-aliasing --compiler-options -fno-inline"],
                [NVCCFLAGS="-O3 -use_fast_math --compiler-options -fno-strict-aliasing --compiler-options -fno-inline"])

        # Add architecture to flags
        NVCCFLAGS+=" $CUDA_ARCH"

        # If device emulation was set, add deviceemu flag
        AS_IF([test "x$EMULATION" = "xtrue"],
                [NVCCFLAGS+=" -deviceemu"])

])
# Make NVCCFLAGS available in Makefile.am
AC_SUBST(NVCCFLAGS)

AC_SUBST(LINKER_CXX)
AC_SUBST(LINKER_FC)

AC_SUBST(ARFLAGS)

AC_CHECK_HEADERS(boost/unordered_map.hpp)

AC_CHECK_HEADERS(metis.h, [], [
AC_CHECK_HEADERS(metis/metis.h)
])

AC_CHECK_HEADERS(parmetis.h)

AC_C_CONST
AC_C_INLINE

AC_OUTPUT(Makefile
    src/Makefile
    tests/Makefile
    docs/Makefile)

cat > include/pragmatic_config.h << EOF
#ifndef PRAGMATIC_CONFIG_H
#define PRAGMATIC_CONFIG_H

#if _OPENMP >= 201107
#define pragmatic_omp_atomic_capture() _Pragma("omp atomic capture")
#else
#define pragmatic_omp_atomic_capture() _Pragma("omp critical")
#endif

EOF
cat confdefs.h | grep "^#[dua][enl][fdl][ieo][nfw]" >> include/pragmatic_config.h
cat >> include/pragmatic_config.h << EOF
#endif
EOF