Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 210 #3995

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions examples/basics/globalArray1D/decomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions examples/basics/globalArray1D/decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stddef.h>

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
54 changes: 32 additions & 22 deletions examples/basics/globalArray1D/globalArray1DRead.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,67 @@
#include "decomp.h"
#include "mpivars.h"
#include <adios2_c.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/basics/globalArray1D/globalArray1DWrite.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 11 additions & 23 deletions examples/basics/globalArray1D/globalArray1DWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "decomp.h"
#include "mpivars.h"
#include <adios2_c.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

Expand All @@ -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);
}
Expand All @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/basics/values/values.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions examples/basics/values/valuesWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include <iostream>
#include <string>
#include <vector>

#include <adios2.h>
Expand Down Expand Up @@ -80,6 +81,8 @@ int main(int argc, char *argv[])

// 2. Global value, same value across processes, varying value over time
adios2::Variable<int> varStep = io.DefineVariable<int>("Step");
adios2::Variable<std::string> varGlobalString =
io.DefineVariable<std::string>("GlobalString");

// 3. Local value, varying across processes, constant over time
adios2::Variable<int> varProcessID =
Expand Down Expand Up @@ -110,6 +113,11 @@ int main(int argc, char *argv[])
writer.Put<int>(varNproc, nproc);
}
writer.Put<int>(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<std::string>(varGlobalString, str, adios2::Mode::Sync);
}

// 3. and 4. Writing a local value on every process. Will be shown
Expand Down
16 changes: 13 additions & 3 deletions source/adios2/toolkit/format/bp5/BP5Deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,13 +1577,23 @@ BP5Deserializer::GenerateReadRequests(const bool doAllocTempBuffers, size_t *max
throw std::runtime_error("No data exists for this variable");
if (Req->MemSpace != MemorySpace::Host)
RR.DirectToAppMemory = false;
else if (VarRec->Operator != NULL)
RR.DirectToAppMemory = false;
else
RR.DirectToAppMemory =
IsContiguousTransfer(Req, &writer_meta_base->Offsets[StartDim],
&writer_meta_base->Count[StartDim]);
RR.ReadLength =
helper::GetDataTypeSize(VarRec->Type) *
CalcBlockLength(VarRec->DimCount, &writer_meta_base->Count[StartDim]);
if (VarRec->Operator)
{
// have to have the whole thing
RR.ReadLength = writer_meta_base->DataBlockSize[NeededBlock];
}
else
{
RR.ReadLength =
helper::GetDataTypeSize(VarRec->Type) *
CalcBlockLength(VarRec->DimCount, &writer_meta_base->Count[StartDim]);
}
RR.OffsetInBlock = 0;
if (RR.DirectToAppMemory)
{
Expand Down
28 changes: 17 additions & 11 deletions source/utils/bpls/bpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,21 +1144,27 @@ int printVariableInfo(core::Engine *fp, core::IO *io, core::Variable<T> *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
Expand Down
Loading