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: write variables along with an rectilinear mesh.
17
#include "public/adios.h"
18
#include "public/adios_types.h"
20
//will work with 12 cores, which are arranged by npx=4, npy=3 (4x3)
21
char npx_str[256]; // # of procs in x dim (string value)
22
char npy_str[256]; // # of procs in y dim (string value)
23
int npx; // # of procs in x direction
24
int npy; // # of procs in y direction
25
int nproc; // # of total procs
27
void printUsage(char *prgname)
29
printf("Usage: mpirun -np <N> %s <nx> <ny>\n"
30
" <nx> <ny> 2D decomposition values in each dimension of an 2D array\n"
31
" The product of these number must be equal the number of processes\n"
32
" e.g. for N=12 you may use 4 3\n"
37
int processArgs(int argc, char ** argv)
44
strncpy(npx_str, argv[1], sizeof(npx_str));
45
strncpy(npy_str, argv[2], sizeof(npy_str));
50
if (npx*npy != nproc) {
51
printf ("ERROR: Product of decomposition numbers in X and Y dimension %d != number of processes %d\n", npx*npy, nproc);
60
int main (int argc, char ** argv)
62
MPI_Comm comm = MPI_COMM_WORLD;
64
int ndx, ndy; // size of array per processor
67
double *X; //X coordinate
68
double *Y; //Y coordinate
71
int offs_x, offs_y; //offset in x and y direction
72
int nx_local, ny_local; //local address
73
int nx_global, ny_global; //global address
74
int posx, posy; // position index in the array
77
int64_t m_adios_group;
78
uint64_t adios_groupsize, adios_totalsize;
81
MPI_Init (&argc, &argv);
82
MPI_Comm_rank (comm, &rank);
83
MPI_Comm_size (comm, &nproc);
85
if (processArgs(argc, argv)) {
89
//will work with each core writing ndx = 65, ndy = 129, (65*4,129*3) global
93
//2D array with block,block decomposition
94
posx = rank%npx; // 1st dim
95
posy = rank/npx; // 2nd dim
100
nx_global = npx * ndx;
101
ny_global = npy * ndy;
103
data = malloc (ndx * ndy * sizeof(double));
104
for( i = 0; i < ndx; i++ )
105
for( j = 0; j < ndy; j++)
106
data[i*ndy + j] = 1.0*rank;
108
X = malloc (ndx * sizeof(double));
109
for( i = 0; i < ndx; i++ )
110
//X[i] = 0.1*i*i+ndx*posx;
111
X[i] = 0.1*(i+offs_x)*(i+offs_x);
113
Y = malloc (ndy * sizeof(double));
114
for( i = 0; i < ndy; i++ )
115
//Y[i] = 0.1*i*i+ndx*posy;
116
Y[i] = 0.1*(i+offs_y)*(i+offs_y);
118
char * schema_version = "1.1";
119
char * dimemsions = "nx_global,ny_global";
121
adios_init_noxml (comm);
122
adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, 50);
124
adios_declare_group (&m_adios_group, "rectilinear2d", "", adios_flag_yes);
125
adios_select_method (m_adios_group, "MPI", "", "");
127
adios_define_var (m_adios_group, "nx_global"
130
adios_define_var (m_adios_group, "ny_global"
133
adios_define_var (m_adios_group, "nproc"
136
adios_define_var (m_adios_group, "offs_x"
139
adios_define_var (m_adios_group, "offs_y"
142
adios_define_var (m_adios_group, "nx_local"
145
adios_define_var (m_adios_group, "ny_local"
148
adios_define_var (m_adios_group, "X"
150
,"nx_local", "nx_global", "offs_x");
151
adios_define_var (m_adios_group, "Y"
153
,"ny_local", "ny_global", "offs_y");
154
adios_define_var (m_adios_group, "data"
156
,"nx_local,ny_local", "nx_global,ny_global", "offs_x,offs_y");
158
adios_define_schema_version (m_adios_group, schema_version);
159
adios_define_mesh_rectilinear (dimemsions, "X,Y", "2", m_adios_group, "rectilinearmesh");
160
adios_define_mesh_timevarying ("no", m_adios_group, "rectilinearmesh");
161
adios_define_var_mesh (m_adios_group, "data", "rectilinearmesh");
162
adios_define_var_centering (m_adios_group, "data", "point");
163
adios_open (&adios_handle, "rectilinear2d", "rectilinear2d_noxml.bp", "w", comm);
165
adios_groupsize = 7*sizeof(int) \
166
+ sizeof(double) * (nx_local*ny_local) \
167
+ sizeof(double) * (nx_local) \
168
+ sizeof(double) * (ny_local);
170
adios_group_size (adios_handle, adios_groupsize, &adios_totalsize);
171
adios_write (adios_handle, "nproc", &nproc);
172
adios_write (adios_handle, "nx_global", &nx_global);
173
adios_write (adios_handle, "ny_global", &ny_global);
174
adios_write (adios_handle, "offs_x", &offs_x);
175
adios_write (adios_handle, "offs_y", &offs_y);
176
adios_write (adios_handle, "nx_local", &nx_local);
177
adios_write (adios_handle, "ny_local", &ny_local);
179
adios_write (adios_handle, "X", X);
181
//printf ("rank %d: check if to print Y, rank%%npx=%d offs_y=%d\n", rank, rank%npx, offs_y);
182
if( rank % npx == 0 )
184
adios_write (adios_handle, "Y", Y);
186
adios_write (adios_handle, "data", data);
188
adios_close (adios_handle);
196
adios_finalize (rank);