Commit f30be35d authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add 2D decomposition test.

* It's at the moment identical to the 1D test. That will change with the next commit.
parent b541a473
......@@ -337,6 +337,7 @@ tests/cksum_read.c -text
tests/cksum_verify.c -text
tests/cksum_write.c -text
tests/cksum_write_chunk.c -text
tests/deco2d_model.c -text
tests/ensure_array_size.c -text
tests/ensure_array_size.h -text
tests/pio_cksum_asynch.in -text
......@@ -346,6 +347,7 @@ tests/pio_cksum_mpinonb.in -text
tests/pio_cksum_writer.in -text
tests/pio_write.c -text
tests/pio_write.h -text
tests/pio_write_deco2d_run.in -text
tests/pio_write_run.in -text
tests/simple_model.c -text
tests/stream_cksum.c -text
......
......@@ -27683,7 +27683,7 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
 
 
ac_config_files="$ac_config_files tests/test_cksum_grib tests/test_cksum_nc tests/test_cksum_nc2 tests/test_cksum_nc4 tests/test_cksum_extra tests/test_cksum_service tests/test_cksum_ieg tests/test_chunk_cksum tests/pio_write_run tests/pio_cksum_mpinonb tests/pio_cksum_fpguard tests/pio_cksum_asynch tests/pio_cksum_writer tests/pio_cksum_cdf tests/test_resource_copy_mpi_run util/serialrun"
ac_config_files="$ac_config_files tests/test_cksum_grib tests/test_cksum_nc tests/test_cksum_nc2 tests/test_cksum_nc4 tests/test_cksum_extra tests/test_cksum_service tests/test_cksum_ieg tests/test_chunk_cksum tests/pio_write_run tests/pio_write_deco2d_run tests/pio_cksum_mpinonb tests/pio_cksum_fpguard tests/pio_cksum_asynch tests/pio_cksum_writer tests/pio_cksum_cdf tests/test_resource_copy_mpi_run util/serialrun"
 
 
ac_config_files="$ac_config_files Makefile src/Makefile interfaces/Makefile app/Makefile tests/Makefile examples/Makefile cdi.settings examples/pio/Makefile src/pkgconfig/cdi.pc src/pkgconfig/cdipio.pc"
......@@ -29034,6 +29034,7 @@ do
"tests/test_cksum_ieg") CONFIG_FILES="$CONFIG_FILES tests/test_cksum_ieg" ;;
"tests/test_chunk_cksum") CONFIG_FILES="$CONFIG_FILES tests/test_chunk_cksum" ;;
"tests/pio_write_run") CONFIG_FILES="$CONFIG_FILES tests/pio_write_run" ;;
"tests/pio_write_deco2d_run") CONFIG_FILES="$CONFIG_FILES tests/pio_write_deco2d_run" ;;
"tests/pio_cksum_mpinonb") CONFIG_FILES="$CONFIG_FILES tests/pio_cksum_mpinonb" ;;
"tests/pio_cksum_fpguard") CONFIG_FILES="$CONFIG_FILES tests/pio_cksum_fpguard" ;;
"tests/pio_cksum_asynch") CONFIG_FILES="$CONFIG_FILES tests/pio_cksum_asynch" ;;
......@@ -30866,6 +30867,7 @@ _LT_EOF
"tests/test_cksum_ieg":F) chmod a+x "$ac_file" ;;
"tests/test_chunk_cksum":F) chmod a+x "$ac_file" ;;
"tests/pio_write_run":F) chmod a+x "$ac_file" ;;
"tests/pio_write_deco2d_run":F) chmod a+x "$ac_file" ;;
"tests/pio_cksum_mpinonb":F) chmod a+x "$ac_file" ;;
"tests/pio_cksum_fpguard":F) chmod a+x "$ac_file" ;;
"tests/pio_cksum_asynch":F) chmod a+x "$ac_file" ;;
......
......@@ -326,6 +326,7 @@ AC_CONFIG_FILES([tests/test_cksum_grib \
tests/test_cksum_ieg \
tests/test_chunk_cksum \
tests/pio_write_run \
tests/pio_write_deco2d_run \
tests/pio_cksum_mpinonb \
tests/pio_cksum_fpguard \
tests/pio_cksum_asynch \
......
......@@ -6,9 +6,10 @@ TESTS = test_grib.sh cksum_verify \
test_chunk_cksum \
pio_write_run pio_cksum_mpinonb pio_cksum_fpguard \
pio_cksum_asynch pio_cksum_writer pio_cksum_cdf \
test_resource_copy
test_resource_copy pio_write_deco2d_run
check_PROGRAMS = cksum_verify test_grib cksum_write cksum_read pio_write \
test_resource_copy cksum_write_chunk
test_resource_copy cksum_write_chunk pio_write_deco2d
#
test_grib_SOURCES = test_grib.c
cksum_verify_SOURCES = cksum_verify.c
......@@ -19,6 +20,7 @@ cksum_read_SOURCES = cksum_read.c \
stream_cksum.c stream_cksum.h \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c
test_resource_copy_SOURCES = test_resource_copy.c \
$(top_srcdir)/src/resource_unpack.c
test_resource_copy_mpi_SOURCES = test_resource_copy.c
......@@ -26,12 +28,14 @@ test_resource_copy_mpi_SOURCES = test_resource_copy.c
AM_CFLAGS = $(YAXT_CFLAGS)
if USE_MPI
pio_write_LDADD = ../src/libcdipio.la
pio_write_deco2d_LDADD = ../src/libcdipio.la
TESTS += test_resource_copy_mpi_run
check_PROGRAMS += test_resource_copy_mpi
test_resource_copy_mpi_LDADD = ../src/libcdipio.la
test_resource_copy_mpi_CFLAGS = $(AM_CFLAGS) $(CFLAGS) -DMPI_MARSHALLING
else
pio_write_LDADD = $(LDADD)
pio_write_deco2d_LDADD = $(LDADD)
endif
LDADD = ../src/libcdi.la -lm
......
......@@ -55,18 +55,20 @@ TESTS = test_grib.sh cksum_verify$(EXEEXT) test_cksum_grib \
test_cksum_nc2 test_cksum_nc4 test_cksum_ieg test_chunk_cksum \
pio_write_run pio_cksum_mpinonb pio_cksum_fpguard \
pio_cksum_asynch pio_cksum_writer pio_cksum_cdf \
test_resource_copy$(EXEEXT) $(am__append_1)
test_resource_copy$(EXEEXT) pio_write_deco2d_run \
$(am__append_1)
check_PROGRAMS = cksum_verify$(EXEEXT) test_grib$(EXEEXT) \
cksum_write$(EXEEXT) cksum_read$(EXEEXT) pio_write$(EXEEXT) \
test_resource_copy$(EXEEXT) cksum_write_chunk$(EXEEXT) \
$(am__EXEEXT_1)
pio_write_deco2d$(EXEEXT) $(am__EXEEXT_1)
@USE_MPI_TRUE@am__append_1 = test_resource_copy_mpi_run
@USE_MPI_TRUE@am__append_2 = test_resource_copy_mpi
subdir = tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/pio_cksum_asynch.in $(srcdir)/pio_cksum_cdf.in \
$(srcdir)/pio_cksum_fpguard.in $(srcdir)/pio_cksum_mpinonb.in \
$(srcdir)/pio_cksum_writer.in $(srcdir)/pio_write_run.in \
$(srcdir)/pio_cksum_writer.in \
$(srcdir)/pio_write_deco2d_run.in $(srcdir)/pio_write_run.in \
$(srcdir)/test_chunk_cksum.in $(srcdir)/test_cksum_extra.in \
$(srcdir)/test_cksum_grib.in $(srcdir)/test_cksum_ieg.in \
$(srcdir)/test_cksum_nc.in $(srcdir)/test_cksum_nc2.in \
......@@ -92,8 +94,9 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES = test_cksum_grib test_cksum_nc test_cksum_nc2 \
test_cksum_nc4 test_cksum_extra test_cksum_service \
test_cksum_ieg test_chunk_cksum pio_write_run \
pio_cksum_mpinonb pio_cksum_fpguard pio_cksum_asynch \
pio_cksum_writer pio_cksum_cdf test_resource_copy_mpi_run
pio_write_deco2d_run pio_cksum_mpinonb pio_cksum_fpguard \
pio_cksum_asynch pio_cksum_writer pio_cksum_cdf \
test_resource_copy_mpi_run
CONFIG_CLEAN_VPATH_FILES =
@USE_MPI_TRUE@am__EXEEXT_1 = test_resource_copy_mpi$(EXEEXT)
am_cksum_read_OBJECTS = cksum_read.$(OBJEXT) var_cksum.$(OBJEXT) \
......@@ -118,6 +121,11 @@ pio_write_OBJECTS = $(am_pio_write_OBJECTS)
am__DEPENDENCIES_1 = ../src/libcdi.la
@USE_MPI_FALSE@pio_write_DEPENDENCIES = $(am__DEPENDENCIES_1)
@USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la
am_pio_write_deco2d_OBJECTS = pio_write.$(OBJEXT) \
deco2d_model.$(OBJEXT)
pio_write_deco2d_OBJECTS = $(am_pio_write_deco2d_OBJECTS)
@USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(am__DEPENDENCIES_1)
@USE_MPI_TRUE@pio_write_deco2d_DEPENDENCIES = ../src/libcdipio.la
am_test_grib_OBJECTS = test_grib.$(OBJEXT)
test_grib_OBJECTS = $(am_test_grib_OBJECTS)
test_grib_LDADD = $(LDADD)
......@@ -151,13 +159,13 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(cksum_read_SOURCES) $(cksum_verify_SOURCES) \
$(cksum_write_SOURCES) $(cksum_write_chunk_SOURCES) \
$(pio_write_SOURCES) $(test_grib_SOURCES) \
$(test_resource_copy_SOURCES) \
$(pio_write_SOURCES) $(pio_write_deco2d_SOURCES) \
$(test_grib_SOURCES) $(test_resource_copy_SOURCES) \
$(test_resource_copy_mpi_SOURCES)
DIST_SOURCES = $(cksum_read_SOURCES) $(cksum_verify_SOURCES) \
$(cksum_write_SOURCES) $(cksum_write_chunk_SOURCES) \
$(pio_write_SOURCES) $(test_grib_SOURCES) \
$(test_resource_copy_SOURCES) \
$(pio_write_SOURCES) $(pio_write_deco2d_SOURCES) \
$(test_grib_SOURCES) $(test_resource_copy_SOURCES) \
$(test_resource_copy_mpi_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
......@@ -367,6 +375,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
#
test_grib_SOURCES = test_grib.c
cksum_verify_SOURCES = cksum_verify.c
......@@ -378,6 +387,7 @@ cksum_read_SOURCES = cksum_read.c \
ensure_array_size.h ensure_array_size.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c
pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c
test_resource_copy_SOURCES = test_resource_copy.c \
$(top_srcdir)/src/resource_unpack.c
......@@ -386,6 +396,8 @@ test_resource_copy_mpi_SOURCES = test_resource_copy.c
AM_CFLAGS = $(YAXT_CFLAGS)
@USE_MPI_FALSE@pio_write_LDADD = $(LDADD)
@USE_MPI_TRUE@pio_write_LDADD = ../src/libcdipio.la
@USE_MPI_FALSE@pio_write_deco2d_LDADD = $(LDADD)
@USE_MPI_TRUE@pio_write_deco2d_LDADD = ../src/libcdipio.la
@USE_MPI_TRUE@test_resource_copy_mpi_LDADD = ../src/libcdipio.la
@USE_MPI_TRUE@test_resource_copy_mpi_CFLAGS = $(AM_CFLAGS) $(CFLAGS) -DMPI_MARSHALLING
LDADD = ../src/libcdi.la -lm
......@@ -448,6 +460,8 @@ test_chunk_cksum: $(top_builddir)/config.status $(srcdir)/test_chunk_cksum.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
pio_write_run: $(top_builddir)/config.status $(srcdir)/pio_write_run.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
pio_write_deco2d_run: $(top_builddir)/config.status $(srcdir)/pio_write_deco2d_run.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
pio_cksum_mpinonb: $(top_builddir)/config.status $(srcdir)/pio_cksum_mpinonb.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
pio_cksum_fpguard: $(top_builddir)/config.status $(srcdir)/pio_cksum_fpguard.in
......@@ -484,6 +498,9 @@ cksum_write_chunk$(EXEEXT): $(cksum_write_chunk_OBJECTS) $(cksum_write_chunk_DEP
pio_write$(EXEEXT): $(pio_write_OBJECTS) $(pio_write_DEPENDENCIES) $(EXTRA_pio_write_DEPENDENCIES)
@rm -f pio_write$(EXEEXT)
$(LINK) $(pio_write_OBJECTS) $(pio_write_LDADD) $(LIBS)
pio_write_deco2d$(EXEEXT): $(pio_write_deco2d_OBJECTS) $(pio_write_deco2d_DEPENDENCIES) $(EXTRA_pio_write_deco2d_DEPENDENCIES)
@rm -f pio_write_deco2d$(EXEEXT)
$(LINK) $(pio_write_deco2d_OBJECTS) $(pio_write_deco2d_LDADD) $(LIBS)
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)
......@@ -504,6 +521,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_verify.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write_chunk.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/deco2d_model.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ensure_array_size.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_unpack.Po@am__quote@
......
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifdef USE_MPI
#include <mpi.h>
#include <yaxt.h>
#else
typedef int MPI_Comm;
#endif
#include "cdi.h"
#ifdef USE_MPI
#include "cdipio.h"
#include "pio_util.h"
#endif
#include "cksum.h"
#include "dmemory.h"
#include "error.h"
#include "pio_write.h"
enum {
ntfiles = 2,
};
static void
var_scale(int datatype, double *mscale, double *mrscale);
static inline double
sign_flat(double v)
{
if (v == 0.0)
return 0.0;
return v;
}
static time_t
cditime2time_t(int date, int timeofday);
static void
time_t2cditime(time_t t, int *date, int *timeofday);
static void
modelRegionCompute(double region[], size_t offset, size_t len,
int nlev, int nlat, int nlon,
int tsID, const double lons[], const double lats[],
double mscale, double mrscale)
{
size_t local_pos;
for (local_pos = 0; local_pos < len; ++local_pos)
{
size_t global_pos = offset + local_pos;
int k = global_pos / (nlon * nlat);
int j = (global_pos % (nlon * nlat))/ nlon;
int i = global_pos % nlon;
region[local_pos]
= sign_flat(round((cos(2.0 * M_PI * (lons[(i + tsID)%nlon] - lons[0])
/ (lons[nlon-1] - lons[0]))
* sin(2.0 * M_PI * (lats[(j + k)%nlat] - lats[0])
/ (lats[nlat-1] - lats[0]))
) * mscale)) * mrscale;
}
}
#ifdef USE_MPI
static int
uniform_partition_start(int set_interval[2], int nparts, int part_idx);
#endif
void
modelRun(struct model_config setup, MPI_Comm comm)
{
static const char * const fname_prefix = "example";
struct
{
size_t size;
int nlev, zaxisID, id, code;
uint32_t checksum_state;
#if USE_MPI
int chunkSize, start;
Xt_idxlist partDesc;
#endif
} *varDesc;
int gridID, taxisID, vlistID, streamID, tsID, tfID = 0;
int i, nmiss = 0;
double *lons, *lats, *levs;
double *var = NULL, *varslice = NULL;
double mscale, mrscale;
time_t current_time;
int vdate = 19850101, vtime = 120000;
int rank = 0;
char filename[1024];
int nlon = setup.nlon, nlat = setup.nlat;
int nVars = setup.nvars;
size_t varslice_size = 0;
#if USE_MPI
int *chunks = NULL, *displs = NULL, comm_size = 1;
#endif
#if USE_MPI
xmpi ( MPI_Comm_rank ( comm, &rank ));
xmpi ( MPI_Comm_size ( comm, &comm_size ));
if (rank == 0 && setup.compute_checksum)
{
chunks = xmalloc(comm_size * sizeof (chunks[0]));
displs = xmalloc(comm_size * sizeof (displs[0]));
var = xmalloc((size_t)nlon * (size_t)nlat
* (size_t)setup.max_nlev * sizeof(var[0]));
}
#endif
var_scale(setup.datatype, &mscale, &mrscale);
gridID = gridCreate ( GRID_LONLAT, nlon*nlat );
gridDefXsize ( gridID, nlon );
gridDefYsize ( gridID, nlat );
lons = xmalloc(nlon * sizeof (lons[0]));
for (i = 0; i < nlon; ++i)
lons[i] = ((double)(i * 360))/nlon;
lats = xmalloc(nlat * sizeof (lats[0]));
for (i = 0; i < nlat; ++i)
lats[i] = ((double)(i * 180))/nlat - 90.0;
gridDefXvals ( gridID, lons );
gridDefYvals ( gridID, lats );
levs = xmalloc(setup.max_nlev * sizeof (levs[0]));
for (i = 0; i < setup.max_nlev; ++i)
levs[i] = 101300.0
- 3940.3 * (exp(1.3579 * (double)(i)/(setup.max_nlev - 1)) - 1.0);
vlistID = vlistCreate ();
varDesc = xmalloc(nVars * sizeof (varDesc[0]));
for (int varIdx = 0; varIdx < nVars; varIdx++ )
{
int varLevs = random()%4;
switch (varLevs)
{
case 1:
varLevs = setup.max_nlev / 3;
break;
case 2:
varLevs = setup.max_nlev >= 11 ? 11 : setup.max_nlev / 2;
break;
case 3:
varLevs = setup.max_nlev - 1;
break;
}
++varLevs;
varDesc[varIdx].nlev = varLevs;
for (i = 0; i < varIdx; ++i)
if (varDesc[i].nlev == varLevs)
{
varDesc[varIdx].zaxisID = varDesc[i].zaxisID;
goto zaxisIDset;
}
varDesc[varIdx].zaxisID
= zaxisCreate(ZAXIS_PRESSURE, varDesc[varIdx].nlev);
zaxisDefLevels(varDesc[varIdx].zaxisID, levs);
zaxisIDset:
varDesc[varIdx].id = vlistDefVar(vlistID, gridID, varDesc[varIdx].zaxisID,
TIME_VARIABLE);
varDesc[varIdx].size = nlon * nlat * varDesc[varIdx].nlev;
#ifdef USE_MPI
{
int start
= uniform_partition_start((int [2]){ 0, varDesc[varIdx].size - 1 },
comm_size, rank),
chunkSize
= uniform_partition_start((int [2]){ 0, varDesc[varIdx].size - 1 },
comm_size, rank + 1) - start;
fprintf(stderr, "%d: start=%d, chunkSize = %d\n", rank,
start, chunkSize);
Xt_idxlist idxlist
= xt_idxstripes_new(&(struct Xt_stripe){ .start = start,
.nstrides = chunkSize, .stride = 1 }, 1);
varDesc[varIdx].start = start;
varDesc[varIdx].chunkSize = chunkSize;
varDesc[varIdx].partDesc = idxlist;
}
#endif
varDesc[varIdx].code = 129 + varIdx;
vlistDefVarCode(vlistID, varDesc[varIdx].id, varDesc[varIdx].code);
vlistDefVarDatatype(vlistID, varDesc[varIdx].id, setup.datatype);
}
taxisID = taxisCreate ( TAXIS_ABSOLUTE );
vlistDefTaxis ( vlistID, taxisID );
sprintf ( &filename[0], "%s_%d.%s", fname_prefix, tfID, setup.suffix );
streamID = streamOpenWrite ( filename, setup.filetype );
xassert ( streamID >= 0 );
streamDefVlist ( streamID, vlistID);
#ifdef USE_MPI
pioEndDef ();
#endif
for ( tfID = 0; tfID < ntfiles; tfID++ )
{
for (int varIdx = 0; varIdx < nVars; ++varIdx)
varDesc[varIdx].checksum_state = 0;
if ( tfID > 0 )
{
streamClose ( streamID );
sprintf ( &filename[0], "%s_%d.%s", fname_prefix, tfID, setup.suffix );
streamID = streamOpenWrite ( filename, setup.filetype );
xassert ( streamID >= 0 );
streamDefVlist ( streamID, vlistID );
}
vdate = 19850101;
vtime = 120000;
current_time = cditime2time_t(vdate, vtime);
for ( tsID = 0; tsID < setup.nts; tsID++ )
{
time_t2cditime(current_time, &vdate, &vtime);
taxisDefVdate ( taxisID, vdate );
taxisDefVtime ( taxisID, vtime );
streamDefTimestep ( streamID, tsID );
for (int varID = 0; varID < nVars; ++varID)
{
#ifdef USE_MPI
int start = varDesc[varID].start;
int chunk = varDesc[varID].chunkSize;
#else
int chunk = varDesc[varID].size;
int start = 0;
#endif
if (varslice_size < chunk)
{
varslice = xrealloc(varslice, chunk * sizeof (var[0]));
varslice_size = chunk;
}
modelRegionCompute(varslice, start, chunk,
varDesc[varID].nlev, nlat, nlon,
tsID, lons, lats,
mscale, mrscale);
if (setup.compute_checksum)
{
#if USE_MPI
xmpi(MPI_Gather(&chunk, 1, MPI_INT,
chunks, 1, MPI_INT, 0, comm));
if (rank == 0)
{
displs[0] = 0;
for (i = 1; i < comm_size; ++i)
displs[i] = displs[i - 1] + chunks[i - 1];
}
xmpi(MPI_Gatherv(varslice, chunk, MPI_DOUBLE,
var, chunks, displs, MPI_DOUBLE, 0, comm));
#else
var = varslice;
#endif
}
if (rank == 0 && setup.compute_checksum)
{
memcrc_r(&varDesc[varID].checksum_state,
(const unsigned char *)var,
varDesc[varID].size * sizeof (var[0]));
}
#ifdef USE_MPI
streamWriteVarPart(streamID, varDesc[varID].id, varslice, nmiss,
varDesc[varID].partDesc);
#else
streamWriteVar(streamID, varDesc[varID].id, varslice, nmiss);
#endif
}
current_time += 86400;
#ifdef USE_MPI
pioWriteTimestep ( tsID, vdate, vtime );
#endif
}
if (rank == 0 && setup.compute_checksum)
{
FILE *tablefp;
{
sprintf(filename, "%s_%d.cksum", fname_prefix, tfID);
if (!(tablefp = fopen(filename, "w")))
{
perror("failed to open table file");
exit(EXIT_FAILURE);
}
for (i = 0; i < nVars; ++i)
{
uint32_t cksum;
int code;
cksum = memcrc_finish(&varDesc[i].checksum_state,
(off_t)varDesc[i].size
* sizeof (var[0]) * setup.nts);
code = vlistInqVarCode(vlistID, varDesc[i].id);
if (fprintf(tablefp, "%08lx %d\n", (unsigned long)cksum,
code) < 0)
{
perror("failed to write table file");
exit(EXIT_FAILURE);
}
}
fclose(tablefp);
}
}
}
free(varslice);
#ifdef USE_MPI
pioEndTimestepping ();
#endif
streamClose ( streamID );
vlistDestroy ( vlistID );
taxisDestroy ( taxisID );
for ( i = 0; i < nVars; i++ )
{
int zID = varDesc[i].zaxisID;
if (zID != CDI_UNDEFID)
{
zaxisDestroy(zID);
for (int j = i + 1; j < nVars; ++j)
if (zID == varDesc[j].zaxisID)
varDesc[j].zaxisID = CDI_UNDEFID;
}
}
gridDestroy ( gridID );
#if USE_MPI
for (int varID = 0; varID < nVars; ++varID)
xt_idxlist_delete(varDesc[varID].partDesc);
free(displs);
free(chunks);
free(var);
#endif
free(varDesc);
free(levs);
free(lats);
free(lons);
}
static time_t
cditime2time_t(int date, int timeofday)
{
struct tm t_s;
time_t t;
t_s.tm_year = date / 10000;
t_s.tm_mon = (date - t_s.tm_year * 10000)/100;
t_s.tm_mday = date % 100;
t_s.tm_year -= 1900;
t_s.tm_hour = timeofday/10000;
t_s.tm_min = (timeofday%10000)/100;
t_s.tm_sec = timeofday%100;
t_s.tm_isdst = 0;
t = mktime(&t_s);
/*
* fprintf(stderr, "converted %d,%d to %s to %lld.\n", date, timeofday,
* asctime(&t_s), (long long)t);
*/
return t;
}
static void
var_scale(int datatype, double *mscale, double *mrscale)
{
int mant_bits;
switch (datatype)
{
case DATATYPE_PACK8:
mant_bits = 7;
break;
case DATATYPE_PACK16:
mant_bits = 15;
break;
case DATATYPE_PACK24:
mant_bits = 23;
break;
case DATATYPE_FLT32:
mant_bits = 24;
break;
case DATATYPE_FLT64:
mant_bits = 53;
break;
case DATATYPE_INT8:
case DATATYPE_INT16:
case DATATYPE_INT32:
default:
fprintf(stderr, "Unexpected or unusable content format: %d\n",
datatype);
exit(EXIT_FAILURE);
}
*mscale = INT64_C(1) << mant_bits;
*mrscale = 1.0 / *mscale;
}
static void
time_t2cditime(time_t t, int *date, int *timeofday)
{
struct tm *t_s;
t_s = localtime(&t);
/* fprintf(stderr, "converted %lld to %s.\n", (long long)t, asctime(t_s)); */
*date = (t_s->tm_year + 1900) * 10000 + t_s->tm_mon * 100 + t_s->tm_mday;
*timeofday = t_s->tm_hour * 10000 + t_s->tm_min * 100 + t_s->tm_sec;
}
#ifdef USE_MPI
static int
uniform_partition_start(int set_interval[2], int nparts, int part_idx)
{
int part_offset
= (((long long)set_interval[1] - (long long)set_interval[0] + 1LL)
* (long long)part_idx) / (long long)nparts;
int start = set_interval[0] + part_offset;
return start;
}
#endif
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End: