Commit 5d790ed9 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Introduce test case for copying of resources.

parent fc52b332
......@@ -336,6 +336,7 @@ tests/test_cksum_nc4.in -text
tests/test_cksum_service.in -text
tests/test_grib.c -text
tests/test_grib.sh -text
tests/test_resource_copy.c -text
tests/var_cksum.c -text
tests/var_cksum.h -text
util/mpi_launch_poe -text
......
......@@ -4,7 +4,8 @@ TESTS = test_grib.sh test_cksum_grib test_cksum_nc test_cksum_extra \
test_cksum_service test_cksum_nc2 test_cksum_nc4 test_cksum_ieg \
pio_write_run pio_cksum_mpinonb pio_cksum_fpguard \
pio_cksum_asynch pio_cksum_writer pio_cksum_cdf
check_PROGRAMS = test_grib cksum_write cksum_read pio_write
check_PROGRAMS = test_grib cksum_write cksum_read pio_write \
test_resource_copy
#
test_grib_SOURCES = test_grib.c
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
......@@ -14,6 +15,7 @@ cksum_read_SOURCES = cksum_read.c \
cksum.c cksum.h \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c cksum.h cksum.c
test_resource_copy_SOURCES = test_resource_copy.c
#
AM_CFLAGS = $(YAXT_CFLAGS)
LDADD = ../src/libcdi.la -lm
......
......@@ -51,7 +51,8 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
check_PROGRAMS = test_grib$(EXEEXT) cksum_write$(EXEEXT) \
cksum_read$(EXEEXT) pio_write$(EXEEXT)
cksum_read$(EXEEXT) pio_write$(EXEEXT) \
test_resource_copy$(EXEEXT)
subdir = tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/pio_cksum_asynch.in $(srcdir)/pio_cksum_cdf.in \
......@@ -102,6 +103,10 @@ am_test_grib_OBJECTS = test_grib.$(OBJEXT)
test_grib_OBJECTS = $(am_test_grib_OBJECTS)
test_grib_LDADD = $(LDADD)
test_grib_DEPENDENCIES = ../src/libcdi.la
am_test_resource_copy_OBJECTS = test_resource_copy.$(OBJEXT)
test_resource_copy_OBJECTS = $(am_test_resource_copy_OBJECTS)
test_resource_copy_LDADD = $(LDADD)
test_resource_copy_DEPENDENCIES = ../src/libcdi.la
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
am__depfiles_maybe = depfiles
......@@ -116,9 +121,11 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(cksum_read_SOURCES) $(cksum_write_SOURCES) \
$(pio_write_SOURCES) $(test_grib_SOURCES)
$(pio_write_SOURCES) $(test_grib_SOURCES) \
$(test_resource_copy_SOURCES)
DIST_SOURCES = $(cksum_read_SOURCES) $(cksum_write_SOURCES) \
$(pio_write_SOURCES) $(test_grib_SOURCES)
$(pio_write_SOURCES) $(test_grib_SOURCES) \
$(test_resource_copy_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
......@@ -331,6 +338,7 @@ cksum_read_SOURCES = cksum_read.c \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c cksum.h cksum.c
test_resource_copy_SOURCES = test_resource_copy.c
#
AM_CFLAGS = $(YAXT_CFLAGS)
LDADD = ../src/libcdi.la -lm
......@@ -420,6 +428,9 @@ pio_write$(EXEEXT): $(pio_write_OBJECTS) $(pio_write_DEPENDENCIES) $(EXTRA_pio_w
test_grib$(EXEEXT): $(test_grib_OBJECTS) $(test_grib_DEPENDENCIES) $(EXTRA_test_grib_DEPENDENCIES)
@rm -f test_grib$(EXEEXT)
$(LINK) $(test_grib_OBJECTS) $(test_grib_LDADD) $(LIBS)
test_resource_copy$(EXEEXT): $(test_resource_copy_OBJECTS) $(test_resource_copy_DEPENDENCIES) $(EXTRA_test_resource_copy_DEPENDENCIES)
@rm -f test_resource_copy$(EXEEXT)
$(LINK) $(test_resource_copy_OBJECTS) $(test_resource_copy_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
......@@ -434,6 +445,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cksum.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_grib.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_resource_copy.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/var_cksum.Po@am__quote@
.c.o:
......
#if defined (HAVE_CONFIG_H)
#include "config.h"
#endif
#include <stdio.h>
#ifdef USE_MPI
#include <mpi.h>
#include "cdi.h"
#include "pio_util.h"
extern int reshListCompare ( int, int );
extern void reshPackBufferCreate ( char **, int *, MPI_Comm );
extern void reshPackBufferDestroy ( char ** );
extern void rpcUnpackResources ( char *, int, MPI_Comm );
extern void arrayDestroy ( void );
enum {
IOMode = PIO_NONE,
nProcsIO = 1,
nNamespaces = 2,
DOUBLE_PRECISION = 8,
nlon = 12,
nlat = 6,
nlev = 5,
ntsteps = 3 };
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};
int defineGrid ()
{
int gridID = CDI_UNDEFID;
int mask_vec[nlon*nlat];
const int * mp = &mask_vec[0];
double area_vec[nlon*nlat];
const double * ap = &area_vec[0];
int i;
gridID = gridCreate(GRID_LONLAT, nlon*nlat);
gridDefXsize(gridID, nlon);
gridDefYsize(gridID, nlat);
gridDefXvals(gridID, lons);
gridDefYvals(gridID, lats);
gridDefNvertex ( gridID, 1 );
gridDefXbounds ( gridID, lons );
gridDefYbounds ( gridID, lats );
for ( i = 0; i < nlon*nlat; i++ )
mask_vec[i] = i % 2 ;
gridDefMaskGME ( gridID, mp );
for ( i = 0; i < nlon*nlat; i++ )
mask_vec[i] = 1;
gridDefMask ( gridID, mp );
gridDefXname ( gridID, "myXname" );
gridDefXlongname ( gridID, "myXlongname" );
gridDefXunits ( gridID, "myXunits" );
gridDefYname ( gridID, "myYname" );
gridDefYlongname ( gridID, "myYlongname" );
gridDefYunits ( gridID, "myYunits" );
gridDefPrec ( gridID, DOUBLE_PRECISION );
gridDefXpole ( gridID, 90.0 );
gridDefYpole ( gridID, 180.0 );
gridDefAngle ( gridID, 360.0 );
gridDefTrunc ( gridID, 1 );
gridDefGMEnd ( gridID, 2 );
gridDefGMEni ( gridID, 3 );
gridDefGMEni2 ( gridID, 4 );
gridDefGMEni3 ( gridID, 5 );
gridDefNumber ( gridID, 6 );
gridDefPosition ( gridID, 7 );
gridDefReference ( gridID, "myReference" );
/* gridDefLCC ( gridID, double originLon, double originLat, */
/* double lonParY, double lat1, double lat2, double xinc, double yinc, int projflag, int scanflag); */
/* gridDefLcc2 ( gridID, double earth_radius, double lon_0, */
/* double lat_0, double lat_1,double lat_2);*/
/* gridDefLaea ( gridID, double earth_radius, double lon_0, double lat_0); */
for ( i = 0; i < nlon*nlat; i++ )
area_vec[i] = 0.1 * i;
gridDefArea ( gridID, ap );
for ( i = 0; i < nlon*nlat; i++ )
mask_vec[i] = i;
gridDefRowlon ( gridID, nlon*nlat, mp );
gridDefComplexPacking ( gridID, 1 );
return gridID;
}
int defineZaxis ()
{
int zaxisID = CDI_UNDEFID;
double vct[3] = { 3.0, 3.3, 3.6 };
zaxisID = zaxisCreate(ZAXIS_PRESSURE, nlev);
zaxisDefLevels(zaxisID, levs);
zaxisDefLevel ( zaxisID, 2, 8507.3 );
zaxisDefName ( zaxisID, "myName" );
zaxisDefLongname ( zaxisID, "myLongname" );
zaxisDefUnits ( zaxisID, "myUnits" );
zaxisDefPrec ( zaxisID, DOUBLE_PRECISION );
zaxisDefLtype ( zaxisID, 1 );
zaxisDefVct ( zaxisID, 3, vct );
zaxisDefLbounds ( zaxisID, &levs[0] );
zaxisDefUbounds ( zaxisID, &levs[0] );
zaxisDefWeights ( zaxisID, &levs[0] );
return zaxisID;
}
int defineTaxis ()
{
int taxisID = CDI_UNDEFID;
taxisID = taxisCreate(TAXIS_ABSOLUTE);
taxisDefType ( taxisID, 0 );
taxisDefVdate ( taxisID, 1 );
taxisDefVtime ( taxisID, 2 );
taxisDefRdate ( taxisID, 3 );
taxisDefRtime ( taxisID, 4 );
taxisDefVdateBounds ( taxisID, 5, 6 );
taxisDefVtimeBounds ( taxisID, 7, 8 );
taxisDefCalendar ( taxisID, 1 );
taxisDefTunit ( taxisID, 1 );
taxisDefNumavg ( taxisID, 1 );
return taxisID;
}
void defineStream ( int streamID, int vlistID )
{
streamDefByteorder ( streamID, 1 );
streamDefCompType ( streamID, 2 );
streamDefCompLevel ( streamID, 3 );
streamDefVlist(streamID, vlistID);
}
int defineVlist ( int gridID, int zaxisID, int taxisID )
{
int vlistID = CDI_UNDEFID;
int zaxisID2 = zaxisCreate(ZAXIS_SURFACE, 1);
int varID1, varID2;
vlistID = vlistCreate();
varID1 = vlistDefVar(vlistID, gridID, zaxisID, TIME_VARIABLE);
varID2 = vlistDefVar(vlistID, gridID, zaxisID2, TIME_VARIABLE);
vlistDefVarName(vlistID, varID1, "varname1");
{
int globfac[] = { 23, 42 };
vlistDefAttInt(vlistID, varID1, "seer's globule factors", DATATYPE_INT16,
2, globfac);
}
vlistDefVarName(vlistID, varID2, "varname2");
vlistDefAttTxt(vlistID, varID2, "txt demo", 6, "banana");
vlistDefTaxis(vlistID, taxisID);
return vlistID;
}
int defineInstitute ()
{
int instID = CDI_UNDEFID;
instID = institutDef( 0, 0,"MYINSTITUTE", "myInstitute");
return instID;
}
int defineModel ( int instID )
{
int modelID = CDI_UNDEFID;
modelID = modelDef ( instID, 0, "myModel");
return modelID;
}
void modelRun ( MPI_Comm comm )
{
int gridID, zaxisID, taxisID, instID, modelID, vlistID, streamID;
char * recvBuffer, * sendBuffer;
int bufferSize, differ;
MPI_Status status;
pioNamespaceSetActive ( 0 );
gridID = defineGrid ();
zaxisID = defineZaxis ();
taxisID = defineTaxis ();
instID = defineInstitute ();
modelID = defineModel ( instID );
vlistID = defineVlist ( gridID, zaxisID, taxisID);
streamID = streamOpenWrite("example.grb", FILETYPE_GRB);
if ( streamID < 0 ) xabort ( "Could not open file" );
defineStream ( streamID, vlistID );
reshPackBufferCreate ( &sendBuffer, &bufferSize, comm );
xmpi ( MPI_Send ( sendBuffer, bufferSize, MPI_PACKED, 0, 0, comm ));
recvBuffer = xmalloc ( bufferSize * sizeof ( char ));
xmpi ( MPI_Recv ( recvBuffer, bufferSize, MPI_PACKED, 0,
0, comm, &status ));
pioNamespaceSetActive ( 1 );
rpcUnpackResources ( recvBuffer, bufferSize, comm );
free ( recvBuffer );
reshPackBufferDestroy ( &sendBuffer );
differ = reshListCompare ( 0, 1 );
printf ( "The resource arrays %s.\n", differ ? "differ" : "are equal" );
reshListPrint ( "reshArrayModel" );
pioNamespaceSetActive ( 0 );
streamClose(streamID);
return;
}
#endif
int main (int argc, char *argv[])
{
#ifdef USE_MPI
int sizeGlob, pioNamespace;
MPI_Comm commGlob, commModel;
MPI_Init(&argc, &argv);
xmpi ( MPI_Comm_dup ( MPI_COMM_WORLD, &commGlob ));
xmpi ( MPI_Comm_set_errhandler ( commGlob, MPI_ERRORS_RETURN ));
xmpi ( MPI_Comm_size ( commGlob, &sizeGlob ));
if ( sizeGlob != 1 )
xabort ( "test transition of resource array only with 1 PE." );
if ( nProcsIO != 1 )
xabort ( "bad distribution of tasks on PEs" );
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0f);
pioNamespaceSetActive(pioNamespace);
modelRun ( commModel );
MPI_Finalize ();
#else
printf ( "Use MPI for this testprogram.\n" );
#endif
return 0;
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
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