2
* ADIOS is freely available under the terms of the BSD license described
3
* in the COPYING file in the top level directory of this source distribution.
5
* Copyright (c) 2008 - 2009. UT-BATTELLE, LLC. All rights reserved.
8
/* ADIOS C Example: read global arrays from a BP file
10
* This code is using the generic read API, which can read in
11
* arbitrary slices of an array and thus we can read in an array
12
* on arbitrary number of processes (provided our code is smart
13
* enough to do the domain decomposition).
15
* Run this example after adios_global, which generates
16
* adios_global.bp. Run this example on equal or less
17
* number of processes since we decompose only on one
18
* dimension of the global array here.
25
#include "adios_read.h"
27
int main (int argc, char ** argv)
30
int rank, size, i, j, npl, token;
31
MPI_Comm comm = MPI_COMM_WORLD;
33
enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP;
34
ADIOS_SELECTION * sel;
36
uint64_t start[1], count[1], bytes_read = 0;
38
MPI_Init (&argc, &argv);
39
MPI_Comm_rank (comm, &rank);
40
MPI_Comm_size (comm, &size);
42
adios_read_init_method (method, comm, "verbose=3");
44
ADIOS_FILE * f = adios_read_open ("no_xml_write_byid.bp", method,
45
comm, ADIOS_LOCKMODE_NONE, 0);
48
printf ("%s\n", adios_errmsg());
52
ADIOS_VARINFO * v = adios_inq_var (f, "temperature");
54
/* Using less readers to read the global array back, i.e., non-uniform */
55
uint64_t slice_size = v->dims[0]/size;
56
start[0] = slice_size * rank;
57
if (rank == size-1) /* last rank may read more lines */
58
slice_size = slice_size + v->dims[0]%size;
59
count[0] = slice_size;
61
data = malloc (slice_size * sizeof (double));
64
fprintf (stderr, "malloc failed.\n");
68
/* Read a subset of the temperature array */
69
sel = adios_selection_boundingbox (v->ndim, start, count);
70
adios_schedule_read (f, sel, "temperature", 0, 1, data);
71
adios_perform_reads (f, 1);
74
MPI_Recv (&token, 1, MPI_INT, rank-1, 0, comm, &status);
77
printf (" ======== Rank %d ========== \n", rank);
79
for (i = 0; i < slice_size; i+=npl) {
80
printf ("[%4.4d] ", rank*slice_size+i);
81
for (j= 0; j < npl; j++) {
82
printf (" %6.6g", * ((double *)data + i + j));
90
MPI_Send (&token, 1, MPI_INT, rank+1, 0, comm);
98
adios_read_finalize_method (method);