PLUTO
al_write_array_async.c File Reference

ArrayLib routines for asynchronous MPI-IO. More...

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

Go to the source code of this file.

Functions

int AL_Write_array_begin (void *va, int sz_ptr, int *output_stag, int *output_dump, int output_nvar)
 
int AL_Write_array_end (void *va, int sz_ptr)
 

Variables

SZsz_stack [AL_MAX_ARRAYS]
 
int stack_ptr [AL_MAX_ARRAYS]
 

Detailed Description

ArrayLib routines for asynchronous MPI-IO.

ArrayLib routines for asynchronous MPI-IO

Authors
G. Muscianisi (g.mus.nosp@m.cian.nosp@m.isi@c.nosp@m.inec.nosp@m.a.it)
Date
Feb 28, 2012

Definition in file al_write_array_async.c.

Function Documentation

int AL_Write_array_begin ( void *  va,
int  sz_ptr,
int *  output_stag,
int *  output_dump,
int  output_nvar 
)

Write a distributed array to a parallel file by using asynchronous MPI-IO

Parameters
[in]bufferpointer to the buffer to write
[in]sz_ptrinteger pointer to the distributed array descriptor
[in]output_stagvector sets to -1 for centred variables, and sets to 0,1,2 for staggered field in the x,y,z direction
[in]output_dumpvector sets to 1 if the variable has to be dumped, 0 in the contrary case
[in]output_nvartotal number of variables in PLUTO simulation

Definition at line 26 of file al_write_array_async.c.

41 {
42  char *a;
43  register int i;
44  SZ *s;
45 
46  MPI_File ifp;
47 
48  int errcode;
49 
50  int myrank;
51  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
52 
53  a = (char *) va;
54 
55  s = sz_stack[sz_ptr];
56  ifp = s->ifp;
57 
58  /* Definition of a "global" filetype given by nvar times gsubarr for the MPI_File_set_view */
59  MPI_Datatype filetype_gsub_arr;
60  int count; /* number of variable to be dumped */
61  count=0;
62  for (i=0; i<output_nvar; i++){
63  if (!(output_dump[i]== 0)) count = count+1;
64  }
65  errcode = MPI_Type_contiguous(count, s->gsubarr, &filetype_gsub_arr);
66  errcode = MPI_Type_commit(&filetype_gsub_arr);
67 
68  /* Definition of a "global" datatype for the MPI_File_write_all_begin */
69  MPI_Datatype dtype_lsub_arr;
70 
71 #ifdef DEBUG
72  if(myrank==0) printf("count=%d, output_nvar=%d\n",count,output_nvar);
73 #endif
74 
75  int *block_leng, *displ;
76  int k=0;
77 
78  block_leng= (int*) malloc(count*sizeof(int));
79  displ=(int*) malloc(count*sizeof(int));
80 
81  for (i=0; i<output_nvar; i++){
82  if (!(output_dump[i]==0)){ /* cioè devo scrivere la variabile */
83  block_leng[k] = 1;
84  displ[k] = i;
85  k=k+1;
86  }
87  }
88 
89  errcode = MPI_Type_indexed(count,block_leng, displ, s->lsubarr, &dtype_lsub_arr);
90  errcode = MPI_Type_commit(&dtype_lsub_arr);
91 /*
92  MPI_Type_get_extent(dtype_lsub_arr,lb,extent);
93  printf("myid, %d, lb %d, extent %d of dtype_lsub_arr\n",myrank,lb,extent);
94 */
95 /* DIAGNOSTICS */
96 #ifdef DEBUG
97  if (myrank==0) {
98  for (i=0; i<output_nvar; i++) printf("myid, %d, count %d, output_nvar %d, i %d, output_dump[i] %d, block_leng[i] %d, displ[i] %d\n", myrank, count, output_nvar, i, output_dump[i], block_leng[i], displ[i]);
99  }
100 #endif
101 
102  free(block_leng);
103  free(displ);
104  MPI_Barrier(s->comm);
105 
106  /* Setting of the new view. Each procs see all the file at the beginning of the writing */
107  errcode = MPI_File_set_view(ifp, 0, MPI_BYTE, filetype_gsub_arr,
108  "native", MPI_INFO_NULL);
109  MPI_Type_free(&filetype_gsub_arr);
110 
111 /* DIAGNOSTICS */
112 #ifdef DEBUG
113  int len;
114  char es[MPI_MAX_ERROR_STRING];
115  MPI_Error_string(errcode, es, &len);
116  printf("myid %d, Errcode from MPI_File_set_view: %d | %s\n", myrank, errcode, es);
117 #endif
118 
119  errcode = MPI_File_write_all_begin(ifp, va, 1,dtype_lsub_arr);
120  MPI_Type_free(&dtype_lsub_arr);
121 
122 /* DIAGNOSTICS */
123 #ifdef DEBUG
124  printf("myid %d\n", myrank);
125  MPI_Error_string(errcode, es, &len);
126  printf("myid %d, Errcode from MPI_File_write_all_begin: %d | %s\n", myrank, errcode, es);
127 #endif
128 
129  return (int) AL_SUCCESS;
130 }
static double a
Definition: init.c:135
#define AL_SUCCESS
Definition: al_codes.h:32
MPI_Datatype gsubarr
Definition: al_hidden.h:110
MPI_File ifp
Definition: al_hidden.h:117
MPI_Datatype lsubarr
Definition: al_hidden.h:111
int k
Definition: analysis.c:2
#define s
int i
Definition: analysis.c:2
MPI_Comm comm
Definition: al_hidden.h:47
SZ * sz_stack[AL_MAX_ARRAYS]
Definition: al_szptr_.c:18
Definition: al_hidden.h:38
int AL_Write_array_end ( void *  va,
int  sz_ptr 
)

Completition of writing of a distributed array to a parallel file by using asynchronous MPI-IO

Parameters
[in]bufferpointer to the buffer to write
[in]sz_ptrinteger pointer to the distributed array descriptor

Definition at line 133 of file al_write_array_async.c.

141 {
142  char *a;
143  SZ *s;
144 
145  MPI_Status status;
146 
147  MPI_File ifp;
148 
149  int errcode;
150 
151  int myrank;
152  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
153 
154  a = (char *) va;
155 
156  s = sz_stack[sz_ptr];
157  ifp = s->ifp;
158 
159  errcode=MPI_File_write_all_end(ifp, a, &status);
160 
161  /* DIAGNOSTICS */
162 #ifdef DEBUG
163  int len;
164  char es[128];
165  if( errcode ){
166  MPI_Error_string(errcode, es, &len);
167  printf("Errcode from MPI_File_write_all_end: %d | %s\n", errcode, es);
168  }
169 #endif
170 
171  MPI_File_sync(ifp);
172 
173  return (int) AL_SUCCESS;
174 }
static double a
Definition: init.c:135
#define AL_SUCCESS
Definition: al_codes.h:32
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

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.