Commit 033d08bb authored by Deike Kleberg's avatar Deike Kleberg
Browse files

used pio_mpi, fixed arrayDestroy()

parent 6822922f
......@@ -2,9 +2,6 @@
# include "config.h"
#endif
#define nProcsIO 1
#define nNodes 1
#ifdef USE_MPI
#include <mpi.h>
#endif
......@@ -13,63 +10,30 @@
#include "pio_c_temp.h"
#include "pio_util.h"
extern void reshArrayPrint ( char * );
#define nProcsIO 1
#define nNodes 1
static int nodeSizes[nNodes] = {1};
static int hasLocalFile[] = { 0 };
#define nVars 5
static int nlev[nVars] = {1,1,5,5,2};
#define nlon 12 // Number of longitudes
#define nlat 6 // Number of latitudes
#define nlev 5 // Number of levels
#define ntsteps 3 // Number of time steps
/*
int nodeSizes[nNodes] = {1,2};
int nStreams = 6;
int streamSizes[6] = {5,127,19,18,9,52};
int vlistSizes[230] = {
1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,
47,47,47,47,47,47,47,47,47,47,
1,1,1,
11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,5,
1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,
11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,
11,11,11,11,11 };
*/
int nodeSizes[nNodes] = {1};
int nStreams = 4;
int streamSizes[4] = {2,5,1,3};
int vlistSizes[11] = {5,1,7,3,2,47,11,11,5,47,1 };
#define nlon 12
#define nlat 6
#define maxlev 5
#define ntsteps 3
void modelRun ()
{
int gridID, zaxisID, taxisID;
int vlistID, varID, streamID, tsID;
int gridID, zaxisID[nVars], taxisID;
int vlistID, varID[nVars], streamID, tsID;
int i, nmiss = 0, rank;
double lons[nlon] = {0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330};
double lats[nlat] = {-75, -45, -15, 15, 45, 75};
double levs[nlev] = {101300, 92500, 85000, 50000, 20000};
double var[nlon*nlat*nlev];
double levs[maxlev] = {101300, 92500, 85000, 50000, 20000};
pioNamespaceInit ( 1, hasLocalFile );
......@@ -79,17 +43,16 @@ void modelRun ()
gridDefXvals(gridID, lons);
gridDefYvals(gridID, lats);
zaxisID = zaxisCreate(ZAXIS_PRESSURE, nlev);
zaxisDefLevels(zaxisID, levs);
vlistID = vlistCreate();
varID = vlistDefVar(vlistID, gridID, zaxisID, TIME_VARIABLE);
vlistDefVarName(vlistID, varID, "myVar");
{
int globfac[] = { 23, 42 };
vlistDefAttInt(vlistID, varID, "seer's globule factors", DATATYPE_INT16,
2, globfac); // bug vlistAttunpack: ..DefAtt.. can't be left out
}
for ( i = 0; i < nVars; i++ )
{
zaxisID[i] = zaxisCreate ( ZAXIS_PRESSURE, nlev[i] );
zaxisDefLevels ( zaxisID[i], levs );
}
vlistID = vlistCreate ();
for ( i = 0; i < nVars; i++ )
varID[i] = vlistDefVar ( vlistID, gridID, zaxisID[i], TIME_VARIABLE);
taxisID = taxisCreate(TAXIS_ABSOLUTE);
vlistDefTaxis(vlistID, taxisID);
......@@ -124,11 +87,11 @@ void modelRun ()
if ( rank == 0 ) reshArrayPrint ( "reshArrayModel" );
#endif
streamClose(streamID);
vlistDestroy(vlistID);
taxisDestroy(taxisID);
zaxisDestroy(zaxisID);
for ( i = 0; i < nVars; i++ )
zaxisDestroy ( zaxisID[i] );
gridDestroy(gridID);
pioNamespaceCleanup ();
......@@ -152,7 +115,7 @@ int main (int argc, char *argv[])
if ( nProcsIO <=0 || nProcsIO >= sizeGlob )
xabort ( "bad distribution of tasks on PEs" );
commModel = pioInit_c ( commGlob, nProcsIO, 0 );
commModel = pioInit_c ( commGlob, nProcsIO, PIO_MPI_NONB );
#endif
modelRun ();
......
......@@ -79,8 +79,8 @@ void modelRun ()
int rank;
#ifdef USE_MPI
namespaceInit ( 2, hlf );
namespaceSetActive ( 0 );
pioNamespaceInit ( 2, hlf );
pioNamespaceSetActive ( 0 );
#endif
// Create a regular lon/lat grid
......@@ -90,10 +90,10 @@ void modelRun ()
gridDefXvals(gridID, lons);
gridDefYvals(gridID, lats);
// Test namespaces: Create a 2. grid list
// Test namespace: Create a 2. grid list
#ifdef USE_MPI
namespaceSetActive ( 1 );
pioNamespaceSetActive ( 1 );
#endif
gridID2 = gridCreate(GRID_LONLAT, (nlon-1)*(nlat-1));
......@@ -109,7 +109,7 @@ void modelRun ()
gridDefYvals(gridID3, lats);
#ifdef USE_MPI
namespaceSetActive ( 0 );
pioNamespaceSetActive ( 0 );
#endif
......@@ -123,13 +123,13 @@ void modelRun ()
// Test namespaces: Create a 2. zaxis list
#ifdef USE_MPI
namespaceSetActive ( 1 );
pioNamespaceSetActive ( 1 );
#endif
zaxisID3 = zaxisCreate(ZAXIS_PRESSURE, 3);
zaxisDefLevels(zaxisID3, levs);
#ifdef USE_MPI
namespaceSetActive ( 0 );
pioNamespaceSetActive ( 0 );
#endif
// Create a variable list
......@@ -156,14 +156,14 @@ void modelRun ()
taxisID2 = taxisCreate(TAXIS_ABSOLUTE);
#ifdef USE_MPI
namespaceSetActive ( 1 );
pioNamespaceSetActive ( 1 );
#endif
taxisID3 = taxisCreate(TAXIS_ABSOLUTE);
taxisID4 = taxisCreate(TAXIS_ABSOLUTE);
taxisID5 = taxisCreate(TAXIS_ABSOLUTE);
#ifdef USE_MPI
namespaceSetActive ( 0 );
pioNamespaceSetActive ( 0 );
#endif
// Assign the Time axis to the variable list
......@@ -222,6 +222,8 @@ void modelRun ()
zaxisDestroy(zaxisID1);
zaxisDestroy(zaxisID2);
gridDestroy(gridID);
pioNamespaceCleanup ();
}
......
......@@ -211,9 +211,6 @@ int pioInit ( int, int, int );
void pioFinalize ( void );
void pioMetadata ( int, int * );
void namespaceInit ( int, int * );//to delete
void namespaceSetActive ( int );//to delete
void pioNamespaceInit ( int, int * );
void pioNamespaceCleanup ( void );
void pioNamespaceSetActive ( int );
......
......@@ -4,7 +4,7 @@
!
! Author:
! -------
! Uwe Schulzweida, MPI-MET, Hamburg, June 2011
! Uwe Schulzweida, MPI-MET, Hamburg, July 2011
!
INTEGER CDI_MAX_NAME
......@@ -349,14 +349,17 @@
! INTEGER )
EXTERNAL pioMetadata
! namespaceInit
! pioNamespaceInit
! (INTEGER ,
! INTEGER )
EXTERNAL namespaceInit
EXTERNAL pioNamespaceInit
! namespaceSetActive
! pioNamespaceCleanup
EXTERNAL pioNamespaceCleanup
! pioNamespaceSetActive
! (INTEGER )
EXTERNAL namespaceSetActive
EXTERNAL pioNamespaceSetActive
! gridGetIndexArray
! (INTEGER ,
......
......@@ -59,8 +59,9 @@
FCALLSCFUN3 (INT, pioInit, PIOINIT, pioinit, INT, INT, INT)
FCALLSCSUB0 (pioFinalize, PIOFINALIZE, piofinalize)
FCALLSCSUB2 (pioMetadata, PIOMETADATA, piometadata, INT, PINT)
FCALLSCSUB2 (namespaceInit, NAMESPACEINIT, namespaceinit, INT, PINT)
FCALLSCSUB1 (namespaceSetActive, NAMESPACESETACTIVE, namespacesetactive, INT)
FCALLSCSUB2 (pioNamespaceInit, PIONAMESPACEINIT, pionamespaceinit, INT, PINT)
FCALLSCSUB0 (pioNamespaceCleanup, PIONAMESPACECLEANUP, pionamespacecleanup)
FCALLSCSUB1 (pioNamespaceSetActive, PIONAMESPACESETACTIVE, pionamespacesetactive, INT)
FCALLSCSUB2 (gridGetIndexArray, GRIDGETINDEXARRAY, gridgetindexarray, INT, PINT)
FCALLSCSUB2 (streamGetIndexArray, STREAMGETINDEXARRAY, streamgetindexarray, INT, PINT)
FCALLSCSUB2 (zaxisGetIndexArray, ZAXISGETINDEXARRAY, zaxisgetindexarray, INT, PINT)
......
......@@ -201,7 +201,11 @@ void file_list_new(void)
void file_list_delete(void)
{
if ( _fileList ) free(_fileList);
if ( _fileList )
{
free(_fileList);
_fileList = NULL;
}
}
static
......@@ -1167,7 +1171,8 @@ int fileClose(int fileID)
/* begin deike */
#ifdef USE_MPI
if ( pioinfo->type != PIO_NONE )
return pioFileClose ( fileID );
return pioFileClose ( fileID );
#endif
/* end deike */
......
......@@ -66,21 +66,6 @@ namespaceTuple_t namespaceResHDecode ( int resH )
return tin;
}
// to delete
void namespaceInit ( int nspn, int * argHasLocalFile )
{
int i;
assert(nspn <= NUM_NAMESPACES && nspn >= 1 );
nNamespaces = nspn;
if ( nspn >= 1 )
{
hasLocalFile = xmalloc ( nspn * sizeof ( int ));
for ( i = 0; i < nspn; i++ )
hasLocalFile[i] = argHasLocalFile[i];
}
}
void pioNamespaceInit ( int nspn, int * argHasLocalFile )
{
......@@ -99,7 +84,11 @@ void pioNamespaceInit ( int nspn, int * argHasLocalFile )
void pioNamespaceCleanup ( void )
{
if ( nNamespaces > 1 ) free ( hasLocalFile );
if ( nNamespaces > 1 )
{
free ( hasLocalFile );
hasLocalFile = NULL;
}
}
......@@ -109,7 +98,7 @@ int namespaceGetNumber ()
}
void namespaceSetActive ( int nId )
void pioNamespaceSetActive ( int nId )
{
if ( nId >= nNamespaces || nId < 0 )
abort ();
......@@ -118,12 +107,6 @@ void namespaceSetActive ( int nId )
}
void pioNamespaceSetActive ( int nId )
{
namespaceSetActive ( nId );
}
int namespaceGetActive ()
{
return activeNamespace;
......@@ -135,7 +118,7 @@ int namespaceHasLocalFile ( int nId )
if ( nId >= nNamespaces || nId < 0 )
abort ();
return hasLocalFile[nId];
return hasLocalFile ? hasLocalFile[nId] : 0;
}
......
......@@ -115,7 +115,6 @@ size_t pioFileWrite ( int id, int tsId, const void *buffer, size_t len )
int pioFileClose ( int id )
{
int iret = CDI_UNDEFID;
switch ( pioinfo->type )
{
case PIO_MPI_NONB:
......@@ -295,7 +294,7 @@ MPI_Comm bInit ( int ptype, MPI_Comm comm, int *color, int *nnodes )
MPI_Comm_rank ( pioinfo->comm, &( pioinfo->rank ));
MPI_Comm_size ( pioinfo->comm, &( pioinfo->size ));
xdebug( "pe%d in bInit(), ptype=%d, initial_buffersize=%ld: "
xdebug( "IOPE%d in bInit(), ptype=%d, initial_buffersize=%ld: "
"after init pioinfo ...",
pioinfo->rank, pioinfo->type, initial_buffersize );
......@@ -330,8 +329,6 @@ MPI_Comm bInit ( int ptype, MPI_Comm comm, int *color, int *nnodes )
}
#endif
xdebug ("out" );
#ifdef USE_MPI
return pioinfo->collectorComm;
#else
......@@ -359,8 +356,6 @@ void bFinalize ()
free ( pioinfo );
#endif
return;
}
/*
* Local Variables:
......
......@@ -14,7 +14,7 @@
#ifdef USE_MPI
#include "pio_impl.h"
bool ldebug =true;
bool ldebug =false;
int dbuffer_init ( struct dBuffer **dbuffer, size_t size )
......
......@@ -90,8 +90,6 @@ MPI_Comm pioInit_c ( MPI_Comm comm, int nIOP, int mode )
MPI_Finalize ();
exit ( 0 );
}
xdebug ( "out" );
return commModel;
}
......@@ -160,8 +158,6 @@ void mapProblems ( int problemSizes[], int * problemMapping, int nProblems,
int sum = 0;
int writerIdx = 0;
int i, j;
if ( ddebug >= 1 ) xdebug ();
for ( i = 0; i < nProblems; i++ )
......@@ -247,9 +243,6 @@ void varMapGen ( int * vSizes, int * sSizes, int * varMapping,
int nVarsNode, summandRank = 0;
int buckets[nProcsIO];
if ( ddebug >= 1 ) xdebug ();
for ( i = 0; i < nStreams; i++ )
{
......@@ -430,8 +423,6 @@ void pioFinalize ()
#ifdef USE_MPI
int i, ibuffer = 1111;
if ( ddebug >= 1 ) xdebug ();
for ( i = 0; i < nProcsIO; i++ )
MPI_Send ( &ibuffer, 1, MPI_INT, nProcsCalc, FINALIZE, *( commsIO + i ));
......
......@@ -51,9 +51,8 @@ static aFiledataM *initAFiledataMPINONB ( const char *filename, size_t bs )
size_t len;
int iret;
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d initAFiledataMPINONB (): filename=%s, buffersize=%zu, in\n",
pioinfo->rank, filename, bs );
xdebug ( "IOPE%d: filename=%s, buffersize=%zu, in",
pioinfo->rank, filename, bs );
of = ( aFiledataM * ) xmalloc ( sizeof ( aFiledataM ));
memset ( of, 0, sizeof ( aFiledataM ));
......@@ -65,9 +64,8 @@ static aFiledataM *initAFiledataMPINONB ( const char *filename, size_t bs )
/* init output buffer */
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d initOpenFileCollector(): name=%s, init output buffer\n",
pioinfo->rank, of->name );
xdebug ( "IOPE%d: name=%s, init output buffer",
pioinfo->rank, of->name );
iret = dbuffer_init ( &( of->db1 ), of->size );
iret += dbuffer_init ( &( of->db2 ), of->size );
......@@ -77,16 +75,14 @@ static aFiledataM *initAFiledataMPINONB ( const char *filename, size_t bs )
of->db = of->db1;
/* open file */
xmpi ( MPI_File_open ( pioinfo->comm, of->name,
( MPI_MODE_CREATE|MPI_MODE_WRONLY ),
MPI_INFO_NULL, &( of->fh )));
of->request = MPI_REQUEST_NULL;
of->finished = false;
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d initAFiledataMPINONB (), opened file %s, return\n",
pioinfo->rank, of->name );
xdebug ( "IOPE%d opened file %s, return",
pioinfo->rank, of->name );
return of;
}
......@@ -101,17 +97,15 @@ int destroyAFiledataMPINONB ( void *v )
of = (aFiledataM * ) v;
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d destroyAFiledataMPINONB(): name=%s, close file, in\n",
pioinfo->rank, of->name );
xdebug ( "IOPE%d: name=%s, close file, in",
pioinfo->rank, of->name );
/* close file */
startTime = MPI_Wtime ();
MPI_Wait ( & ( of->request ), &status );
xmpi ( MPI_Wait ( & ( of->request ), &status ));
accumWait += ( MPI_Wtime () - startTime );
iret = MPI_File_sync ( of->fh );
iret = MPI_File_close ( & ( of->fh ));
/* file closed, cleanup */
......@@ -122,9 +116,8 @@ int destroyAFiledataMPINONB ( void *v )
free ( of->name );
free ( of );
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d destroyAFiledataMPINONB(), closed file, cleaned up, return\n",
pioinfo->rank );
xdebug ( "IOPE%d: closed file, cleaned up, return",
pioinfo->rank );
return iret == MPI_SUCCESS ? 0 : -1;
}
......@@ -160,13 +153,12 @@ void writeMPINONB ( aFiledataM *of, int id )
if ( amount == 0 ) return;
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d writeMPINONB(): Write buffer, size %d bytes, in\n",
pioinfo->rank, amount );
xdebug ( "IOPI%d: Write buffer, size %d bytes, in\n",
pioinfo->rank, amount );
MPI_Wait ( & ( of->request ), &status );
MPI_File_iwrite_shared ( of->fh, of->db->buffer, amount, MPI_CHAR,
& ( of->request ));
xmpi ( MPI_Wait ( & ( of->request ), &status ));
xmpi ( MPI_File_iwrite_shared ( of->fh, of->db->buffer, amount, MPI_CHAR,
& ( of->request )));
/* change outputBuffer */
......@@ -174,15 +166,13 @@ void writeMPINONB ( aFiledataM *of, int id )
if ( of->db == of->db1 )
{
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d writeMPINONB (): id=%d, change to buffer 2 ...\n",
pioinfo->rank, id );
xdebug ( "IOPE%d: id=%d, change to buffer 2 ...",
pioinfo->rank, id );
of->db = of->db2;
}
else
{
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d writeMPINONB (): id=%d, change to buffer 1 ...\n",
xdebug ( "IOPE%d: id=%d, change to buffer 1 ...",
pioinfo->rank, id );
of->db = of->db1;
}
......@@ -206,8 +196,7 @@ size_t fwMPINONB ( int id, int tsId, const void *buffer, size_t len )
if ( flush == 1 )
{
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d fileWriter (): tsId = %d, flush buffer\n",
xdebug ( "IOPE%d: tsId = %d, flush buffer",
pioinfo->rank, tsId );
curr = bibAFiledataM->head;
while ( curr )
......@@ -222,10 +211,9 @@ size_t fwMPINONB ( int id, int tsId, const void *buffer, size_t len )
of = ( aFiledataM * ) queueIdx2val ( bibAFiledataM, id );
filled = dbuffer_push ( of->db, ( unsigned char * ) buffer, len );
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d fileWriter (): id = %d, tsId = %d,"
" pushed data on buffer, filled = %d\n",
pioinfo->rank, id, tsId, filled );
xdebug ( "IOPE%d: id = %d, tsId = %d,"
" pushed data on buffer, filled = %d",
pioinfo->rank, id, tsId, filled );
if ( filled == 1 )
{
......@@ -257,9 +245,8 @@ int fcMPINONB ( int id )
double accumWaitMax;
char errorString[maxErrorString];
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d fileClose (%d ): write buffer, close file and cleanup, in\n",
pioinfo->rank, id );
xdebug ( "IOPE%d: write buffer, close file and cleanup, in",
pioinfo->rank, id );
if ( ! ( of = ( aFiledataM * ) queueIdx2val ( bibAFiledataM, id )))
{
......@@ -275,10 +262,9 @@ int fcMPINONB ( int id )
if ( !bibAFiledataM->head )
{
if ( ddebug == MAXDEBUG )
fprintf ( stderr, "pe%d fileClose (): cleanup queue \n",
pioinfo->rank );
free ( bibAFiledataM );
xdebug ( "IOPE%d: cleanup queue",
pioinfo->rank );
free ( bibAFiledataM );
}
/* timer output */
......@@ -287,11 +273,11 @@ int fcMPINONB ( int id )
{
MPI_Reduce ( &accumWait, &accumWaitMax,
1, MPI_DOUBLE, MPI_MAX, 0, pioinfo->comm );
fprintf ( stderr, "pe%d pioFileClose(): Wait time %15.10lf s\n",
pioinfo->rank, accumWait );
xdebug ( "IOPE%d: Wait time %15.10lf s",
pioinfo->rank, accumWait );
if ( pioinfo->rank == 0 )
fprintf ( stderr, "pe%d pioFileClose(): Max wait time %15.10lf s\n",
pioinfo->rank, accumWaitMax );
xdebug ( "IOPE%d: Max wait time %15.10lf s",
pioinfo->rank, accumWaitMax );
}
return iret;
......@@ -338,9 +324,7 @@ int fowMPINONB ( const char *filename )
if ( ! buffersize )
{
if ( ddebug == MAXDEBUG )
fprintf ( stderr,
"pe%d fowMPINONB(): Broadcast buffersize to collectors ...\n",
xdebug ( "IOPE%d: Broadcast buffersize to collectors ...",
pioinfo->rank );
if ( pioinfo->rank == bcastRank )
......@@ -354,6 +338,8 @@ int fowMPINONB ( const char *filename )
MPI_Bcast ( &buffersize, 1, MPI_LONG, bcastRank, pioinfo->comm );
}
xdebug ( "buffersize=%d", buffersize );
queueCheck ( bibAFiledataM, filename );
of = initAFiledataMPINONB ( filename, buffersize );
......@@ -362,11 +348,9 @@ int fowMPINONB ( const char *filename )
sprintf ( errorString, "filename %s not unique", of->name );
xabort ( errorString );
}
if ( ddebug == MAXDEBUG )
fprintf ( stderr,
"pe%d fowMPINONB(): name=%s, init and enqueued aFiledataM, return id = %d\n",
pioinfo->rank, filename, id );