From 88fedc2ff9f70e05fa3757000051b8e48ef0f4d1 Mon Sep 17 00:00:00 2001 From: schnetter Date: Thu, 25 Aug 2005 09:43:18 +0000 Subject: Get the MPI communicator more intelligently: use aliased function GetMPICommWorld if it is provided, otherwise fall back to using Carpet- and PUGH- specific methods, otherwise use MPI_COMM_WORLD. Don't disable (i.e., re-enable) some assert checks even if NDEBUG is defined. These are cheap checks that check the arguments that are passed in. Otherwise errors would go undetected. git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/Slab/trunk@43 2e825fa2-fb71-486d-8b7f-a5ff3f0f6cb8 --- interface.ccl | 3 ++ src/slab.c | 137 +++++++++++++++++++++++++++++++++++----------------------- 2 files changed, 85 insertions(+), 55 deletions(-) diff --git a/interface.ccl b/interface.ccl index 171bc4a..100ed3a 100644 --- a/interface.ccl +++ b/interface.ccl @@ -5,3 +5,6 @@ IMPLEMENTS: Slab INCLUDES HEADER: slab.h IN Slab.h INCLUDES HEADER: slab.inc IN Slab.inc + +CCTK_INT FUNCTION GetMPICommWorld (CCTK_POINTER_TO_CONST IN cctkGH) +USES FUNCTION GetMPICommWorld diff --git a/src/slab.c b/src/slab.c index b61f48b..3fec618 100644 --- a/src/slab.c +++ b/src/slab.c @@ -34,6 +34,8 @@ #include "cctk.h" #include "cctk_DefineThorn.h" +#include "util_ErrorCodes.h" +#include "util_Table.h" #ifdef CCTK_MPI # include @@ -61,6 +63,12 @@ CCTK_FILEVERSION(TAT_Slab_slab_c); # define ifcheck while (0) #endif +#ifdef NDEBUG +# define check(x) ((x) ? 0 : CCTK_WARN (0, "internal error")) +#else +# define check(x) assert (x) +#endif + static int timer_init; @@ -88,7 +96,7 @@ void Slab_PrintTimers (void) /* Find out which driver to use */ #ifdef CCTK_MPI -# if defined CARPET_CARPET || defined CARPETORIG_CARPET +# if defined CARPET_CARPET # include "Carpet/Carpet/src/carpet_public.h" # endif # if defined CACTUSPUGH_PUGH @@ -293,7 +301,10 @@ static MPI_Comm get_mpi_comm (const cGH * restrict const cctkGH) { #ifdef CCTK_MPI -# if defined CARPET_CARPET || defined CARPETORIG_CARPET + if (CCTK_IsFunctionAliased ("GetMPICommWorld")) { + return GetMPICommWorld (cctkGH); + } +# if defined CARPET_CARPET { static int Carpet_active = -1; if (Carpet_active == -1) Carpet_active = CCTK_IsThornActive ("Carpet"); @@ -659,43 +670,45 @@ int Slab_MultiTransfer (cGH const * const cctkGH, int d; /* Check arguments */ - assert (cctkGH); - assert (dim >= 0); - assert (xferinfo); - assert (nvars >= 0); - assert (nvars==0 || srctypes); - for (var=0; var= 0); - assert (nvars==0 || srcptrs); -/* for (var=0; var= 0); - assert (nvars==0 || dstptrs); -/* for (var=0; var= 0); + check (xferinfo); + check (nvars >= 0); + check (nvars==0 || srctypes); + for (var=0; var= 0); + check (nvars==0 || srcptrs); +/* for (var=0; var= 0); + check (nvars==0 || dstptrs); +/* for (var=0; var= 0 && info[d].xpose < dim); + check (info[d].xpose >= 0 && info[d].xpose < dim); info[d].flip = xferinfo[d].flip; - assert (info[d].flip == 0 || info[d].flip == 1); + check (info[d].flip == 0 || info[d].flip == 1); } for (d=dim; d= 0 && info[d].xpose < SLAB_MAXDIM); + check (info[d].xpose >= 0 && info[d].xpose < SLAB_MAXDIM); info[d].flip = 0; - assert (info[d].flip == 0 || info[d].flip == 1); + check (info[d].flip == 0 || info[d].flip == 1); } ifcheck { @@ -786,7 +799,21 @@ int Slab_MultiTransfer (cGH const * const cctkGH, - comm = get_mpi_comm (cctkGH); + { + CCTK_INT tmp; + int const iret = Util_TableGetInt (options, &tmp, "comm"); + if (iret == 1) { + /* There was an entry, use it */ + comm = tmp; + } else if (iret == UTIL_ERROR_BAD_HANDLE + || iret == UTIL_ERROR_TABLE_NO_SUCH_KEY) { + /* There was no entry, use a default */ + comm = get_mpi_comm (cctkGH); + } else { + /* Something went wrong, abort */ + check (0); + } + } ifcheck { ifdebug fflush (stdout); @@ -807,27 +834,27 @@ int Slab_MultiTransfer (cGH const * const cctkGH, ++ count; } - assert (nvars >= 1); + check (nvars >= 1); srctype = srctypes[0]; dsttype = dsttypes[0]; for (var=0; var 0); + check (srctypesize > 0); dsttypesize = CCTK_VarTypeSize (dsttype); - assert (dsttypesize > 0); + check (dsttypesize > 0); srcdatatype = mpi_type (srctype); - assert (srcdatatype >= 0); + check (srcdatatype >= 0); dstdatatype = mpi_type (dsttype); - assert (dstdatatype >= 0); + check (dstdatatype >= 0); allinfo = malloc (size * SLAB_MAXDIM * sizeof *allinfo); - assert (allinfo); + check (allinfo); { int const info_nints = sizeof(struct info) / sizeof(int); ifdebug fflush (stdout); @@ -872,7 +899,7 @@ int Slab_MultiTransfer (cGH const * const cctkGH, srcdetail = malloc (size * SLAB_MAXDIM * sizeof *srcdetail); - assert (srcdetail); + check (srcdetail); for (n = 0; n < size; ++n) { ifdebug printf ("srcdetail n=%d:\n", n); for (d=0; d