PLUTO
al_io.c File Reference

Miscellaneous functions for IO operations. More...

#include "al_hidden.h"
#include <string.h>
Include dependency graph for al_io.c:

Go to the source code of this file.

Functions

int AL_File_open (char *filename, int sz_ptr)
 
int AL_File_close (int sz_ptr)
 
int AL_Write_array (void *va, int sz_ptr, int istag)
 
int AL_Read_array (void *va, int sz_ptr, int istag)
 
int AL_Write_header (void *vbuffer, int nelem, AL_Datatype type, int sz_ptr)
 
long long AL_Get_offset (int sz_ptr)
 
int AL_Set_offset (int sz_ptr, long long offset)
 

Variables

SZsz_stack [AL_MAX_ARRAYS]
 
int stack_ptr [AL_MAX_ARRAYS]
 

Detailed Description

Miscellaneous functions for IO operations.

Author
A. Malagoli (University of Chicago)
A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t)
G. Muscianisi (g.mus.nosp@m.cian.nosp@m.isi@c.nosp@m.inec.nosp@m.a.it)
Date
Aug 26, 2012

Definition in file al_io.c.

Function Documentation

int AL_File_close ( int  sz_ptr)

Close a file associate with and array

Parameters
[in]sz_ptrinteger pointer to array descriptor

Definition at line 83 of file al_io.c.

89 {
90  int myrank;
91  int errcode;
92  SZ *s;
93 
94  s = sz_stack[sz_ptr];
95  myrank = s->rank;
96 
97  errcode = MPI_File_close(&(s->ifp));
98 
99  /* DIAGNOSTICS */
100 #ifdef DEBUG
101  int myid, len;
102  char es[128];
103  if( errcode ){
104  MPI_Comm_rank(MPI_COMM_WORLD, &myid);
105  MPI_Error_string(errcode, es, &len);
106  printf("Errcode from MPI_File_close: %d | %s\n", errcode, es);
107  }
108  printf("myid %d, AL_File_close: Closed file, errcode %d \n",myid, errcode);
109 #endif
110 
111  return (int) AL_SUCCESS;
112 }
#define AL_SUCCESS
Definition: al_codes.h:32
int rank
Definition: al_hidden.h:44
MPI_File ifp
Definition: al_hidden.h:117
#define s
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
Definition: al_hidden.h:38

Here is the caller graph for this function:

int AL_File_open ( char *  filename,
int  sz_ptr 
)

Open a file associated with a distributed array

Parameters
[in]filenamename of the file
[in]sz_ptrinteger pointer to the distributed array descriptor
Returns
ifp pointer to integer file pointer

Definition at line 27 of file al_io.c.

36 {
37  int myrank, nproc;
38  int errcode;
39  MPI_File ifp;
40  MPI_Comm comm;
41  SZ *s;
42 
43  /* DIAGNOSTICS
44  Check that sz_ptr points to an allocated SZ
45  */
46  if( stack_ptr[sz_ptr] == AL_STACK_FREE){
47  printf("AL_Decompose: wrong SZ pointer\n");
48  }
49 
50  s = sz_stack[sz_ptr];
51 
52  myrank = s->rank;
53  nproc = s->size;
54 
55  comm = s->comm;
56 
57  MPI_Barrier(comm);
58 
59  errcode = MPI_File_open(comm, filename,
60  MPI_MODE_CREATE | MPI_MODE_RDWR | MPI_MODE_UNIQUE_OPEN,
61  MPI_INFO_NULL, &ifp);
62 
63  s->io_offset = 0;
64  s->ifp = ifp;
65 
66  /* DIAGNOSTICS */
67 #ifdef DEBUG
68  int myid, len;
69  char es[128];
70  MPI_Comm_rank(MPI_COMM_WORLD, &myid);
71  if( errcode ){
72  MPI_Error_string(errcode, es, &len);
73  printf("Errcode from MPI_File_open: %d | %s\n", errcode, es);
74  }
75  printf("myid %d, AL_File_open: Opened file %s\n",myid,filename);
76 #endif
77 
78  return (int) AL_SUCCESS;
79 }
#define AL_SUCCESS
Definition: al_codes.h:32
#define AL_STACK_FREE
Definition: al_codes.h:24
int rank
Definition: al_hidden.h:44
MPI_File ifp
Definition: al_hidden.h:117
#define s
int size
Definition: al_hidden.h:45
MPI_Comm comm
Definition: al_hidden.h:47
MPI_Offset io_offset
Definition: al_hidden.h:116
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
Definition: al_hidden.h:38
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26

Here is the caller graph for this function:

long long AL_Get_offset ( int  sz_ptr)

Definition at line 327 of file al_io.c.

332 {
333  SZ *s;
334 
335  if( stack_ptr[sz_ptr] == AL_STACK_FREE){
336  printf("AL_Get_offset: wrong SZ pointer\n");
337  }
338  s = sz_stack[sz_ptr];
339  return s->io_offset;
340 }
#define AL_STACK_FREE
Definition: al_codes.h:24
#define s
MPI_Offset io_offset
Definition: al_hidden.h:116
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
Definition: al_hidden.h:38
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26

Here is the caller graph for this function:

int AL_Read_array ( void *  va,
int  sz_ptr,
int  istag 
)

Read a distributed array to a file in parallel using synchronous and collective IO operations

Parameters
[in]bufferpointer to the buffer to write
[in]sz_ptrinteger pointer to a distributed array descriptor
[in]istagset it to -1 for centred variables, set to 0,1,2 for staggered field in the x,y,z direction

Bugs fixed on Aug 26, 2012:

  • nelem has been declared long long in order to manage dbl and flt output 'single_file' in which each PLUTO variable is >= 4GB
  • the updating of nelem after the writing of a variable has been modified from ''nelem *= (long long)(s->arrdim[i] +(istag == i));'' to ''nelem *= (long long)(s->arrdim[i]);'' because when a staggered variable is written, in the sz_ptr descriptor there is the information about the really number of element of this variable. This appens because the function AL_Set_staggered_dim is called for a staggered array.

Definition at line 209 of file al_io.c.

220 {
221  char *a;
222  register int i;
223  int myrank;
224  long long nelem;
225  SZ *s;
226  MPI_Status status;
227  AL_Datatype gsub_arr, lsub_arr;
228 
229 
230  MPI_File ifp;
231  MPI_Offset offset;
232  int size;
233 
234  a = (void *)va;
235 
236  s = sz_stack[sz_ptr];
237  myrank = s->rank;
238 
239  ifp = s->ifp;
240 
241  offset = s->io_offset;
242  if (istag == -1){
243  gsub_arr = s->gsubarr;
244  lsub_arr = s->lsubarr;
245  }else{
246  gsub_arr = s->gsubarr_stag[istag];
247  lsub_arr = s->lsubarr_stag[istag];
248  }
249 
250  MPI_Barrier(s->comm);
251 
252  MPI_File_set_view(ifp, offset, MPI_BYTE, gsub_arr,
253  "native", MPI_INFO_NULL);
254  MPI_File_read_all(ifp, a, 1, lsub_arr, &status);
255 
256  MPI_Type_size( s->type, &size);
257 
258  nelem = 1;
259  for(i = 0; i < s->ndim; i++) {
260 /* -------------------------------------------------------------------- */
261 /*! Bugs fixed on Aug 26, 2012:
262  \li nelem has been declared long long in order to manage dbl and flt
263  output 'single_file' in which each PLUTO variable is >= 4GB
264  \li the updating of nelem after the writing of a variable has been
265  modified from ''nelem *= (long long)(s->arrdim[i] +(istag == i));''
266  to ''nelem *= (long long)(s->arrdim[i]);'' because when a staggered
267  variable is written, in the sz_ptr descriptor there is the
268  information about the really number of element of this variable.
269  This appens because the function AL_Set_staggered_dim is called
270  for a staggered array. */
271 /* -------------------------------------------------------------------- */
272 /* nelem *= (long long)(s->arrdim[i] + (istag == i)); */
273  nelem *= (long long)(s->arrdim[i]);
274  }
275  s->io_offset += (long long)(size)*nelem;
276 
277  return (int) AL_SUCCESS;
278 }
static double a
Definition: init.c:135
#define AL_Datatype
Definition: al_defs.h:22
#define AL_SUCCESS
Definition: al_codes.h:32
MPI_Datatype gsubarr
Definition: al_hidden.h:110
int arrdim[AL_MAX_DIM]
Definition: al_hidden.h:53
int rank
Definition: al_hidden.h:44
MPI_File ifp
Definition: al_hidden.h:117
MPI_Datatype lsubarr
Definition: al_hidden.h:111
MPI_Datatype lsubarr_stag[AL_MAX_DIM]
Definition: al_hidden.h:114
#define s
int i
Definition: analysis.c:2
MPI_Comm comm
Definition: al_hidden.h:47
MPI_Datatype type
Definition: al_hidden.h:40
MPI_Offset io_offset
Definition: al_hidden.h:116
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
Definition: al_hidden.h:38
MPI_Datatype gsubarr_stag[AL_MAX_DIM]
Definition: al_hidden.h:113
int ndim
Definition: al_hidden.h:43

Here is the caller graph for this function:

int AL_Set_offset ( int  sz_ptr,
long long  offset 
)

Definition at line 342 of file al_io.c.

347 {
348  SZ *s;
349 
350  if( stack_ptr[sz_ptr] == AL_STACK_FREE){
351  printf("AL_Get_offset: wrong SZ pointer\n");
352  }
353  s = sz_stack[sz_ptr];
354  s->io_offset = offset;
355  return (int)AL_SUCCESS;
356 }
#define AL_SUCCESS
Definition: al_codes.h:32
#define AL_STACK_FREE
Definition: al_codes.h:24
#define s
MPI_Offset io_offset
Definition: al_hidden.h:116
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
Definition: al_hidden.h:38
int stack_ptr[AL_MAX_ARRAYS]
Definition: al_szptr_.c:26

Here is the caller graph for this function:

int AL_Write_array ( void *  va,
int  sz_ptr,
int  istag 
)

Write a distributed array to a file in parallel using synchronous and collective IO operations

Parameters
[in]bufferpointer to the buffer to write
[in]sz_ptrinteger pointer to the distributed array descriptor
[in]istagset it to -1 for centred variables, set to 0,1,2 for staggered field in the x,y,z direction

Bugs fixed on Aug 26, 2012:

  • nelem has been declared long long in order to manage dbl and flt output 'single_file' in which each PLUTO variable is >= 4GB
  • the updating of nelem after the writing of a variable has been modified from ''nelem *= (long long)(s->arrdim[i] +(istag == i));'' to ''nelem *= (long long)(s->arrdim[i]);'' because when a staggered variable is written, in the sz_ptr descriptor there is the information about the really number of element of this variable. This appens because the function AL_Set_staggered_dim is called for a staggered array.

Definition at line 115 of file al_io.c.

126 {
127  char *a;
128  register int i;
129  int myrank;
130  long long nelem;
131  int errcode;
132  SZ *s;
133 
134  MPI_Status status;
135  AL_Datatype gsub_arr, lsub_arr;
136 
137  MPI_File ifp;
138  MPI_Offset offset;
139  int size;
140 
141 
142  a = (char *) va;
143 
144  s = sz_stack[sz_ptr];
145  myrank = s->rank;
146  ifp = s->ifp;
147 
148  offset = s->io_offset;
149  if (istag == -1){
150  gsub_arr = s->gsubarr;
151  lsub_arr = s->lsubarr;
152  }else{
153  gsub_arr = s->gsubarr_stag[istag];
154  lsub_arr = s->lsubarr_stag[istag];
155  }
156 
157  MPI_Barrier(s->comm);
158 
159  errcode = MPI_File_set_view(ifp, offset, MPI_BYTE, gsub_arr,
160  "native", MPI_INFO_NULL);
161 
162 #ifdef DEBUG
163  int myid, len;
164  char es[256];
165  MPI_Comm_rank(MPI_COMM_WORLD, &myid);
166  if( errcode ){
167  MPI_Error_string(errcode, es, &len);
168  printf("Errcode from MPI_File_set_view: %d | %s\n", errcode, es);
169  }
170  printf("myid %d, offset file_set_view %lld\n", myid,offset);
171 #endif
172 
173  errcode = MPI_File_write_all(ifp, a, 1, lsub_arr, &status);
174 
175 #ifdef DEBUG
176  if( errcode ){
177  MPI_Error_string(errcode, es, &len);
178  printf("Errcode from MPI_File_write_all: %d | %s\n", errcode, es);
179  }
180 #endif
181 
182  MPI_Type_size( s->type, &size);
183 
184  nelem = 1;
185  for(i = 0; i < s->ndim; i++) {
186 /* -------------------------------------------------------------------- */
187 /*! Bugs fixed on Aug 26, 2012:
188  \li nelem has been declared long long in order to manage dbl and flt
189  output 'single_file' in which each PLUTO variable is >= 4GB
190  \li the updating of nelem after the writing of a variable has been
191  modified from ''nelem *= (long long)(s->arrdim[i] +(istag == i));''
192  to ''nelem *= (long long)(s->arrdim[i]);'' because when a staggered
193  variable is written, in the sz_ptr descriptor there is the
194  information about the really number of element of this variable.
195  This appens because the function AL_Set_staggered_dim is called
196  for a staggered array. */
197 /* -------------------------------------------------------------------- */
198 /* nelem *= (long long)(s->arrdim[i] +(istag == i)); */
199  nelem *= (long long)(s->arrdim[i]);
200  }
201 
202  s->io_offset += (long long)(size)*nelem;
203 
204  return (int) AL_SUCCESS;
205 }
static double a
Definition: init.c:135
#define AL_Datatype
Definition: al_defs.h:22
#define AL_SUCCESS
Definition: al_codes.h:32
MPI_Datatype gsubarr
Definition: al_hidden.h:110
int arrdim[AL_MAX_DIM]
Definition: al_hidden.h:53
int rank
Definition: al_hidden.h:44
MPI_File ifp
Definition: al_hidden.h:117
MPI_Datatype lsubarr
Definition: al_hidden.h:111
MPI_Datatype lsubarr_stag[AL_MAX_DIM]
Definition: al_hidden.h:114
#define s
int i
Definition: analysis.c:2
MPI_Comm comm
Definition: al_hidden.h:47
MPI_Datatype type
Definition: al_hidden.h:40
MPI_Offset io_offset
Definition: al_hidden.h:116
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
Definition: al_hidden.h:38
MPI_Datatype gsubarr_stag[AL_MAX_DIM]
Definition: al_hidden.h:113
int ndim
Definition: al_hidden.h:43

Here is the caller graph for this function:

int AL_Write_header ( void *  vbuffer,
int  nelem,
AL_Datatype  type,
int  sz_ptr 
)

Definition at line 285 of file al_io.c.

293 {
294  char *buffer;
295  int myrank;
296  int nbytes, size;
297  SZ *s;
298  MPI_Status status;
299  MPI_File ifp;
300 
301 
302  MPI_Offset offset;
303  MPI_Type_size(type, &size);
304  buffer = (char *) vbuffer;
305 
306  nbytes = nelem*size;
307  s = sz_stack[sz_ptr];
308  myrank = s->rank;
309 
310  ifp = s->ifp;
311  offset = s->io_offset;
312  MPI_Barrier(s->comm);
313  MPI_File_set_view(ifp, offset, MPI_BYTE, MPI_CHAR,
314  "native", MPI_INFO_NULL);
315  if( myrank == 0 ){
316 /* MPI_File_write(ifp, buffer, strlen(buffer), MPI_CHAR, &status); */
317  MPI_File_write(ifp, buffer, nelem, type, &status);
318  }
319 
320  s->io_offset += nbytes;
321 
322 
323  return (int) AL_SUCCESS;
324 }
#define AL_SUCCESS
Definition: al_codes.h:32
int rank
Definition: al_hidden.h:44
MPI_File ifp
Definition: al_hidden.h:117
#define s
MPI_Comm comm
Definition: al_hidden.h:47
MPI_Offset io_offset
Definition: al_hidden.h:116
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
Definition: al_hidden.h:38

Here is the caller graph for this function:

Variable Documentation

int stack_ptr[AL_MAX_ARRAYS]

Definition at line 26 of file al_szptr_.c.

SZ* sz_stack[AL_MAX_ARRAYS]

Definition at line 18 of file al_szptr_.c.