Commit a22ba06b authored by Deike Kleberg's avatar Deike Kleberg
Browse files

Inserted namespace.c, upgraded grid.c for the use of namespaces, temp switch TEST_LOCAL in cdi.h

for testing locally.
parent 171923a6
......@@ -195,6 +195,7 @@ src/make_cdilib -text
src/make_fint.c -text
src/mo_cdi.f90 -text
src/model.c -text
src/namespace.c -text
src/pio.c -text
src/pio.h -text
src/pio_c_temp.h -text
......
......@@ -45,7 +45,6 @@ int nodeSizes[nNodes] = {1,2};
11,11,11,11,11 };
*/
int nodeSizes[nNodes] = {1};
int nStreams = 4;
int streamSizes[4] = {2,5,1,3};
......@@ -57,15 +56,17 @@ void modelRun ()
int gridID, zaxisID1, zaxisID2, taxisID;
int vlistID, varID1, varID2, streamID, tsID;
int i, nmiss = 0;
double lons[nlon] = {0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330};
double lons[nlon] = {0, 30, 60, 91830, 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 var1[nlon*nlat];
double var2[nlon*nlat*nlev];
int gridID_test;
if ( ddebug >= 3 )
myDebug ( __FILE__, fnName, __LINE__ );
if ( ddebug >= 3 ) xdebug ( fnName );
namespaceSetNumber ( 2 );
namespaceSetActive ( 0 );
// Create a regular lon/lat grid
gridID = gridCreate(GRID_LONLAT, nlon*nlat);
gridDefXsize(gridID, nlon);
......@@ -73,6 +74,24 @@ void modelRun ()
gridDefXvals(gridID, lons);
gridDefYvals(gridID, lats);
// Test namespaces: Create a 2. regular lon/lat grid
namespaceSetActive ( 1 );
gridID_test = gridCreate(GRID_LONLAT, (nlon-1)*(nlat-1));
gridDefXsize(gridID_test, nlon-1);
gridDefYsize(gridID_test, nlat-1);
gridDefXvals(gridID_test, lons);
gridDefYvals(gridID_test, lats);
gridID_test = gridCreate(GRID_LONLAT, (nlon-2)*(nlat-2));
gridDefXsize(gridID_test, nlon-2);
gridDefYsize(gridID_test, nlat-2);
gridDefXvals(gridID_test, lons);
gridDefYvals(gridID_test, lats);
gridTestNamespace ();
namespaceSetActive ( 0 );
// Create a surface level Z-axis
zaxisID1 = zaxisCreate(ZAXIS_SURFACE, 1);
......@@ -99,6 +118,7 @@ void modelRun ()
// Create a dataset in netCDF fromat
streamID = streamOpenWrite("example.grb", FILETYPE_GRB);
if ( streamID < 0 )
{
......@@ -156,17 +176,16 @@ int main (int argc, char *argv[])
MPI_Comm_size ( commGlob, &sizeGlob );
MPI_Comm_rank ( commGlob, &rankGlob );
if ( nProcsIO <=0 || nProcsIO >= ( float ) sizeGlob / 2.0 )
if ( nProcsIO <=0 || nProcsIO >= ( float ) sizeGlob / 2.0 && ! TEST_LOCAL )
pcdiAbort ( "bad distribution of tasks on PEs", __FILE__, __LINE__, rankGlob );
if ( ddebug >= 3 )
myDebug ( __FILE__, fnName, __LINE__ );
if ( ddebug >= 3 ) xdebug ( fnName );
commModel = pioInit_c ( commGlob, nProcsIO, 1 );
//commModel = pioInit_c ( commGlob, nProcsIO, 0 );
//modelRun ();
modelRun ();
pioFinalize ();
//pioFinalize ();
MPI_Finalize ();
return 0;
......
......@@ -49,6 +49,7 @@ libcdi_la_SOURCES = \
ieglib.c \
institution.c \
model.c \
namespace.c \
pio.c \
pio.h \
pio_c_temp.h \
......
......@@ -64,8 +64,8 @@ am_libcdi_la_OBJECTS = basetime.lo binary.lo calendar.lo cdf.lo \
cdf_int.lo cdi_error.lo cdi_util.lo cdiFortran.lo \
cgribexlib.lo dmemory.lo error.lo extralib.lo file.lo \
gaussgrid.lo gribapi.lo grid.lo ieglib.lo institution.lo \
model.lo pio.lo pio_dbuffer.lo pio_interface.lo pio_mpinonb.lo \
pio_posixasynch.lo pio_posixfpguardsendrecv.lo \
model.lo namespace.lo pio.lo pio_dbuffer.lo pio_interface.lo \
pio_mpinonb.lo pio_posixasynch.lo pio_posixfpguardsendrecv.lo \
pio_posixfpguardthread.lo pio_posixfpguardthreadrefuse.lo \
pio_posixnonb.lo pio_queue.lo pio_rpc.lo pio_server.lo \
pio_util.lo servicelib.lo stream_cdf.lo stream_cgribex.lo \
......@@ -299,6 +299,7 @@ libcdi_la_SOURCES = \
ieglib.c \
institution.c \
model.c \
namespace.c \
pio.c \
pio.h \
pio_c_temp.h \
......@@ -479,6 +480,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ieglib.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/institution.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/namespace.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_dbuffer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_interface.Plo@am__quote@
......
......@@ -198,11 +198,19 @@ extern "C" {
#define PIO_POSIX_FPGUARD_SENDRECV 4
#define PIO_POSIX_FPGUARD_THREAD_REFUSE 5
#define PIO_POSIX_FPGUARD_THREAD 6
#define TEST_LOCAL 1
int pioInit ( int, int, int );
int pioInit ( int, int, int );
void pioFinalize ( void );
void namespaceSetNumber ( int );
int namespaceGetNumber ();
void namespaceSetActive ( int );
int namespaceGetActive ();
void gridTestNamespace ();
/* CDI control routines */
char *cdiStringError(int cdiErrno);
......
......@@ -1067,8 +1067,9 @@ int fileOpen(const char *filename, const char *mode)
/* begin deike */
#ifdef USE_MPI
if ( memcmp ( mode, "w", 1 ) == 0 && pioinfo->type != PIO_NONE )
return pioFileOpenW ( filename );
if ( ! TEST_LOCAL )
if ( memcmp ( mode, "w", 1 ) == 0 && pioinfo->type != PIO_NONE )
return pioFileOpenW ( filename );
#endif
/* end deike */
......@@ -1162,7 +1163,8 @@ int fileClose(int fileID)
/* begin deike */
#ifdef USE_MPI
if ( pioinfo->type != PIO_NONE )
if ( ! TEST_LOCAL )
if ( pioinfo->type != PIO_NONE )
return pioFileClose ( fileID );
#endif
/* end deike */
......
......@@ -9,6 +9,7 @@
#include "stream_int.h"
#include "grid.h"
#include "gaussgrid.h"
#include "pio_util.h"
#ifndef RAD2DEG
......@@ -40,7 +41,7 @@ char *Grids[] = {
};
static int GRID_Debug = 0; /* If set to 1, debugging */
static int GRID_Debug = 1; /* If set to 1, debugging */
static int _grid_max = MAX_GRIDS;
......@@ -76,45 +77,97 @@ typedef struct _gridPtrToIdx {
} gridPtrToIdx;
static gridPtrToIdx *_gridList = NULL;
static gridPtrToIdx *_gridAvail = NULL;
static gridPtrToIdx **_gridList = NULL;
static gridPtrToIdx **_gridAvail = NULL;
void gridTestNamespace ()
{
int i, j, sizeGridList, temp;
if ( _grid_init )
{
temp = namespaceGetActive ();
for ( i = 0; i < namespaceGetNumber (); i++ )
{
namespaceSetActive ( i );
sizeGridList = gridSize();
fprintf ( stdout, "######### namespace=%d, size of _gridList: %d\n",
i, sizeGridList );
for ( j = 0; j < sizeGridList; j++)
gridPrint ( _gridList[i][j].ptr->self, 0 );
}
namespaceSetActive ( temp );
}
}
static
void grid_list_new(void)
{
assert(_gridList == NULL);
int nnsp, i;
_gridList = (gridPtrToIdx *) malloc(_grid_max*sizeof(gridPtrToIdx));
nnsp = namespaceGetNumber ();
fprintf ( stdout, "grid_list_new()\n" );
for ( i = 0; i < nnsp; i++ )
{
assert(_gridList[i] == NULL);
_gridList[i] = (gridPtrToIdx *) malloc(_grid_max*sizeof(gridPtrToIdx));
}
}
static
void grid_list_delete(void)
{
if ( _gridList ) free(_gridList);
int i, nnsp;
nnsp = namespaceGetNumber ();
if ( _gridList )
{
for ( i = 0; i < nnsp; i++ )
if ( _gridList[i] ) free ( _gridList[i] );
free ( _gridList );
}
if ( _gridAvail ) free ( _gridAvail );
}
static
void grid_init_pointer(void)
{
int i;
for ( i = 0; i < _grid_max; i++ )
{
_gridList[i].next = _gridList + i + 1;
_gridList[i].idx = i;
_gridList[i].ptr = 0;
}
int nnsp, i, j;
_gridList[_grid_max-1].next = 0;
nnsp = namespaceGetNumber ();
_gridAvail = _gridList;
for ( i = 0; i < nnsp; i++ )
{
for ( j = 0; j < _grid_max; j++ )
{
_gridList[i][j].next = _gridList[i] + j + 1;
_gridList[i][j].idx = j;
_gridList[i][j].ptr = 0;
}
_gridList[i][_grid_max-1].next = 0;
_gridAvail[i] = _gridList[i];
}
}
static
grid_t *grid_to_pointer(int idx)
{
grid_t *gridptr = NULL;
int nsp;
nsp = namespaceGetActive ();
GRID_INIT();
......@@ -122,7 +175,7 @@ grid_t *grid_to_pointer(int idx)
{
GRID_LOCK();
gridptr = _gridList[idx].ptr;
gridptr = _gridList[nsp][idx].ptr;
GRID_UNLOCK();
}
......@@ -138,15 +191,18 @@ int grid_from_pointer(grid_t *ptr)
{
int idx = -1;
gridPtrToIdx *newptr;
int nsp;
nsp = namespaceGetActive ();
if ( ptr )
{
GRID_LOCK();
if ( _gridAvail )
if ( _gridAvail[nsp] )
{
newptr = _gridAvail;
_gridAvail = _gridAvail->next;
newptr = _gridAvail[nsp];
_gridAvail[nsp] = _gridAvail[nsp]->next;
newptr->next = 0;
idx = newptr->idx;
newptr->ptr = ptr;
......@@ -248,6 +304,9 @@ static
void grid_delete_entry(grid_t *gridptr)
{
int idx;
int nsp;
nsp = namespaceGetActive ();
idx = gridptr->self;
......@@ -255,9 +314,9 @@ void grid_delete_entry(grid_t *gridptr)
free(gridptr);
_gridList[idx].next = _gridAvail;
_gridList[idx].ptr = 0;
_gridAvail = &_gridList[idx];
_gridList[nsp][idx].next = _gridAvail[nsp];
_gridList[nsp][idx].ptr = 0;
_gridAvail[nsp] = &_gridList[nsp][idx];
GRID_UNLOCK();
......@@ -269,6 +328,9 @@ static
void grid_initialize(void)
{
char *env;
int nnsp;
fprintf ( stdout, "grid_initialize()\n" );
#if defined (HAVE_LIBPTHREAD)
/* initialize global API mutex lock */
......@@ -278,6 +340,10 @@ void grid_initialize(void)
env = getenv("GRID_DEBUG");
if ( env ) GRID_Debug = atoi(env);
nnsp = namespaceGetNumber ();
_gridList = xmalloc ( nnsp * sizeof ( _gridList[0] ));
_gridAvail = xmalloc ( nnsp * sizeof ( _gridList[0] ));
grid_list_new();
atexit(grid_list_delete);
......@@ -313,13 +379,16 @@ int gridSize(void)
{
int gridsize = 0;
long i;
int nsp;
nsp = namespaceGetActive ();
GRID_INIT();
GRID_LOCK();
for ( i = 0; i < _grid_max; i++ )
if ( _gridList[i].ptr ) gridsize++;
if ( _gridList[nsp][i].ptr ) gridsize++;
GRID_UNLOCK();
......@@ -552,6 +621,7 @@ int gridCreate(int gridtype, int size)
}
gridDefXlongname(gridID, "longitude");
gridDefYlongname(gridID, "latitude");
/*
if ( gridtype == GRID_CURVILINEAR )
{
......
#include <stdlib.h>
#include "cdi.h"
enum { MAX_NAMESPACES = 16 };
static int nNamespaces = 1;
static int activeNamespace;
void namespaceSetNumber ( int nspn )
{
if ( nspn > MAX_NAMESPACES || nspn <= 1 )
abort ();
nNamespaces = nspn;
}
int namespaceGetNumber ()
{
return nNamespaces;
}
void namespaceSetActive ( int nId )
{
if ( nId >= nNamespaces || nId < 0 )
abort ();
activeNamespace = nId;
}
int namespaceGetActive ()
{
return activeNamespace;
}
......@@ -19,6 +19,7 @@ void pcdiAbort ( char *errorString, const char *filename, int line, int rank )
void * pcdiXmalloc ( size_t size, const char *filename, int line )
{
void * value = malloc ( size );
memset ( value, 0, size );
if ( value == NULL )
pcdiAbort ( "malloc failed", filename, line, -1 );
......
......@@ -41,10 +41,11 @@ void pcdiAbort ( char *, const char *, int, int );
void * pcdiXmalloc ( size_t, const char *, int );
#define xmalloc(size) pcdiXmalloc ( size, __FILE__, __LINE__ )
void pcdiXMPI ( int, const char *, int );
#define xmpi(ret) pcdiXMPI(ret, __FILE__, __LINE__)
#define xmpi(ret) pcdiXMPI ( ret, __FILE__, __LINE__ )
void pcdiXMPIStat ( int, const char *, int, MPI_Status * );
#define xmpiStat(ret,stat) pcdiXMPIStat ( ret, __FILE__, __LINE__, stat )
void myDebug ( const char *, const char *, int );
#define xdebug(fun) myDebug ( __FILE__, fun, __LINE__ )
void myDebugComm ( const char *filename, const char *functionname, int line, MPI_Comm *comm );
#endif
......@@ -580,7 +580,7 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
/* begin deike */
#ifdef USE_MPI
if ( pioinfo->type != PIO_NONE )
if ( pioinfo->type != PIO_NONE && ! TEST_LOCAL )
nwrite = pioFileWrite ( fileID, tsID, gribbuffer, nbytes );
else
nwrite = fileWrite(fileID, gribbuffer, nbytes);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment