Skip to content
Snippets Groups Projects
Commit bc9338ef authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Add configure-time checking and override for external packing.

parent e503f55e
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ gmon.out
/aclocal.m4
/configure
/config
!/config/checksrc
!/config/checkdoc
config.h
config.log
config.status
......
Your MPI installation has a serious defect in its implementation of
external32 packing of data. This is the only serialization guaranteed
to be portable across different MPI communicators. You can elect to
use the regular data packing routines instead, for which such
portability is not guaranteed, but often works in practice with the
configure argument --without-mpi-pack-external. Alternatively you can
ignore the result of this test with the --without-regard-for-quality
option but this will probably result in a non-working YAC build,
i.e. multiple tests will fail.
test_mpi_pack_external_1.txt
\ No newline at end of file
#include <mpi.h>
#include <stdlib.h>
#include <stdio.h>
static void mpi_err_handler(int error_code, MPI_Comm comm);
char const * datarep = "external32";
#define UINT_COUNT (2)
#define DBLE_COUNT (24)
int main(void) {
MPI_Init(NULL, NULL);
unsigned * uint_data = calloc(UINT_COUNT, sizeof(*uint_data));
double * dble_data = calloc(DBLE_COUNT, sizeof(*dble_data));
MPI_Aint uint_pack_size, dble_pack_size;
mpi_err_handler(MPI_Pack_external_size(datarep, UINT_COUNT, MPI_UNSIGNED,
&uint_pack_size), MPI_COMM_WORLD);
mpi_err_handler(MPI_Pack_external_size(datarep, DBLE_COUNT, MPI_DOUBLE,
&dble_pack_size), MPI_COMM_WORLD);
MPI_Aint pack_size = uint_pack_size + dble_pack_size;
void * pack_buffer = malloc(pack_size);
MPI_Aint position = 0;
#ifndef WITHOUT_PACK_EXTERNAL
#define BUG
#ifdef BUG
mpi_err_handler(MPI_Pack_external(datarep, uint_data, UINT_COUNT,
MPI_UNSIGNED, pack_buffer, pack_size,
&position), MPI_COMM_WORLD);
mpi_err_handler(MPI_Pack_external(datarep, dble_data, DBLE_COUNT, MPI_DOUBLE,
pack_buffer, pack_size, &position),
MPI_COMM_WORLD);
#else // NO_BUG
mpi_err_handler(MPI_Pack_external(datarep, dble_data, DBLE_COUNT, MPI_DOUBLE,
pack_buffer, pack_size, &position),
MPI_COMM_WORLD);
mpi_err_handler(MPI_Pack_external(datarep, uint_data, UINT_COUNT,
MPI_UNSIGNED, pack_buffer, pack_size,
&position), MPI_COMM_WORLD);
#endif // NO_BUG
#endif // WITHOUT_PACK_EXTERNAL
free(pack_buffer);
free(dble_data);
free(uint_data);
MPI_Finalize();
return EXIT_SUCCESS;
}
//taken from http://beige.ucs.indiana.edu/I590/node85.html
static void mpi_err_handler(int error_code, MPI_Comm comm) {
if (error_code != MPI_SUCCESS) {
int rank;
MPI_Comm_rank(comm, &rank);
char error_string[1024];
int length_of_error_string, error_class;
MPI_Error_class(error_code, &error_class);
MPI_Error_string(error_class, error_string, &length_of_error_string);
fprintf(stderr, "%3d: %s\n", rank, error_string);
MPI_Error_string(error_code, error_string, &length_of_error_string);
fprintf(stderr, "%3d: %s\n", rank, error_string);
MPI_Abort(comm, error_code);
}
}
#include <mpi.h>
#include <stdlib.h>
#include <stdio.h>
static void mpi_err_handler(int error_code, MPI_Comm comm);
char const * datarep = "external32";
int main(void) {
int exit_code = EXIT_SUCCESS;
MPI_Init(NULL, NULL);
#ifndef WITHOUT_PACK_EXTERNAL
int send_data[2] = {93184, -9023};
int recv_data[2];
MPI_Aint pack_size;
mpi_err_handler(MPI_Pack_external_size(datarep, 2, MPI_INT, &pack_size),
MPI_COMM_WORLD);
char * buffer = malloc(pack_size);
MPI_Aint position = 0;
mpi_err_handler(MPI_Pack_external(datarep, send_data, 2, MPI_INT, buffer,
pack_size, &position), MPI_COMM_WORLD);
position = 0;
mpi_err_handler(MPI_Unpack_external(datarep, buffer, pack_size, &position,
recv_data, 2, MPI_INT), MPI_COMM_WORLD);
free(buffer);
if ((send_data[0] != recv_data[0]) || (send_data[1] != recv_data[1]))
exit_code = EXIT_FAILURE;
#endif // WITHOUT_PACK_EXTERNAL
MPI_Finalize();
return exit_code;
}
//taken from http://beige.ucs.indiana.edu/I590/node85.html
static void mpi_err_handler(int error_code, MPI_Comm comm) {
if (error_code != MPI_SUCCESS) {
int rank;
MPI_Comm_rank(comm, &rank);
char error_string[1024];
int length_of_error_string, error_class;
MPI_Error_class(error_code, &error_class);
MPI_Error_string(error_class, error_string, &length_of_error_string);
fprintf(stderr, "%3d: %s\n", rank, error_string);
MPI_Error_string(error_code, error_string, &length_of_error_string);
fprintf(stderr, "%3d: %s\n", rank, error_string);
MPI_Abort(comm, error_code);
}
}
......@@ -52,10 +52,36 @@ AS_IF([test x"$enable_MPI" = xno],
])
AS_IF([test x"$enable_MPI" = xyes],
[AC_DEFINE([USE_MPI],[1],[use MPI parallel process environment])
AC_CHECK_PROGS([MPI_LAUNCH],[mpirun mpiexec],[])
AS_IF([test x$MPI_LAUNCH = x],
[AC_MSG_FAILURE([MPI launcher (MPI_LAUNCH) not found])])
AC_SUBST([HAVE_MPI],[1])],
AC_SUBST([HAVE_MPI],[1])
saved_CFLAGS=$CFLAGS
saved_FCFLAGS=$FCFLAGS
saved_LIBS=$LIBS
CFLAGS="$CFLAGS $MPI_C_INCLUDE"
FCFLAGS="$FCFLAGS $MPI_FC_INCLUDE"
LIBS="$LIBS $MPI_C_LIB"
ACX_MPIRUN
# check MPI defects
AC_ARG_WITH([regard-for-quality],
[AS_HELP_STRING([--without-regard-for-quality],
[ignore results of checks for known defects @<:@default: abort on error@:>@])],
[],[with_regard_for_quality=yes])
AC_ARG_WITH([pack-external],
[AS_HELP_STRING([--without-pack-external],
[use MPI_Pack (not guaranteed to work) instead of MPI_Pack_external @<:@default: yes, use MPI_Pack_external@:>@])],,[with_pack_external=yes])
AS_IF([test x"$with_pack_external" = xyes],,
[CPPFLAGS="${CPPFLAGS+$CPPFLAGS }-DWITHOUT_PACK_EXTERNAL"])
ACX_MPI_DEFECTS(,,
[ACX_MPI_DEFECTS_DOCUMENT
AS_CASE(["$acx_subtestname"],[test_mpi_pack_external_*],
[AC_MSG_ERROR([Warning, known problem with MPI_Pack_external detected, please look into the description in config/checkdoc/${acx_subtestname}.txt!])])
AS_IF([test "$with_regard_for_quality" != no],
[AC_MSG_FAILURE([test for known defect $subtestname failed, re-configure with --without-regard-for-quality in case you must use the given MPI implementation, but some tests might fail])])])
AS_IF([test "x$MPI_LAUNCH" = xtrue],
[AC_MSG_WARN([MPI launch command unavailable])])
FCFLAGS=$saved_FCFLAGS
CFLAGS=$saved_CFLAGS
LIBS=$saved_LIBS
],
[MPI_LAUNCH="`pwd`/util/serialrun"
AC_SUBST([MPI_LAUNCH])
AC_SUBST([HAVE_MPI],[0])])
......
dnl acx_mpi_defects.m4 --- check whether MPI has one or more of
dnl several known defects
dnl
dnl Copyright (C) 2014 Thomas Jahns <jahns@dkrz.de>
dnl
dnl Keywords: configure configure.ac autoconf MPI mpirun mpiexec
dnl Author: Thomas Jahns <jahns@dkrz.de>
dnl Maintainer: Thomas Jahns <jahns@dkrz.de>
dnl URL: https://www.dkrz.de/redmine/projects/show/scales-ppm
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl Redistributions of source code must retain the above copyright notice,
dnl this list of conditions and the following disclaimer.
dnl
dnl Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl Neither the name of the DKRZ GmbH nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
dnl IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
dnl OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl
dnl ACX_MPI_DEFECTS([TEST-SOURCE-DIR=config/checksrc],
dnl [ACTION-IF-CHECK-SUCCEEDS],
dnl [ACTION-IF-CHECK-FAILED=AC_MSG_FAILURE])
dnl
dnl Requires MPI_LAUNCH program. Also CC/FC must be setup to
dnl build MPI programs.
dnl Builds and runs simple programs from TEST-SOURCE-DIR, each of which
dnl should represent a test for a known defect that affects the library
dnl code.
dnl Each test is built according to it's file suffix as either Fortran
dnl or C MPI program.
dnl Within ACTION-IF-CHECK-SUCCEEDS and ACTION-IF-CHECK-FAILED,
dnl the following variables are set to test-specific values:
dnl acx_subtestname = base file name of the test
dnl acx_mpi_check_src = path to check source file
dnl acx_suffix = file suffix of source file
dnl
dnl Each test source may contain zero or more of the following stanzas
dnl acx_mpirun_num_tasks = N
dnl specify number of tasks N (positive integer) to run this test with
dnl TODO: extend for F77 and C++
AC_DEFUN([ACX_MPI_DEFECTS],
[AS_IF([test x"$MPI_LAUNCH" = xtrue],
[AC_MSG_NOTICE([Skipping tests for known MPI defects: MPI launcher unavailable])],
[AC_MSG_CHECKING([MPI for known defects])
AC_MSG_RESULT([])
for acx_mpi_check_src in "$srcdir/m4_ifval([$1],[$1],[config/checksrc])/"* ; do
acx_suffix=`echo "$acx_mpi_check_src" | sed 's/^.*\.\(@<:@^.@:>@*\)$/\1/'`
acx_subtestname=`echo "$acx_mpi_check_src" | sed 's/^.*\/\(@<:@^\/@:>@*\)\.@<:@^.@:>@*/\1/'`
AS_CASE([$acx_suffix],
[c],
[cat confdefs.h "$acx_mpi_check_src" >conftest."$acx_suffix"
AC_LANG_PUSH([C])],
[f90|F90],[cat "$acx_mpi_check_src" >conftest."$acx_suffix"
AC_LANG_PUSH([Fortran])],
[AC_MSG_FAILURE([Unexpected language in MPI check: ${acx_subtestname}.${acx_suffix}])])
AC_MSG_CHECKING([$acx_subtestname])
acx_mpirun_num_tasks=`sed -n '/acx_mpirun_num_tasks *= *\(@<:@0-9@:>@*\)/{
s/.*acx_mpirun_num_tasks *= *\(@<:@0-9@:>@*\).*/\1/
p
q
}
' "$acx_mpi_check_src"`
AS_IF([test `expr "$acx_mpirun_num_tasks" : "@<:@0-9@:>@@<:@0-9@:>@*$"` -gt 0 \
&& test "$acx_mpirun_num_tasks" -gt 0],,
[acx_mpirun_num_tasks=1])
AC_LINK_IFELSE(,
[acx_mpirun_num_tasks="$MPI_LAUNCH -n $acx_mpirun_num_tasks ./conftest$EXEEXT"
AC_TRY_EVAL([acx_mpirun_num_tasks])
AS_IF([test $ac_status -eq 0],
[AC_MSG_RESULT([okay])m4_ifval([$2],[
$2])],
[AC_MSG_RESULT([error])
m4_ifval([$3],[$3],
[AC_MSG_FAILURE([chosen MPI has known error $acx_subtestname])])])],
[AC_MSG_RESULT([error])
m4_ifval([$3],[$3],
[AC_MSG_RESULT([chosen MPI has known error $acx_subtestname])])])
AS_CASE([$acx_suffix],
[f90|F90],[AC_LANG_POP([Fortran])],
[c],[AC_LANG_POP([C])])
done
ASX_VAR_UNSET([acx_mpirun_num_tasks])
ASX_VAR_UNSET([acx_mpi_check_src])
ASX_VAR_UNSET([acx_suffix])
ASX_VAR_UNSET([acx_subtestname])
])])
dnl dump text documentation of defect test to stderr
dnl ACX_MPI_DEFECTS_DOCUMENT([TEST-DOC-DIR=config/checkdoc])
AC_DEFUN([ACX_MPI_DEFECTS_DOCUMENT],
[AS_IF([test -r "$srcdir/m4_ifval([$1],[$1],[config/checkdoc])/${acx_subtestname}.txt"],
[cat "$srcdir/m4_ifval([$1],[$1],[config/checkdoc])/${acx_subtestname}.txt" >&2])])
dnl
dnl Local Variables:
dnl mode: autoconf
dnl license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm"
dnl license-default: "bsd"
dnl End:
dnl acx_mpirun.m4 --- check whether launching MPI programs works
dnl
dnl Copyright (C) 2014 Thomas Jahns <jahns@dkrz.de>
dnl
dnl Keywords: configure configure.ac autoconf MPI mpirun mpiexec
dnl Author: Thomas Jahns <jahns@dkrz.de>
dnl Maintainer: Thomas Jahns <jahns@dkrz.de>
dnl URL: https://www.dkrz.de/redmine/projects/show/scales-ppm
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl Redistributions of source code must retain the above copyright notice,
dnl this list of conditions and the following disclaimer.
dnl
dnl Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl Neither the name of the DKRZ GmbH nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
dnl IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
dnl OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl
dnl ACX_MPIRUN([NUM_TASKS=4],[ACTION-IF-WORKING],
dnl [ACTION-IF-RUN-FAILS=AC_MSG_FAILURE],
dnl [ACTION-IF-BUILD-FAILS=AC_MSG_FAILURE])
dnl
dnl First determines mpi launcher program (and sets MPI_LAUNCH to its path),
dnl then builds and runs simple program with 4 tasks
dnl (or NUM_TASKS if specified).
dnl MPI_LAUNCH is either set to a valid MPI launcher program path (unless
dnl cross-compiling, because it can't be tested then) or true (when it
dnl doesn't work).
dnl
dnl TODO: instead of setting C language, perform test for active AC_LANG
AC_DEFUN([ACX_MPIRUN],
[AC_PATH_PROGS([MPI_LAUNCH],[mpirun mpiexec],[true])
AC_ARG_VAR([MPI_LAUNCH],[absolute path to launcher for MPI programs, must be working unless configuring in cross-compilation mode])
AS_IF([test x"$cross_compiling" = xno -a x"$MPI_LAUNCH" != xtrue],
[AC_MSG_CHECKING([if $MPI_LAUNCH works])
AC_LANG_PUSH([C])
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 m4_ifval([$1],[$1],[4]) ./conftest$EXEEXT m4_ifval([$1],[$1],[4])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
MPI_LAUNCH=true])],
[MPI_LAUNCH=true
m4_ifval([$3],[$3],[AC_MSG_FAILURE([Cannot compile simple MPI program])])])
AC_LANG_POP([C])])
AS_IF([test x"$MPI_LAUNCH" = xtrue],
[m4_ifval([$3],[$3],[AC_MSG_FAILURE([failed to run MPI programs])])],
[$2])
])
dnl
dnl Local Variables:
dnl mode: autoconf
dnl license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm"
dnl license-default: "bsd"
dnl End:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment