configure.ac 17.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([SCT], [1.0], [bockelmann@dkrz.de], [], [https://redmine.dkrz.de/doc/sct/html/index.html])
LIB_CURRENT=1
LIB_REVISION=0
LIB_AGE=0
AC_SUBST(LIB_CURRENT)
AC_SUBST(LIB_REVISION)
AC_SUBST(LIB_AGE)

# Checks for system.
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_MACRO_DIR([m4])
16
AC_CANONICAL_SYSTEM
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

AM_INIT_AUTOMAKE([1.14 silent-rules no-dependencies])
AM_EXTRA_RECURSIVE_TARGETS([doc])
AC_CONFIG_SRCDIR([src/sct_reporter.c])

LT_INIT([pic-only])

#
# information on the package
#

# MPI
AC_ARG_ENABLE([mpi],
              [AS_HELP_STRING([--enable-mpi],
                              [compile with MPI support. If none is found, MPI is not used @<:@default: no@:>@])],
              [case "${enableval}" in
                 yes) mpi=true
                      AC_DEFINE([HAVE_MPI], 1, [MPI parallel enabled])
                      ;;
                 no)  mpi=false ;;
                 *) AC_MSG_ERROR([bad value '${enableval}' for --enable-mpi]) ;;
               esac],
            [mpi=false])

# OpenMP
AC_ARG_ENABLE([openmp],
              [AS_HELP_STRING([--enable-openmp],
                              [enable OpenMP parallel timer @<:@default: false@:>@])],
              [case "${enableval}" in
                 yes) openmp=true
                      AC_DEFINE([HAVE_OPENMP], 1, [OpenMP parallel enabled])
                      ;;
                 no)  openmp=false ;;
                 *) AC_MSG_ERROR([bad value ${enableval} for --enable-openmp]) ;;
               esac],
              [openmp=false])

AM_CONDITIONAL([OPENMP], [test x"$openmp" = xtrue])
AM_CONDITIONAL([MPI],    [test x"$mpi"    = xtrue])

# DEBUG
AC_ARG_ENABLE([debug],
              [AS_HELP_STRING([--enable-debug],
                              [enable debug mode @<:@default: no@:>@])],
              [case "${enableval}" in
                 yes) debug=true
                      AC_DEFINE([DEBUG], 1, [DEBUG mode enabled])
                      ;;
                 no)  debug=false ;;
                 *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
               esac],
              [debug=false])

# CHECK_TIMER
AC_ARG_ENABLE([check-timer],
              [AS_HELP_STRING([--enable-check-timer],
                              [set in order to check usage of sct (spoils the accuracy of the performance measurements) @<:@default: no@:>@])],
              [case "${enableval}" in
                 yes) checktimer=true
                      AC_DEFINE([CHECK_TIMER], 1, [CHECK_TIMER mode enabled])
                      ;;
                 no)  checktimer=false ;;
                 *) AC_MSG_ERROR([bad value ${enableval} for --enable-check-timer]) ;;
               esac],
              [checktimer=false])

# NESTED_TIMER
AC_ARG_ENABLE([nested-timer],
              [AS_HELP_STRING([--enable-nested-timer],
                              [enable timer nesting in reports (nested timer cannot be stopped while superordinate timer is still active) @<:@default: yes@:>@])],
              [case "${enableval}" in
                 yes) nestedtimer=true  ;;
                 no)  nestedtimer=false ;;
                 *) AC_MSG_ERROR([bad value ${enableval} for --enable-nested-timer]) ;;
               esac],
              [nestedtimer=true
               AC_DEFINE([NESTED_TIMER], 1, [NESTED_TIMER mode enabled])])

95
96
97
98
99
100
101
102
103
104
105
106
# TIMESTAMP_COUNTER
AC_ARG_ENABLE([timestamp-counter],
              [AS_HELP_STRING([--enable-timestamp-counter],
                              [enable timer based on the processor’s time-stamp counter (a 64-bit MSR) if accessible @<:@default: no@:>@])],
              [case "${enableval}" in
                 yes) timestampcounter=true  ;;
                 no)  timestampcounter=false ;;
                 *) AC_MSG_ERROR([bad value ${enableval} for --enable-timestamp-counter]) ;;
               esac],
              [timestampcounter=false
               AC_DEFINE([TIMESTAMP_COUNTER], 0, [TIMESTAMP_COUNTER mode enabled])])

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
# FAKELIB
AC_ARG_ENABLE([fakelib],
              [AS_HELP_STRING([--enable-fakelib],
                              [build additional fake libsct with same Fortran interface but no backend @<:@default: no@:>@])],
              [case "${enableval}" in
                 yes) fakelib=true
                      AC_DEFINE([FAKELIB], 1, [FAKELIB mode enabled])
                      ;;
                 no)  fakelib=false ;;
                 *) AC_MSG_ERROR([bad value ${enableval} for --enable-fakelib]) ;;
               esac],
              [fakelib=false])
AM_CONDITIONAL([FAKELIB], [test x"$fakelib" = xtrue])


#
# checks for programs
#
AC_PATH_PROG([PERL], [perl])

DX_DOT_FEATURE(ON)
DX_HTML_FEATURE(ON)
DX_CHM_FEATURE(OFF)
DX_CHI_FEATURE(OFF)
DX_MAN_FEATURE(OFF)
DX_RTF_FEATURE(OFF)
DX_XML_FEATURE(OFF)
DX_PDF_FEATURE(OFF)
DX_PS_FEATURE(OFF)
DX_INIT_DOXYGEN([sct], [doc/Doxyfile], [])

AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DX_DOXYGEN"])
AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])

# Checks for C and Fortran compiler - which might be mpi-compiler wrappers

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
dnl AS_CASE([$host_os], # todo: find better check here
dnl         [aix*], [if test x"$openmp" = xtrue; then   # change to use thread safe compiler version if openmp is used
dnl          CC=${CC-xlc_r}
dnl          FC=${FC-xlf90_r}
dnl          if test x"$mpi" = xtrue; then
dnl            MPICC=${MPICC-mpcc_r}
dnl            MPIFC=${MPIFC-mpxlf90_r}
dnl            CC=${MPICC}
dnl            FC=${MPIFC}
dnl          fi
dnl        fi])

AX_PROG_CC_MPI([test x"$mpi" != xfalse],
               [],
               [if test x"$mpi" = xtrue; then
                  AC_MSG_ERROR([MPI C compiler requested, but couldn't use MPI.])
                fi])

AC_PROG_FC
AX_PROG_FC_MPI([test x"$mpi" != xfalse],
               [],
               [if test x"$mpi" = xtrue; then
                  AC_MSG_ERROR([MPI Fortran compiler requested, but couldn't use MPI.])
                fi])
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

AS_IF([test x"$mpi" != xfalse],
      [AC_PATH_PROGS([MPI_LAUNCH], [poe mpirun mpiexec], [true])
       # set MP_HOSTFILE if we are using IBM PE
       if test x"$(basename $ac_cv_path_MPI_LAUNCH)" == x"poe"; then
         # create tmp hostfile and export envVar MP_HOSTFILE
         # to enable compiler check for MPI compiler in case of IBM PE
         if test -z "${MP_HOSTFILE}"; then
           hostname=$(hostname)
           if ! grep "$hostname" $HOME/.rhosts 2>/dev/null >&2 ; then
             AC_MSG_ERROR([
  -----------------------------------------------------
  It seems as if you are using IBM PE (poe) for MPI-
  parallel applications. But current hostname id not
  in ~/.rhosts! Stopping...
  Check 'config.log' for more information.
  Please contact $PACKAGE_BUGREPORT for a bugreport.
  -----------------------------------------------------])
           fi
           MP_HOSTFILE=`mktemp -t hostfile.tmpXXXXXX`
           trap '/bin/rm -f $MP_HOSTFILE' EXIT
           export MP_HOSTFILE
           echo "$hostname" >$MP_HOSTFILE
         fi
         # reset MPI_LAUNCH to wrapper script
         MPI_LAUNCH="$(pwd)/util/mpi_launch_poe"
         ac_cv_path_MPI_LAUNCH=$MPI_LAUNCH
       fi])

# check whether MPI environment is working
AS_IF([test x"$mpi" != xfalse],
      [AS_IF([test x"$cross_compiling" = xno],
             [AC_MSG_CHECKING([if $MPI_LAUNCH works])
              AC_LINK_IFELSE([AC_LANG_SOURCE([
@%:@include <stdio.h>
@%:@include <stdlib.h>

@%:@include <mpi.h>

@%:@define xmpi(ret)        \\
  do {                      \\
    if (ret != MPI_SUCCESS) \\
      exit(EXIT_FAILURE);   \\
  } while (0)

int
main(int argc, char **argv)
{
  xmpi(MPI_Init(&argc, &argv));
  char *numarg = argv@<:@1@:>@;
  int cmdnum = atoi(numarg);
  int procnum = 1;
  xmpi(MPI_Allreduce(MPI_IN_PLACE, &procnum, 1, MPI_INT, MPI_SUM,
                     MPI_COMM_WORLD));
  xmpi(MPI_Finalize());
  return (procnum == cmdnum)?EXIT_SUCCESS:EXIT_FAILURE;
}
])],
                             [AS_IF([$MPI_LAUNCH -n 4 ./conftest$EXEEXT 4],
                                    [AC_MSG_RESULT([yes])],
                                    [AC_MSG_RESULT([no])
                                     AC_MSG_FAILURE([mpirun doesn't work])])],
                             [AC_MSG_FAILURE([Cannot compile simple MPI program])])
             ])
       AS_IF([test "x$MPI_LAUNCH" = xtrue],
             [AC_MSG_WARN([MPI launch command unavailable])])
])


AC_FC_PP_SRCEXT([f90])
AC_FC_PP_DEFINE

# Set FCDEFS and adjust -D flag if needed.
FCDEFS="$DEFS -DHAVE_FCONFIG_H"
if test x"$FC_DEFINE" != x-D; then
  FCDEFS=`echo " $FCDEFS" | sed "s@ -D@ $FC_DEFINE@g"`
fi
AC_SUBST([FCDEFS])

# Get the Fortran compiler to accept free-form source.
AC_FC_FREEFORM
# Get it to accept long source file lines.
AC_FC_LINE_LENGTH
# Find out how to add to the Fortran include path.
AC_FC_MODULE_FLAG
# Find out the Fortran module file extension.
AC_FC_MODULE_EXTENSION
# check for Fortran 2003 standard options
AX_FC_STD2003([fortran_interface=true],
              [AC_MSG_WARN([Fortran compiler does not support ISO_C_BINDING ... suppress building Fortran interface])
               fortran_interface=false])
AM_CONDITIONAL([FORTRAN_INTERFACE], [test x"$fortran_interface" = xtrue])

#
# checks for libraries
#

# check for rtm available:

ac_save_LIBS=$LIBS

# i/ SCT_RTM_READ_REAL_TIME
AC_SEARCH_LIBS([read_real_time], [c])
# sets ac_cv_search_read_real_time to 'none required' if function is already available
#                                  to 'no' if no corresponding lib was found
#                                  '-llibrary' if found

# ii/ SCT_RTM_OMP_GET_WTIME -> omp_get_wtime
# iii/ SCT_RTM_MPI_WTIME	-> MPI_Wtime
# will be set if supported by this built and none else found

# SCT_RTM_POSIX
# iv/ SCT_RTM_CLOCK_GETTIME_MONOTONIC	clock_gettime(CLOCK_MONOTONIC, tm);
# v/  SCT_RTM_CLOCK_GETTIME_REALTIME	clock_gettime(CLOCK_REALTIME, tm);
AC_CHECK_HEADERS([unistd.h time.h])
AC_SEARCH_LIBS([clock_gettime], [rt])
if test x"$ac_cv_search_clock_gettime" != xno; then
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
    [[#include <unistd.h>]],
    [[int n[(_POSIX_TIMERS > 0) ? (+1) : (-1)];]])],
    [ac_cv_test_posix_timers=true],
    [ac_cv_test_posix_timers=false])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
    [[#include <unistd.h>
      #include <time.h>]],
    [[struct timespec tm; clock_gettime(CLOCK_MONOTONIC, &tm);]])],
    [ac_cv_test_posix_monotonic=true],
    [ac_cv_test_posix_monotonic=false])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
    [[#include <unistd.h>
      #include <time.h>]],
    [[struct timespec tm; clock_gettime(CLOCK_REALTIME, &tm);]])],
    [ac_cv_test_posix_realtime=true],
    [ac_cv_test_posix_realtime=false])
fi

# vi/ SCT_RTM_GETTIMEOFDAY
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_FUNCS([gettimeofday])

307
# vii/ SCT_RTM_RDTSCP
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
if test x"$timestampcounter" != xfalse; then
  if test x"$ac_cv_header_inttypes_h" != xno; then
    AC_MSG_CHECKING([if RDTSCP works])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
      [[#include <inttypes.h>]],
      [[unsigned low, high;
        uint64_t res;
        __asm__ __volatile__ ("rdtscp": "=a" (low), "=d" (high) );
        res = ((low) | ((uint64_t)(high) << 32)) ]])],
      [AC_MSG_RESULT([yes])
       ac_cv_test_rdtscp_timers=true],
      [AC_MSG_RESULT([no])
       ac_cv_test_rdtscp_timers=false])
  else
    ac_cv_test_rdtscp_timers=false
  fi
324
325
fi

326
327
328
329
330
331
332
333
334
335
# restore LIBS and decide which rtm to take
LIBS=$ac_save_LIBS

sct_rtm="none"
if test x"$ac_cv_search_read_real_time" != xno; then
  if test x"$ac_cv_search_read_real_time" != x"none required"; then
    LIBS="$ac_save_LIBS $ac_cv_search_read_real_time"
  fi
  AC_DEFINE([SCT_RTM], [1], [use SCT_RTM_READ_REAL_TIME for time measurement])
  sct_rtm="SCT_RTM_READ_REAL_TIME"
336
337
338
elif test x"$ac_cv_test_rdtscp_timers" = xtrue; then
  AC_DEFINE([SCT_RTM], [64], [use SCT_RTM_RDTSCP for time measurement])
  sct_rtm="SCT_RTM_RDTSCP"
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
elif test x"$ac_cv_test_posix_timers" = xtrue && test x"$ac_cv_test_posix_monotonic" = xtrue; then
  if test x"$ac_cv_search_clock_gettime" != x"none required"; then
    LIBS="$ac_save_LIBS $ac_cv_search_clock_gettime"
  fi
  AC_DEFINE([SCT_RTM], [8], [use SCT_RTM_CLOCK_GETTIME_MONOTONIC for time measurement])
  sct_rtm="SCT_RTM_CLOCK_GETTIME_MONOTONIC"
elif test x"$ac_cv_test_posix_timers" = xtrue && test x"$ac_cv_test_posix_realtime" = xtrue; then
  if test x"$ac_cv_search_clock_gettime" != x"none required"; then
    LIBS="$ac_save_LIBS $ac_cv_search_clock_gettime"
  fi
  AC_DEFINE([SCT_RTM], [16], [use SCT_RTM_CLOCK_GETTIME_REALTIME for time measurement])
  sct_rtm="SCT_RTM_CLOCK_GETTIME_REALTIME"
elif test x"$openmp" = xtrue; then
  AC_DEFINE([SCT_RTM], [2], [use SCT_RTM_OMP_GET_WTIME for time measurement])
  sct_rtm="SCT_RTM_OMP_GET_WTIME"
elif test x"$mpi" = xtrue; then
  AC_DEFINE([SCT_RTM], [4], [use SCT_RTM_MPI_WTIME for time measurement])
  sct_rtm="SCT_RTM_MPI_WTIME"
elif test x"$ac_cv_header_sys_time_h" = xyes && test x"$ac_cv_func_gettimeofday" = xyes; then
  AC_DEFINE([SCT_RTM], [32], [use SCT_RTM_GETTIMEOFDAY for time measurement])
  sct_rtm="SCT_RTM_GETTIMEOFDAY"
else
  AC_MSG_ERROR([
  -----------------------------------------------------
  Could not find any usable read time method (RTM).
  Stopping...
  Check 'config.log' for more information.
  Please contact $PACKAGE_BUGREPORT for a bugreport.
  -----------------------------------------------------])
fi


# check for PAPI
dnl use gnulib module 'havelib' ... see https://www.gnu.org/software/gnulib/manual/html_node/Searching-for-Libraries.html
dnl needed to download m4 files m4/m4_lib-* and config/config.rpath
374
375
376
377
378
379
380
381
382
383
AC_ARG_ENABLE([papi],
              [AS_HELP_STRING([--enable-papi],
                              [enable search for PAPI lib @<:@default: false@:>@])],
              [case "${enableval}" in
                 yes) papi=true
                      ;;
                 no)  papi=false ;;
                 *) AC_MSG_ERROR([bad value ${enableval} for --enable-papi]) ;;
               esac],
              [papi=false])
384

385
386
AS_IF([test x"$papi" != xfalse],
      [ AC_LIB_HAVE_LINKFLAGS(papi,,[#include <papi.h>],,
387
388
389
390
391
392
393
              [
  -----------------------------------------
  Using PAPI interface requires library
  and header files. Skipping ...
  Check 'config.log' for more information,
  maybe libdirstem was determined false.
  -----------------------------------------])
394
      ], [])
395
396
AM_CONDITIONAL([PAPI], [test x"$HAVE_LIBPAPI" = xyes])

397
# check for HDF5
398
399
400
401
402
403
404
405
406
407
AC_ARG_ENABLE([hdf5],
              [AS_HELP_STRING([--enable-hdf5],
                              [enable search for HDF5 lib @<:@default: false@:>@])],
              [case "${enableval}" in
                 yes) hdf5=true
                      ;;
                 no)  hdf5=false ;;
                 *) AC_MSG_ERROR([bad value ${enableval} for --enable-hdf5]) ;;
               esac],
              [hdf5=false])
