diff --git a/examples/basics/globalArray1D/decomp.c b/examples/basics/globalArray1D/decomp.c index bb7d3300a5..421f76c2ba 100644 --- a/examples/basics/globalArray1D/decomp.c +++ b/examples/basics/globalArray1D/decomp.c @@ -15,23 +15,23 @@ /* random integer from {minv, minv+1, ..., maxv} including minv and maxv */ -long long int get_random(int minv, int maxv) +size_t get_random(int minv, int maxv, int rank) { - long long int n; + size_t n; time_t t; /* Intializes random number generator */ - srand((unsigned)time(&t)); - n = (rand() % (maxv - minv + 1)) + minv; + srand((unsigned)time(&t) + rank); + n = (size_t)((rand() % (maxv - minv + 1)) + minv); return n; } /* gather the local sizes of arrays and sum them up so that each process knows the global shape and its own offset in the global space */ -void gather_decomp_1d(long long int *mysize, long long int *myshape, long long int *myoffset) +void gather_decomp_1d(size_t *mysize, size_t *myshape, size_t *myoffset) { - long long int *sizes; + size_t *sizes; int i; - sizes = malloc(sizeof(long long int) * (size_t)nproc); + sizes = malloc(sizeof(size_t) * (size_t)nproc); MPI_Allgather(mysize, 1, MPI_LONG_LONG, sizes, 1, MPI_LONG_LONG, app_comm); *myshape = 0; @@ -49,14 +49,14 @@ void gather_decomp_1d(long long int *mysize, long long int *myshape, long long i return; } -void decomp_1d(long long int globalsize, long long int *myoffset, long long int *mysize) +void decomp_1d(size_t *globalsize, size_t *myoffset, size_t *mysize) { - long long int rem; - *mysize = globalsize / nproc; - rem = globalsize - (nproc * *mysize); + size_t rem; + *mysize = *globalsize / nproc; + rem = *globalsize - (nproc * *mysize); if (rank < rem) { - mysize = mysize + 1; + *mysize = *mysize + 1; *myoffset = rank * *mysize; } else diff --git a/examples/basics/globalArray1D/decomp.h b/examples/basics/globalArray1D/decomp.h index e972714844..e3fd49985a 100644 --- a/examples/basics/globalArray1D/decomp.h +++ b/examples/basics/globalArray1D/decomp.h @@ -8,7 +8,9 @@ #ifndef ADIOS2EXAMPLES_DECOMP_H #define ADIOS2EXAMPLES_DECOMP_H -extern long long int get_random(int, int); -extern void gather_decomp_1d(long long int *, long long int *, long long int *); -extern void decomp_1d(long long int, long long int *, long long int *); +#include + +extern size_t get_random(int minv, int maxv, int rank); +extern void gather_decomp_1d(size_t *, size_t *, size_t *); +extern void decomp_1d(size_t *, size_t *, size_t *); #endif // ADIOS2EXAMPLES_DECOMP_H diff --git a/examples/basics/globalArray1D/globalArray1DRead.c b/examples/basics/globalArray1D/globalArray1DRead.c index 288ce9f11b..d01ccdb3de 100644 --- a/examples/basics/globalArray1D/globalArray1DRead.c +++ b/examples/basics/globalArray1D/globalArray1DRead.c @@ -7,57 +7,67 @@ #include "decomp.h" #include "mpivars.h" #include +#include #include #include void reader(adios2_adios *adios) { int step; - float *g; + float *g = NULL; const char *streamname = "adios2-global-array-1d-c.bp"; adios2_step_status err; - long long int fixed_shape = 0, fixed_start = 0, fixed_count = 0; + size_t shape[1], start[1], count[1]; adios2_io *io = adios2_declare_io(adios, "input"); - size_t shape[1]; - shape[0] = (size_t)fixed_shape; adios2_engine *engine = adios2_open(io, streamname, adios2_mode_read); step = 0; - do + while (1) { adios2_begin_step(engine, adios2_step_mode_read, 10.0, &err); + if (err == adios2_step_status_end_of_stream) + { + break; + } + if (err != adios2_step_status_ok) + { + printf("Unexpected status when calling adios2_begin_step() for step %d", step); + break; + } adios2_variable *var_g = adios2_inquire_variable(io, "GlobalArray"); if (step == 0) { /* fixed_shape is allocated in the next call*/ adios2_variable_shape(shape, var_g); - fixed_shape = (long long int)shape[0]; - decomp_1d(fixed_shape, &fixed_start, &fixed_count); - g = malloc((size_t)fixed_count * sizeof(float)); + decomp_1d(shape, start, count); + g = malloc(count[0] * sizeof(float)); + + printf("Read plan rank = %d global shape = %zu local count = %zu offset = %zu\n", rank, + shape[0], count[0], start[0]); + } - printf("Read plan rank = %d global shape = %lld local count = %lld " - "offset = %lld\n", - rank, fixed_shape, fixed_count, fixed_start); + adios2_variable *var = adios2_inquire_variable(io, "GlobalArray"); + if (!var) + { + printf("ERROR: Variable 'GlobalArray' was not found in step %d", step); + break; } + + adios2_set_selection(var, 1, start, count); + // Initiate reading data in default/deferred mode: data is available after end_step + adios2_get(engine, var, g, adios2_mode_deferred); + adios2_end_step(engine); step++; - } while (err != adios2_step_status_end_of_stream); + } // Close the output adios2_close(engine); - free(g); - if (rank == 0) + if (g != NULL) { - printf("Try the following: \n"); - printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -n " - "%lld \n", - fixed_shape); - printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -t -n " - "%lld \n ", - fixed_shape); - printf(" mpirun -n 2 ./adios2-global-array-1d-read-c \n"); + free(g); } } diff --git a/examples/basics/globalArray1D/globalArray1DWrite.F90 b/examples/basics/globalArray1D/globalArray1DWrite.F90 index 90d0778909..51c31d1223 100644 --- a/examples/basics/globalArray1D/globalArray1DWrite.F90 +++ b/examples/basics/globalArray1D/globalArray1DWrite.F90 @@ -85,7 +85,7 @@ subroutine writer " bpls -la adios2-global-array-1d-f.bp ", & "GlobalArray -d -t -n ", fixed_shape(1) write (*,'(a)') & - " mpirun -n 2 ./adios2-global-array-1d-read-f " + " mpirun -n 2 ./adios2_basics_globalArray1DRead_f " endif end subroutine writer diff --git a/examples/basics/globalArray1D/globalArray1DWrite.c b/examples/basics/globalArray1D/globalArray1DWrite.c index 4ae38ed3da..a1744de399 100644 --- a/examples/basics/globalArray1D/globalArray1DWrite.c +++ b/examples/basics/globalArray1D/globalArray1DWrite.c @@ -7,6 +7,7 @@ #include "decomp.h" #include "mpivars.h" #include +#include #include #include @@ -19,35 +20,26 @@ void writer(adios2_adios *adios) const int numsteps = 5; adios2_step_status err; - long long int fixed_shape = 0, fixed_start = 0, fixed_count = 0; + size_t shape[1], start[1], count[1]; /* Application variables g = 1D distributed array, global shape and per-process size is fixed */ - fixed_count = get_random(mincount, maxcount); - g = malloc((size_t)fixed_count * sizeof(float)); - gather_decomp_1d(&fixed_count, &fixed_shape, &fixed_start); + count[0] = get_random(mincount, maxcount, rank); + g = malloc((size_t)count[0] * sizeof(float)); + gather_decomp_1d(count, shape, start); adios2_io *io = adios2_declare_io(adios, "output"); - size_t shape[1]; - shape[0] = (size_t)fixed_shape; - - size_t start[1]; - start[0] = (size_t)fixed_start; - - size_t count[1]; - count[0] = (size_t)fixed_count; adios2_variable *var_g = adios2_define_variable(io, "GlobalArray", adios2_type_float, 1, shape, start, count, adios2_constant_dims_true); adios2_engine *engine = adios2_open(io, "adios2-global-array-1d-c.bp", adios2_mode_write); - printf("Decmp rank = %d global shape = %lld local count = %lld offset = " - "%lld\n", - rank, fixed_shape, fixed_count, fixed_start); + printf("Decomp rank = %d global shape = %zu local count = %zu offset = %zu\n", rank, shape[0], + count[0], start[0]); for (step = 0; step < numsteps; step++) { - for (i = 0; i < fixed_count; i++) + for (i = 0; i < count[0]; i++) { g[i] = (float)(rank + (step + 1) / 100.0); } @@ -63,13 +55,9 @@ void writer(adios2_adios *adios) if (rank == 0) { printf("Try the following: \n"); - printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -n " - "%lld \n", - fixed_shape); - printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -t -n " - "%lld \n ", - fixed_shape); - printf(" mpirun -n 2 ./adios2-global-array-1d-read-c \n"); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -n %zu \n", shape[0]); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -t -n %zu \n ", shape[0]); + printf(" mpirun -n 2 ./adios2_basics_globalArray1DRead_c \n"); } } diff --git a/examples/basics/values/values.F90 b/examples/basics/values/values.F90 index 608ecf37b6..a1f0d9038b 100644 --- a/examples/basics/values/values.F90 +++ b/examples/basics/values/values.F90 @@ -111,7 +111,7 @@ subroutine reader ! Note, every process reads everything in this example call adios2_declare_io(io, adios, "ValuesInput", ierr) - call adios2_open(engine, io, "adios2-values-f.bp", adios2_mode_read, MPI_COMM_SELF, ierr) + call adios2_open(engine, io, "adios2-values-f.bp", adios2_mode_readRandomAccess, MPI_COMM_SELF, ierr) call adios2_inquire_variable(var_gc, io, "GlobalConstant", ierr) call adios2_get(engine, var_gc, gc , ierr) diff --git a/examples/basics/values/valuesWrite.cpp b/examples/basics/values/valuesWrite.cpp index 4f9f556798..8300e4e682 100644 --- a/examples/basics/values/valuesWrite.cpp +++ b/examples/basics/values/valuesWrite.cpp @@ -19,6 +19,7 @@ */ #include +#include #include #include @@ -80,6 +81,8 @@ int main(int argc, char *argv[]) // 2. Global value, same value across processes, varying value over time adios2::Variable varStep = io.DefineVariable("Step"); + adios2::Variable varGlobalString = + io.DefineVariable("GlobalString"); // 3. Local value, varying across processes, constant over time adios2::Variable varProcessID = @@ -110,6 +113,11 @@ int main(int argc, char *argv[]) writer.Put(varNproc, nproc); } writer.Put(varStep, step); + + std::string str = "This is step " + std::to_string(step); + // str will go out of scope before EndStep(), so we must use + // Sync mode in Put() + writer.Put(varGlobalString, str, adios2::Mode::Sync); } // 3. and 4. Writing a local value on every process. Will be shown diff --git a/source/utils/bpls/bpls.cpp b/source/utils/bpls/bpls.cpp index fd263b5748..0d3ce8e73c 100644 --- a/source/utils/bpls/bpls.cpp +++ b/source/utils/bpls/bpls.cpp @@ -1144,21 +1144,27 @@ int printVariableInfo(core::Engine *fp, core::IO *io, core::Variable *variabl if (timestep == false) { MinMaxStruct MinMax; - if (fp->VariableMinMax(*variable, DefaultSizeT, MinMax)) + try { - fprintf(outf, " = "); - print_data(&MinMax.MinUnion, 0, adiosvartype, false); - fprintf(outf, " / "); - print_data(&MinMax.MaxUnion, 0, adiosvartype, false); + if (fp->VariableMinMax(*variable, DefaultSizeT, MinMax)) + { + fprintf(outf, " = "); + print_data(&MinMax.MinUnion, 0, adiosvartype, false); + fprintf(outf, " / "); + print_data(&MinMax.MaxUnion, 0, adiosvartype, false); + } + else + { + fprintf(outf, " = "); + print_data(&variable->m_Min, 0, adiosvartype, false); + fprintf(outf, " / "); + print_data(&variable->m_Max, 0, adiosvartype, false); + } + // fprintf(outf," {MIN / MAX} "); } - else + catch (std::logic_error &) { - fprintf(outf, " = "); - print_data(&variable->m_Min, 0, adiosvartype, false); - fprintf(outf, " / "); - print_data(&variable->m_Max, 0, adiosvartype, false); } - // fprintf(outf," {MIN / MAX} "); } #if 0 else