1
/* Staged write example code.
3
- one output step fits into the memory of the staged writer.
4
Actually, this means, even more memory is needed than the size of output.
5
We need to read each variable while also buffering all of them for output.
6
- output steps contain the same variable set (no changes in variables)
7
- attributes are the same for all steps (will write only once here)
14
#include <sys/types.h>
19
#include "adios_read.h"
20
#include "adios_error.h"
22
static const int max_read_buffer_size = 1024*1024*1024;
23
static const int max_write_buffer_size = 1024*1024*1024;
25
static int timeout_sec = 30; // will stop if no data found for this time (-1: never stop)
26
enum ADIOS_READ_METHOD read_method = ADIOS_READ_METHOD_BP;
32
ADIOS_FILE *f; // stream for reading
33
int64_t fh; // ADIOS output file handle
34
int64_t gh; // ADIOS group for output definitions
35
uint64_t write_total; // data size written by one processor
36
uint64_t largest_block; // the largest variable block one process reads
37
char ** group_namelist; // name of ADIOS group
38
char *readbuf; // read buffer
39
int decomp_values[10];
42
int process_metadata();
46
int main (int argc, char ** argv)
49
int steps = 0, curr_step;
52
MPI_Init (&argc, &argv);
53
comm = MPI_COMM_WORLD;
54
MPI_Comm_rank (comm, &rank);
55
MPI_Comm_size (comm, &numproc);
58
char infilename[] = "steps.bp";
60
err = adios_read_init_method(read_method, comm,
61
"max_chunk_size=100; "
64
"poll_interval = 100;"
68
printf ("%s\n", adios_errmsg());
72
printf ("Waiting to open stream %s...\n", infilename);
73
f = adios_read_open_stream (infilename, read_method, comm,
74
ADIOS_LOCKMODE_ALL, timeout_sec);
75
if (adios_errno == err_file_not_found)
77
printf ("rank %d: Stream not found after waiting %d seconds: %s\n",
78
rank, timeout_sec, adios_errmsg());
81
else if (adios_errno == err_end_of_stream)
83
printf ("rank %d: Stream terminated before open. %s\n", rank, adios_errmsg());
87
printf ("rank %d: Error at opening stream: %s\n", rank, adios_errmsg());
94
steps++; // start counting from 1
97
printf ("File info:\n");
98
printf (" current step: %d\n", f->current_step);
99
printf (" last step: %d\n", f->last_step);
100
printf (" # of variables: %d:\n", f->nvars);
104
retval = process_metadata();
106
retval = read_records();
108
// advance to 1) next available step with 2) blocking wait
109
curr_step = f->current_step; // save for final bye print
110
adios_advance_step (f, 0, 0.0);
112
if (adios_errno == err_end_of_stream)
114
break; // quit while loop
116
else if (adios_errno == err_step_notready)
118
printf ("rank %d: No new step arrived within the timeout. Quit. %s\n",
119
rank, adios_errmsg());
120
break; // quit while loop
122
else if (f->current_step != curr_step+1)
124
// we missed some steps
125
printf ("rank %d: WARNING: steps %d..%d were missed when advancing.\n",
126
rank, curr_step+1, f->current_step-1);
131
adios_read_close (f);
134
adios_read_finalize_method (read_method);
145
uint64_t writesize; // size of subset this process writes, 0: do not write
150
int NX, Width, nblocks;
152
int process_metadata()
156
char gdims[256], ldims[256], offs[256];
158
ADIOS_VARINFO *v; // shortcut pointer
160
/* First step processing */
162
printf ("Get info on variable Width\n");
163
v = adios_inq_var (f, "Width");
165
printf ("rank %d: ERROR: Variable %s inquiry failed: %s\n",
166
rank, "Width", adios_errmsg());
169
Width = *(int *)v->value;
170
adios_free_varinfo (v);
171
printf ("rank %d: Width = %d\n", rank, Width);
173
printf ("Get info on variable NX\n");
174
v = adios_inq_var (f, "NX");
176
printf ("rank %d: ERROR: Variable %s inquiry failed: %s\n",
177
rank, "NX", adios_errmsg());
180
NX = *(int *)v->value;
181
adios_free_varinfo (v);
182
printf ("rank %d: NX = %d\n", rank, NX);
184
printf ("Get info on variable record\n");
185
v = adios_inq_var (f, "record");
187
printf ("rank %d: ERROR: Variable %s inquiry failed: %s\n",
188
rank, "record", adios_errmsg());
191
nblocks = v->nblocks[0];
192
printf ("rank %d: record dims = %llu * %llu \n", rank, v->dims[0], v->dims[1]);
193
adios_free_varinfo (v);
194
printf ("rank %d: nblocks = %d\n", rank, nblocks);
204
int N = nblocks/numproc;
208
text = malloc (Width*NX+1);
213
memset (text, '+', Width*NX);
214
// read one block of records
215
//printf ("rank %d: Read block %d\n", rank, startidx+i);
216
ADIOS_SELECTION *sel = adios_selection_writeblock (startidx+i);
217
adios_schedule_read (f, sel, "record", 0, 1, text);
218
adios_perform_reads (f, 1);
219
adios_selection_delete (sel);
221
printf ("block %2d = ", startidx+i);
223
printf ("[%s]", text+j*Width);