408

409
410
AS_IF([test x"$hdf5" != xfalse],
      [ AC_LIB_HAVE_LINKFLAGS(hdf5,,[#include <hdf5.h>],,
411
412
413
414
415
416
417
              [
  -----------------------------------------
  Using HDF5 interface requires library
  and header files. Skipping ...
  Check 'config.log' for more information,
  maybe libdirstem was determined false.
  -----------------------------------------])
418
      ], [])
419
420
421
AM_CONDITIONAL([HDF5], [test x"$HAVE_LIBHDF5" = xyes])


422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# checks for header files
AC_CHECK_HEADERS([math.h stdio.h limits.h stdlib.h string.h strings.h inttypes.h sys/systemcfg.h])


# checks for typedefs, structures, and compiler characteristics
AC_C_INLINE
AC_C_RESTRICT

if test x"$openmp" = xtrue; then
  AC_LANG_PUSH([C])
  AC_OPENMP
  AC_LANG_POP([C])
  AC_LANG_PUSH([Fortran])
  AC_OPENMP
  AC_LANG_POP([Fortran])
fi


#
# checks for library functions
#
AC_SEARCH_LIBS([sqrt], [m])
AC_CHECK_FUNCS([floor pow sqrt memset strcasecmp])


#
# Output
#
AC_CONFIG_FILES([tests/test_precision_run
                 tests/test_sct_run
                 tests/test_papi_run
453
                 tests/test_hdf5_run
454
                 tests/test_hdf5_fortran_run   
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
                 tests/test_serial_run
                 tests/test_omp_run
                 tests/test_mpi_run
                 tests/test_hybrid_run],[chmod a+x "$ac_file"])
AC_CONFIG_FILES([Makefile
                 doc/Makefile
                 src/Makefile
                 src/pkgconfig/sct.pc
                 src_nosct/Makefile
                 tests/Makefile])

# Create config headers: config.h comes from autoheader-generated config.h.in,
AC_CONFIG_HEADERS([config.h])

# Convert fconfig.h.in into an fconfig.h suitable for inclusion into Fortran.
# The sed script transforms C style /* comments */ into Fortran style.
AC_CONFIG_HEADERS([fconfig.h:config.h.in],
 [[sed '
    /\/\*\(.*\)\*\//{
      s,,!\1,p
      d
    }
    /\/\*/,/\*\//{
      s,/\*,,
      s,\*/,,
      s,^,!,p
      d
    }' fconfig.h > fconfig.ht
   mv -f fconfig.ht fconfig.h
]])

AC_OUTPUT

echo \
"------------------------------------------------------------

${PACKAGE_NAME} Version ${PACKAGE_VERSION}

493
Prefix          : ${prefix}
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
C-Compiler      : ${CC} ${DEFS} ${CFLAGS} ${CPPFLAGS}
Fortran-Compiler: ${FC} ${FCDEFS} ${FCFLAGS} ${FCFLAGS_f90} ${FCCPPFLAGS}


Package features:

MPI              : ${mpi}"

echo \
"OpenMP           : ${openmp}"

if test x"$openmp" = xtrue; then
echo \
"    CFLAGS       : ${OPENMP_CFLAGS}
    FCFLAGS      : ${OPENMP_FCFLAGS}"
fi

echo \
"PAPI library     : ${LIBPAPI}"

514
515
516
echo \
"HDF5 library     : ${LIBHDF5}"

517
518
519
520
521
522
523
524
echo \
"use timer nesting: ${nestedtimer}
use RTM          : ${sct_rtm}

Now type 'make @<:@<target>@:>@' with optional <target>:

   all           - build libsct
   check         - check some features of sct
525
   install       - install configured version only"
526
527
528
529
echo \
"   @<:@doxygen-@:>@doc - build documentation based on Doxygen

------------------------------------------------------------"