#include "mpi.h"
#include "mpitestconf.h"
#include "mpitest.h"
-#include "smpi_cocci.h"
#if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
#include <stdio.h>
#endif
/* Here is where we could put the includes and definitions to enable
memory testing */
-SMPI_VARINIT_GLOBAL_AND_SET(dbgflag, int, 0); /* Flag used for debugging */
-SMPI_VARINIT_GLOBAL_AND_SET(wrank, int, -1); /* World rank */
-SMPI_VARINIT_GLOBAL_AND_SET(verbose, int, 0); /* Message level (0 is none) */
-SMPI_VARINIT_GLOBAL_AND_SET(returnWithVal, int, 0); /* Allow programs to return
- with a non-zero if there was an error (may
- cause problems with some runtime systems) */
-SMPI_VARINIT_GLOBAL_AND_SET(usageOutput, int, 0); /* */
+static int dbgflag = 0; /* Flag used for debugging */
+static int wrank = -1; /* World rank */
+static int verbose = 0; /* Message level (0 is none) */
+static int returnWithVal = 0; /* Allow programs to return with a non-zero
+ if there was an error (may cause problems
+ with some runtime systems) */
+static int usageOutput = 0; /* */
/* Provide backward portability to MPI 1 */
#ifndef MPI_VERSION
}
/* Check for debugging control */
if (getenv( "MPITEST_DEBUG" )) {
- SMPI_VARGET_GLOBAL(dbgflag) = 1;
- MPI_Comm_rank( MPI_COMM_WORLD, &SMPI_VARGET_GLOBAL(wrank) );
+ dbgflag = 1;
+ MPI_Comm_rank( MPI_COMM_WORLD, &wrank );
}
/* Check for verbose control */
}
else {
if (val >= 0) {
- SMPI_VARGET_GLOBAL(verbose) = val;
+ verbose = val;
}
else {
fprintf( stderr, "Warning: %s not valid for MPITEST_VERBOSE\n",
strcmp( envval, "YES" ) == 0 ||
strcmp( envval, "true" ) == 0 ||
strcmp( envval, "TRUE" ) == 0) {
- SMPI_VARGET_GLOBAL(returnWithVal) = 1;
+ returnWithVal = 1;
}
else if (strcmp( envval, "no" ) == 0 ||
strcmp( envval, "NO" ) == 0 ||
strcmp( envval, "false" ) == 0 ||
strcmp( envval, "FALSE" ) == 0) {
- SMPI_VARGET_GLOBAL(returnWithVal) = 0;
+ returnWithVal = 0;
}
else {
fprintf( stderr,
/* Print rusage data if set */
if (getenv( "MPITEST_RUSAGE" )) {
- SMPI_VARGET_GLOBAL(usageOutput) = 1;
+ usageOutput = 1;
}
}
/*
fflush( stdout );
}
- if (SMPI_VARGET_GLOBAL(usageOutput))
+ if (usageOutput)
MTestResourceSummary( stdout );
*/
int MTestReturnValue( int errors )
{
- if (SMPI_VARGET_GLOBAL(returnWithVal)) return errors ? 1 : 0;
+ if (returnWithVal) return errors ? 1 : 0;
return 0;
}
/* ------------------------------------------------------------------------ */
* from the tests.
* MTestSleep( seconds )
*/
-#ifdef HAVE_WINDOWS_H
+#ifdef _WIN32
#include <windows.h>
void MTestSleep( int sec )
{
* Indexed - Indexed datatype. Only for a count of 1 instance of the
* datatype
*/
-SMPI_VARINIT_GLOBAL_AND_SET(datatype_index, int, 0);
+static int datatype_index = 0;
/* ------------------------------------------------------------------------ */
/* Datatype routines for contiguous datatypes */
static void *MTestTypeIndexedFree( MTestDatatype *mtype )
{
- if (mtype->buf) {
- free( mtype->buf );
+ if (mtype->buf)
+ free( mtype->buf );
free( mtype->displs );
free( mtype->index );
mtype->buf = 0;
mtype->displs = 0;
mtype->index = 0;
- }
return 0;
}
recvtype->count = count;
/* Use datatype_index to choose a datatype to use. If at the end of the
list, return 0 */
- switch (SMPI_VARGET_GLOBAL(datatype_index)) {
+ switch (datatype_index) {
case 0:
sendtype->datatype = MPI_INT;
sendtype->isBasic = 1;
break;
#endif
default:
- SMPI_VARGET_GLOBAL(datatype_index) = -1;
+ datatype_index = -1;
}
if (!sendtype->InitBuf) {
sendtype->CheckBuf = MTestTypeContigCheckbuf;
recvtype->CheckBuf = MTestTypeContigCheckbuf;
}
- SMPI_VARGET_GLOBAL(datatype_index)++;
+ datatype_index++;
- if (SMPI_VARGET_GLOBAL(dbgflag) && SMPI_VARGET_GLOBAL(datatype_index) > 0) {
+ if (dbgflag && datatype_index > 0) {
int typesize;
- fprintf( stderr, "%d: sendtype is %s\n", SMPI_VARGET_GLOBAL(wrank), MTestGetDatatypeName( sendtype ) );
+ fprintf( stderr, "%d: sendtype is %s\n", wrank, MTestGetDatatypeName( sendtype ) );
merr = MPI_Type_size( sendtype->datatype, &typesize );
if (merr) MTestPrintError( merr );
- fprintf( stderr, "%d: sendtype size = %d\n", SMPI_VARGET_GLOBAL(wrank), typesize );
- fprintf( stderr, "%d: recvtype is %s\n", SMPI_VARGET_GLOBAL(wrank), MTestGetDatatypeName( recvtype ) );
+ fprintf( stderr, "%d: sendtype size = %d\n", wrank, typesize );
+ fprintf( stderr, "%d: recvtype is %s\n", wrank, MTestGetDatatypeName( recvtype ) );
merr = MPI_Type_size( recvtype->datatype, &typesize );
if (merr) MTestPrintError( merr );
- fprintf( stderr, "%d: recvtype size = %d\n", SMPI_VARGET_GLOBAL(wrank), typesize );
+ fprintf( stderr, "%d: recvtype size = %d\n", wrank, typesize );
fflush( stderr );
}
- else if (SMPI_VARGET_GLOBAL(verbose) && SMPI_VARGET_GLOBAL(datatype_index) > 0) {
+ else if (verbose && datatype_index > 0) {
printf( "Get new datatypes: send = %s, recv = %s\n",
MTestGetDatatypeName( sendtype ),
MTestGetDatatypeName( recvtype ) );
fflush( stdout );
}
- return SMPI_VARGET_GLOBAL(datatype_index);
+ return datatype_index;
}
/* Reset the datatype index (start from the initial data type.
*/
void MTestResetDatatypes( void )
{
- SMPI_VARGET_GLOBAL(datatype_index) = 0;
+ datatype_index = 0;
}
/* Return the index of the current datatype. This is rarely needed and
is provided mostly to enable debugging of the MTest package itself */
int MTestGetDatatypeIndex( void )
{
- return SMPI_VARGET_GLOBAL(datatype_index);
+ return datatype_index;
}
/* Free the storage associated with a datatype */
simplify the use of the routine */
const char *MTestGetDatatypeName( MTestDatatype *dtype )
{
- typedef char name_type[4][MPI_MAX_OBJECT_NAME];
- SMPI_VARINIT_STATIC(name, name_type);
- SMPI_VARINIT_STATIC_AND_SET(sp, int, 0);
+ static char name[4][MPI_MAX_OBJECT_NAME];
+ static int sp=0;
int rlen, merr;
- if (SMPI_VARGET_STATIC(sp) >= 4) SMPI_VARGET_STATIC(sp) = 0;
- merr = MPI_Type_get_name( dtype->datatype, SMPI_VARGET_STATIC(name)[SMPI_VARGET_STATIC(sp)], &rlen );
+ if (sp >= 4) sp = 0;
+ merr = MPI_Type_get_name( dtype->datatype, name[sp], &rlen );
if (merr) MTestPrintError( merr );
- return (const char *)SMPI_VARGET_STATIC(name)[SMPI_VARGET_STATIC(sp)++];
+ return (const char *)name[sp++];
}
/* ----------------------------------------------------------------------- */
* that return value as well.
*
*/
-SMPI_VARINIT_GLOBAL_AND_SET(interCommIdx, int, 0);
-SMPI_VARINIT_GLOBAL_AND_SET(intraCommIdx, int, 0);
-SMPI_VARINIT_GLOBAL_AND_SET(intraCommName, const char *, 0);
-SMPI_VARINIT_GLOBAL_AND_SET(interCommName, const char *, 0);
+static int interCommIdx = 0;
+static int intraCommIdx = 0;
+static const char *intraCommName = 0;
+static const char *interCommName = 0;
/*
* Get an intracommunicator with at least min_size members. If "allowSmaller"
MPI_COMM_NULL is always considered large enough */
while (!done) {
isBasic = 0;
- SMPI_VARGET_GLOBAL(intraCommName) = "";
- switch (SMPI_VARGET_GLOBAL(intraCommIdx)) {
+ intraCommName = "";
+ switch (intraCommIdx) {
case 0:
*comm = MPI_COMM_WORLD;
isBasic = 1;
- SMPI_VARGET_GLOBAL(intraCommName) = "MPI_COMM_WORLD";
+ intraCommName = "MPI_COMM_WORLD";
break;
case 1:
/* dup of world */
merr = MPI_Comm_dup(MPI_COMM_WORLD, comm );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(intraCommName) = "Dup of MPI_COMM_WORLD";
+ intraCommName = "Dup of MPI_COMM_WORLD";
break;
case 2:
/* reverse ranks */
if (merr) MTestPrintError( merr );
merr = MPI_Comm_split( MPI_COMM_WORLD, 0, size-rank, comm );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(intraCommName) = "Rank reverse of MPI_COMM_WORLD";
+ intraCommName = "Rank reverse of MPI_COMM_WORLD";
break;
case 3:
/* subset of world, with reversed ranks */
merr = MPI_Comm_split( MPI_COMM_WORLD, ((rank < size/2) ? 1 : MPI_UNDEFINED),
size-rank, comm );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(intraCommName) = "Rank reverse of half of MPI_COMM_WORLD";
+ intraCommName = "Rank reverse of half of MPI_COMM_WORLD";
break;
case 4:
*comm = MPI_COMM_SELF;
isBasic = 1;
- SMPI_VARGET_GLOBAL(intraCommName) = "MPI_COMM_SELF";
+ intraCommName = "MPI_COMM_SELF";
break;
/* These next cases are communicators that include some
int newsize;
merr = MPI_Comm_size( MPI_COMM_WORLD, &size );
if (merr) MTestPrintError( merr );
- newsize = size - (SMPI_VARGET_GLOBAL(intraCommIdx) - 4);
+ newsize = size - (intraCommIdx - 4);
if (allowSmaller && newsize >= min_size) {
merr = MPI_Comm_rank( MPI_COMM_WORLD, &rank );
*comm = MPI_COMM_NULL;
}
else {
- SMPI_VARGET_GLOBAL(intraCommName) = "Split of WORLD";
+ intraCommName = "Split of WORLD";
}
}
else {
/* Act like default */
*comm = MPI_COMM_NULL;
- SMPI_VARGET_GLOBAL(intraCommIdx) = -1;
+ intraCommIdx = -1;
}
}
break;
/* Other ideas: dup of self, cart comm, graph comm */
default:
*comm = MPI_COMM_NULL;
- SMPI_VARGET_GLOBAL(intraCommIdx) = -1;
+ intraCommIdx = -1;
break;
}
done = 1;
}
else {
- SMPI_VARGET_GLOBAL(intraCommName) = "MPI_COMM_NULL";
+ intraCommName = "MPI_COMM_NULL";
isBasic = 1;
done = 1;
}
/* Advance the comm index whether we are done or not, otherwise we could
* spin forever trying to allocate a too-small communicator over and
* over again. */
- SMPI_VARGET_GLOBAL(intraCommIdx)++;
+ intraCommIdx++;
if (!done && !isBasic && *comm != MPI_COMM_NULL) {
/* avoid leaking communicators */
}
}
- return SMPI_VARGET_GLOBAL(intraCommIdx);
+ return intraCommIdx;
}
/*
/* Return the name of an intra communicator */
const char *MTestGetIntracommName( void )
{
- return SMPI_VARGET_GLOBAL(intraCommName);
+ return intraCommName;
}
/*
while (!done) {
*comm = MPI_COMM_NULL;
*isLeftGroup = 0;
- SMPI_VARGET_GLOBAL(interCommName) = "MPI_COMM_NULL";
+ interCommName = "MPI_COMM_NULL";
- switch (SMPI_VARGET_GLOBAL(interCommIdx)) {
+ switch (interCommIdx) {
case 0:
/* Split comm world in half */
merr = MPI_Comm_rank( MPI_COMM_WORLD, &rank );
merr = MPI_Intercomm_create( mcomm, 0, MPI_COMM_WORLD, rleader,
12345, comm );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(interCommName) = "Intercomm by splitting MPI_COMM_WORLD";
+ interCommName = "Intercomm by splitting MPI_COMM_WORLD";
}
else
*comm = MPI_COMM_NULL;
merr = MPI_Intercomm_create( mcomm, 0, MPI_COMM_WORLD,
rleader, 12346, comm );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(interCommName) = "Intercomm by splitting MPI_COMM_WORLD into 1, rest";
+ interCommName = "Intercomm by splitting MPI_COMM_WORLD into 1, rest";
}
else
*comm = MPI_COMM_NULL;
merr = MPI_Intercomm_create( mcomm, 0, MPI_COMM_WORLD,
rleader, 12347, comm );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(interCommName) = "Intercomm by splitting MPI_COMM_WORLD into 2, rest";
+ interCommName = "Intercomm by splitting MPI_COMM_WORLD into 2, rest";
}
else
*comm = MPI_COMM_NULL;
mcomm = *comm;
merr = MPI_Comm_dup(mcomm, comm);
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(interCommName) = "Intercomm by splitting MPI_COMM_WORLD then dup'ing";
+ interCommName = "Intercomm by splitting MPI_COMM_WORLD then dup'ing";
}
else
*comm = MPI_COMM_NULL;
/* this split is effectively a dup but tests the split code paths */
merr = MPI_Comm_split(mcomm, 0, rank, comm);
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(interCommName) = "Intercomm by splitting MPI_COMM_WORLD then then splitting again";
+ interCommName = "Intercomm by splitting MPI_COMM_WORLD then then splitting again";
}
else
*comm = MPI_COMM_NULL;
merr = MPI_Intercomm_create( mcomm, 0, MPI_COMM_WORLD, rleader, 12345, comm );
if (merr) MTestPrintError( merr );
}
- SMPI_VARGET_GLOBAL(interCommName) = "Intercomm by splitting MPI_COMM_WORLD (discarding rank 0 in the left group) then MPI_Intercomm_create'ing";
+ interCommName = "Intercomm by splitting MPI_COMM_WORLD (discarding rank 0 in the left group) then MPI_Intercomm_create'ing";
}
else {
*comm = MPI_COMM_NULL;
merr = MPI_Group_free(&newgroup);
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(interCommName) = "Intercomm by splitting MPI_COMM_WORLD then discarding 0 ranks with MPI_Comm_create";
+ interCommName = "Intercomm by splitting MPI_COMM_WORLD then discarding 0 ranks with MPI_Comm_create";
}
else {
*comm = MPI_COMM_NULL;
default:
*comm = MPI_COMM_NULL;
- SMPI_VARGET_GLOBAL(interCommIdx) = -1;
+ interCommIdx = -1;
break;
}
if (size + remsize >= min_size) done = 1;
}
else {
- SMPI_VARGET_GLOBAL(interCommName) = "MPI_COMM_NULL";
+ interCommName = "MPI_COMM_NULL";
done = 1;
}
/* Advance the comm index whether we are done or not, otherwise we could
* spin forever trying to allocate a too-small communicator over and
* over again. */
- SMPI_VARGET_GLOBAL(interCommIdx)++;
+ interCommIdx++;
if (!done && *comm != MPI_COMM_NULL) {
/* avoid leaking communicators */
}
}
- return SMPI_VARGET_GLOBAL(interCommIdx);
+ return interCommIdx;
}
/* Return the name of an intercommunicator */
const char *MTestGetIntercommName( void )
{
- return SMPI_VARGET_GLOBAL(interCommName);
+ return interCommName;
}
/* Get a communicator of a given minimum size. Both intra and inter
int MTestGetComm( MPI_Comm *comm, int min_size )
{
int idx=0;
- SMPI_VARINIT_STATIC_AND_SET(getinter, int, 0);
+ static int getinter = 0;
- if (!SMPI_VARGET_STATIC(getinter)) {
+ if (!getinter) {
idx = MTestGetIntracomm( comm, min_size );
if (idx == 0) {
- SMPI_VARGET_STATIC(getinter) = 1;
+ getinter = 1;
}
}
- if (SMPI_VARGET_STATIC(getinter)) {
+ if (getinter) {
int isLeft;
idx = MTestGetIntercomm( comm, &isLeft, min_size );
if (idx == 0) {
- SMPI_VARGET_STATIC(getinter) = 0;
+ getinter = 0;
}
}
{
va_list list;
- if (SMPI_VARGET_GLOBAL(verbose) && level >= SMPI_VARGET_GLOBAL(verbose)) {
+ if (verbose && level >= verbose) {
va_start(list,format);
vprintf( format, list );
va_end(list);
{
#ifdef HAVE_GETRUSAGE
struct rusage ru;
- SMPI_VARINIT_STATIC_AND_SET(pfThreshold, int, -2);
+ static int pfThreshold = -2;
int doOutput = 1;
if (getrusage( RUSAGE_SELF, &ru ) == 0) {
/* There is an option to generate output only when a resource
exceeds a threshold. To date, only page faults supported. */
- if (SMPI_VARGET_STATIC(pfThreshold) == -2) {
+ if (pfThreshold == -2) {
char *p = getenv("MPITEST_RUSAGE_PF");
- SMPI_VARGET_STATIC(pfThreshold) = -1;
+ pfThreshold = -1;
if (p) {
- SMPI_VARGET_STATIC(pfThreshold) = strtol( p, 0, 0 );
+ pfThreshold = strtol( p, 0, 0 );
}
}
- if (SMPI_VARGET_STATIC(pfThreshold) > 0) {
- doOutput = ru.ru_minflt > SMPI_VARGET_STATIC(pfThreshold);
+ if (pfThreshold > 0) {
+ doOutput = ru.ru_minflt > pfThreshold;
}
if (doOutput) {
/* Cast values to long in case some system has defined them
/*
* Create MPI Windows
*/
-SMPI_VARINIT_GLOBAL_AND_SET(win_index, int, 0);
-SMPI_VARINIT_GLOBAL(winName, const char *);
+static int win_index = 0;
+static const char *winName;
/* Use an attribute to remember the type of memory allocation (static,
malloc, or MPI_Alloc_mem) */
-SMPI_VARINIT_GLOBAL_AND_SET(mem_keyval, int, MPI_KEYVAL_INVALID);
+static int mem_keyval = MPI_KEYVAL_INVALID;
int MTestGetWin( MPI_Win *win, int mustBePassive )
{
- typedef char actbuf_type[1024];
- SMPI_VARINIT_STATIC(actbuf, actbuf_type);
- SMPI_VARINIT_STATIC(pasbuf, char *);
+ static char actbuf[1024];
+ static char *pasbuf;
char *buf;
int n, rank, merr;
MPI_Info info;
- if (SMPI_VARGET_GLOBAL(mem_keyval) == MPI_KEYVAL_INVALID) {
+ if (mem_keyval == MPI_KEYVAL_INVALID) {
/* Create the keyval */
merr = MPI_Win_create_keyval( MPI_WIN_NULL_COPY_FN,
MPI_WIN_NULL_DELETE_FN,
- &SMPI_VARGET_GLOBAL(mem_keyval), 0 );
+ &mem_keyval, 0 );
if (merr) MTestPrintError( merr );
}
- switch (SMPI_VARGET_GLOBAL(win_index)) {
+ switch (win_index) {
case 0:
/* Active target window */
- merr = MPI_Win_create( SMPI_VARGET_STATIC(actbuf), 1024, 1, MPI_INFO_NULL, MPI_COMM_WORLD,
+ merr = MPI_Win_create( actbuf, 1024, 1, MPI_INFO_NULL, MPI_COMM_WORLD,
win );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(winName) = "active-window";
- merr = MPI_Win_set_attr( *win, SMPI_VARGET_GLOBAL(mem_keyval), (void *)0 );
+ winName = "active-window";
+ merr = MPI_Win_set_attr( *win, mem_keyval, (void *)0 );
if (merr) MTestPrintError( merr );
break;
case 1:
/* Passive target window */
- merr = MPI_Alloc_mem( 1024, MPI_INFO_NULL, &SMPI_VARGET_STATIC(pasbuf) );
+ merr = MPI_Alloc_mem( 1024, MPI_INFO_NULL, &pasbuf );
if (merr) MTestPrintError( merr );
- merr = MPI_Win_create( SMPI_VARGET_STATIC(pasbuf), 1024, 1, MPI_INFO_NULL, MPI_COMM_WORLD,
+ merr = MPI_Win_create( pasbuf, 1024, 1, MPI_INFO_NULL, MPI_COMM_WORLD,
win );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(winName) = "passive-window";
- merr = MPI_Win_set_attr( *win, SMPI_VARGET_GLOBAL(mem_keyval), (void *)2 );
+ winName = "passive-window";
+ merr = MPI_Win_set_attr( *win, mem_keyval, (void *)2 );
if (merr) MTestPrintError( merr );
break;
case 2:
merr = MPI_Win_create( buf, n, 1, MPI_INFO_NULL, MPI_COMM_WORLD,
win );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(winName) = "active-all-different-win";
- merr = MPI_Win_set_attr( *win, SMPI_VARGET_GLOBAL(mem_keyval), (void *)1 );
+ winName = "active-all-different-win";
+ merr = MPI_Win_set_attr( *win, mem_keyval, (void *)1 );
if (merr) MTestPrintError( merr );
break;
case 3:
if (merr) MTestPrintError( merr );
merr = MPI_Info_free( &info );
if (merr) MTestPrintError( merr );
- SMPI_VARGET_GLOBAL(winName) = "active-nolocks-all-different-win";
- merr = MPI_Win_set_attr( *win, SMPI_VARGET_GLOBAL(mem_keyval), (void *)1 );
+ winName = "active-nolocks-all-different-win";
+ merr = MPI_Win_set_attr( *win, mem_keyval, (void *)1 );
if (merr) MTestPrintError( merr );
break;
default:
- SMPI_VARGET_GLOBAL(win_index) = -1;
+ win_index = -1;
}
- SMPI_VARGET_GLOBAL(win_index)++;
- return SMPI_VARGET_GLOBAL(win_index);
+ win_index++;
+ return win_index;
}
/* Return a pointer to the name associated with a window object */
const char *MTestGetWinName( void )
{
- return SMPI_VARGET_GLOBAL(winName);
+ return winName;
}
/* Free the storage associated with a window object */
void MTestFreeWin( MPI_Win *win )
}
if (addr) {
void *val;
- merr = MPI_Win_get_attr( *win, SMPI_VARGET_GLOBAL(mem_keyval), &val, &flag );
+ merr = MPI_Win_get_attr( *win, mem_keyval, &val, &flag );
if (merr) MTestPrintError( merr );
if (flag) {
if (val == (void *)1) {
}
static void MTestRMACleanup( void )
{
- if (SMPI_VARGET_GLOBAL(mem_keyval) != MPI_KEYVAL_INVALID) {
- MPI_Win_free_keyval( &SMPI_VARGET_GLOBAL(mem_keyval) );
+ if (mem_keyval != MPI_KEYVAL_INVALID) {
+ MPI_Win_free_keyval( &mem_keyval );
}
}
#else