SIONlib  1.7.5
Scalable I/O library for parallel access to task-local files
sion_generic_internal.c
Go to the documentation of this file.
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2019 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
19 #define _XOPEN_SOURCE 700
20 
21 
22 #if defined(_SION_MSA_HOSTNAME_REGEX)
23 #include <regex.h>
24 #endif
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <unistd.h>
29 
30 #include "sion.h"
31 #include "sion_debug.h"
32 #include "sion_error_handler.h"
33 #include "sion_file.h"
34 #include "sion_filedesc.h"
35 #include "sion_fd.h"
36 #include "sion_metadata.h"
37 #include "sion_internal.h"
38 #include "sion_printts.h"
39 #include "sion_keyvalue.h"
40 #include "sion_flags.h"
41 
42 #include "sion_cache.h"
43 #include "sion_buffer.h"
44 #include "sion_flags.h"
45 #include "sion_hints.h"
46 #include "sion_generic_internal.h"
48 #include "sion_generic_buddy.h"
49 #include "sion_internal_startptr.h"
50 
74  int sid,
75  char *fname,
76  _sion_flags_store *flags_store,
77  char *prefix,
78  int *numFiles,
79  int *filenumber,
80  sion_int64 *chunksize,
81  sion_int32 *fsblksize,
82  int rank,
83  int ntasks,
84  int *globalrank,
85  int flag,
86  FILE **fileptr,
87  _sion_generic_gendata *sion_gendata,
88  _sion_generic_buddy *buddy_data )
89 {
90 
91  int i, j;
92  int rc;
93 
94  _sion_filedesc *sion_filedesc;
95  _sion_fileptr *sion_fileptr;
96 
97  int nfiles, filenum;
98  sion_int64 lchunksize, lstartpointer, lglobalrank, new_fsblocksize, helpint64, apiflag;
99  sion_int64 *sion_tmpintfield = NULL;
100  sion_int32 *sion_tmpintfield_map = NULL, helpint32;
101  sion_int32 *sion_tmpintfield_buddy32 = NULL;
102  sion_int64 *sion_tmpintfield_buddy64 = NULL;
103  void *comm_group=NULL;
104  int do_open_file;
105 
106  _sion_flags_entry* flags_entry = NULL;
107 
108  if (flags_store->mask&_SION_FMODE_POSIX) apiflag=SION_FILE_FLAG_POSIX;
109  else if (flags_store->mask&_SION_FMODE_SIONFWD) apiflag=SION_FILE_FLAG_SIONFWD;
110  else apiflag=SION_FILE_FLAG_ANSI;
111 
112  DPRINTFP((2, "_sion_paropen_generic_one_file", rank, "enter parallel open of file %s in mode %d #tasks=%d\n", fname, (int) flags_store->mask, ntasks));
113  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, "sizeof: int=%d long=%d longlong=%d sion_int32=%d sion_int64=%d\n", sizeof(int), sizeof(long),
114  sizeof(long long), sizeof(sion_int32), sizeof(sion_int64)));
115 
116  /* some shortcuts */
117  nfiles = *numFiles;
118  filenum = *filenumber;
119 
120  /* select local communicator */
121  if(flag& _SION_INTERNAL_FLAG_NORMAL ) comm_group=sion_gendata->comm_data_local;
122  if(flag& _SION_INTERNAL_FLAG_BUDDY_NORMAL ) comm_group=sion_gendata->comm_data_local;
123  if(flag& _SION_INTERNAL_FLAG_BUDDY_SEND ) comm_group=buddy_data->buddy_send.commgroup;
124  if(flag& _SION_INTERNAL_FLAG_BUDDY_COLL ) comm_group=buddy_data->buddy_coll.commgroup;
125  if(flag& _SION_INTERNAL_FLAG_BUDDY_READ ) comm_group=buddy_data->groups[buddy_data->currentgroup]->commgroup;
126 
127  /* decide if file has to be opened physically */
128  do_open_file=1;
129  if (flag&_SION_INTERNAL_FLAG_BUDDY_SEND) do_open_file=0;
130  if ( (flag&_SION_INTERNAL_FLAG_BUDDY_COLL) && (rank>0) ) do_open_file=0;
131  if ( (flag&_SION_INTERNAL_FLAG_BUDDY_READ) && (rank>0) ) do_open_file=0;
132  /* WF: todo decide if data is local, these tasks can read data directly? */
133  DPRINTFP((2, "_sion_paropen_generic_one_file", rank, "do_open_file=%d\n", do_open_file));
134 
135  sion_filedesc = _sion_alloc_filedesc();
136  if (sion_filedesc == NULL) {
137  _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_ABORT,"_sion_paropen_omp: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n",
138  (unsigned long) sizeof(sion_filedesc));
139  }
140  _sion_init_filedesc(sion_filedesc);
141  sion_filedesc->fname = strdup(fname); /* Set the filename */
142 
143  _sion_reassignvcd(sid,sion_filedesc, SION_FILEDESCRIPTOR);
144  sion_filedesc->sid=sid;
145 
146  /* Allocate memory for storing MAXCHUNKS chunksize infos in internal structure */
148  sion_filedesc->lastchunknr = 0; /* Set the current number of chunks */
149  sion_filedesc->currentblocknr = 0; /* Set the current block number */
150 
151  if (flags_store->mask&_SION_FMODE_WRITE) {
152  /* **************** WRITE mode **************** */
153 
154  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, " starting open for write #tasks=%d\n", ntasks));
155 
156  /* check parameter */
157  if (ntasks<0) {
158  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_paropen: wrong number of tasks specific: ntasks=%d (<0), returning ...\n", (int) ntasks));
159  }
160 
161  /* check parameter */
162  if ((chunksize != NULL) && (*chunksize<0)) {
163  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_paropen: ((chunksize != NULL) && (*chunksize<0)), returning ...\n"));
164  }
165 
166  /* check parameter */
167  if ((flag & _SION_INTERNAL_FLAG_NORMAL ) && (globalrank != NULL) && (*globalrank<0)) {
168  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_paropen: ((globalrank != NULL) && (*globalrank<0)), returning ...\n"));
169  }
170 
171  sion_filedesc->state = SION_FILESTATE_PAROPEN;
172  sion_filedesc->mode = SION_FILEMODE_WRITE;
173  sion_filedesc->endianness = _sion_get_endianness_with_flags(flags_store->mask); /* Endianness */
174  sion_filedesc->swapbytes = 0; /* Endianness, swapping bytes */
175  sion_filedesc->fsblksize = *fsblksize;
176  sion_filedesc->rank = rank;
177  sion_filedesc->globalrank = *globalrank;
178  sion_filedesc->ntasks = ntasks;
179  sion_filedesc->nfiles = nfiles;
180  sion_filedesc->filenumber = filenum;
181  sion_filedesc->prefix = strdup(prefix);
182  sion_filedesc->compress = flags_store->mask&_SION_FMODE_COMPRESS;
183  sion_filedesc->usecoll = (flags_store->mask&_SION_FMODE_COLLECTIVE)>0;
184  sion_filedesc->collmergemode = (flags_store->mask&_SION_FMODE_COLLECTIVE_MERGE)>0;
185  sion_filedesc->collmsa = !!_sion_flags_get(flags_store, "collmsa");
186  sion_filedesc->usebuddy = (flags_store->mask&_SION_FMODE_BUDDY)>0;
187  if(sion_filedesc->usebuddy) {
188  sion_filedesc->buddylevel = atoi(_sion_flags_get(flags_store,"buddy")->val);
189  if (sion_filedesc->buddylevel==0) sion_filedesc->buddylevel=1; /* default */
190  }
191 
192  /* open file on rank 0, first time to create file and get fsblksize if necessary */
193  if (rank == 0) {
194  sion_fileptr = _sion_file_open(fname,apiflag|SION_FILE_FLAG_WRITE|SION_FILE_FLAG_CREATE,0);
195  if (!sion_fileptr) {
196  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
197  }
198  if(*fsblksize<=-1) {
199  /* check with fstat fsblksize */
200  new_fsblocksize=(sion_int64) _sion_file_get_opt_blksize(sion_fileptr);
201  if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
202  }
203  _sion_file_close(sion_fileptr);
204  }
205  sion_gendata->apidesc->barrier_cb(comm_group);
206  /* printf("WF: rank=%2d after first barrier fsblksize=%d\n",rank,(int) *fsblksize); */
207 
208  /* distribute new fsblksize */
209  if(*fsblksize==-1) {
210  sion_gendata->apidesc->bcastr_cb(&new_fsblocksize, comm_group, _SION_INT64, 1, 0);
211  *fsblksize=new_fsblocksize;
212  sion_filedesc->fsblksize = *fsblksize;
213  /* printf("WF: rank=%2d after bcast fsblksize=%d new_fsblocksize=%d\n",rank,(int) *fsblksize,(int) new_fsblocksize); */
214  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, "setting fsblksize to %lld\n", new_fsblocksize));
215  }
216 
217  /* check for buffer, needed at this point to set flag before writing header */
218  _sion_cache_check_env(sion_filedesc);
219  _sion_buffer_check_env(sion_filedesc);
220 
221  /* check for keyval parameter, needed at this point to set flag before writing header (flag1) */
222  if (rank == 0) {
223  _sion_keyval_check_env(sion_filedesc, flags_store->mask);
224  }
225  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->keyvalmode, comm_group, _SION_INT32, 1, 0);
226 
227  /* check for collective options */
228  if (rank == 0) {
229  if ((flags_entry = _sion_flags_get(flags_store, "collsize"))) {
230  sion_filedesc->collsize = atoi(flags_entry->val);
231  }
232  _sion_coll_check_env(sion_filedesc);
233  }
234 
235  if (
236  ( flag&_SION_INTERNAL_FLAG_BUDDY_NORMAL )
237  || ( flag&_SION_INTERNAL_FLAG_BUDDY_SEND )
238  || ( flag&_SION_INTERNAL_FLAG_BUDDY_COLL )
239  )
240  {
241  /* overwrite collective info if not set*/
242  if(!sion_filedesc->usecoll) {
243  sion_filedesc->usecoll=1;
244  sion_filedesc->collsize=sion_filedesc->ntasks;
245  };
246  }
247 
248  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->usecoll, comm_group, _SION_INT32, 1, 0);
249  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->collsize, comm_group, _SION_INT32, 1, 0);
250  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->collmergemode, comm_group, _SION_INT32, 1, 0);
251 
252  /* check if API support coalescing I/O */
253  if(sion_filedesc->usecoll) {
254  if(sion_gendata->apidesc->level!=SION_GENERIC_API_LEVEL_FULL) {
255  _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_WARN,"sion_paropen_generic: requested coalescing I/O but API does not support this mode, falling back to individual mode ...\n");
256  sion_filedesc->usecoll=0;
257  }
258  }
259 
260  /* check for hints options */
261  if (rank == 0) {
262  _sion_hints_check_env(sion_filedesc);
263  }
264  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->usehints, comm_group, _SION_INT32, 1, 0);
265  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->hinttype, comm_group, _SION_INT32, 1, 0);
266 
267  /* */ DPRINTFTS(rank, "before alloc");
268  if (rank == 0) {
269  /* memory allocation for internal fields */
270  _sion_alloc_filedesc_arrays(sion_filedesc);
271  if(sion_filedesc->usecoll) _sion_alloc_filedesc_coll_arrays(sion_filedesc);
272  }
273  /* */ DPRINTFTS(rank, "after alloc");
274 
275  /* collect data and init startpointers on PE 0 */
276  lchunksize = (sion_int64) *chunksize;
277  lglobalrank = (sion_int64) *globalrank;
278  sion_filedesc->chunksize_req=lchunksize;
279  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, "lchunksize=%lld lglobalrank=%lld\n", lchunksize,lglobalrank));
280 
281  /* */ DPRINTFTS2(rank, "before gather");
282  sion_gendata->apidesc->gatherr_cb(&lchunksize, sion_filedesc->all_chunksizes, comm_group, _SION_INT64, 1, 0);
283  sion_gendata->apidesc->gatherr_cb(&lglobalrank, sion_filedesc->all_globalranks, comm_group, _SION_INT64, 1, 0);
284 
285  /* check capability of tasks */
286  if(sion_filedesc->usecoll) {
287  sion_filedesc->coll_capability=sion_gendata->apidesc->get_capability_cb(comm_group);
288  sion_gendata->apidesc->gatherr_cb(&sion_filedesc->coll_capability, sion_filedesc->all_coll_capability, comm_group, _SION_INT32, 1, 0);
289  }
290 
291  /* */ DPRINTFTS2(rank, "after gather");
292  if (rank == 0) {
293  /* */ DPRINTFTS(rank, "before calculate");
294  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, "chunksizes[%d - 1]=%ld\n", ntasks,(long) sion_filedesc->all_chunksizes[ntasks - 1]));
295  if (!sion_filedesc->usecoll) _sion_calculate_startpointers(sion_filedesc);
296  else {
297  if (sion_filedesc->collmergemode) _sion_calculate_startpointers_collective_merge(sion_filedesc);
298  else if (sion_filedesc->collmsa) _sion_calculate_startpointers_collective_msa(sion_filedesc);
299  else _sion_calculate_startpointers_collective(sion_filedesc);
300  }
301  /* */ DPRINTFTS(rank, "after calculate");
302  }
303 
304  /* */ DPRINTFTS(rank, "before open");
305  /* open not file on non-collector task if buddy-checkpointing */
306  if(do_open_file) {
307 
308  /* open file on all ranks */
309  sion_fileptr = _sion_file_open(fname,apiflag|SION_FILE_FLAG_WRITE,0);
310  if (!sion_fileptr) {
311  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
312  }
313  /* store data in static data structure (sid) */
314  sion_filedesc->fileptr = sion_fileptr;
315  }
316  sion_gendata->apidesc->barrier_cb(comm_group);
317  /* */ DPRINTFTS(rank, "after open");
318 
319 
320  /* write header */
321  if (rank == 0) {
322 
323  /* apply hint for first meta data block */
324  _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_METADATABLOCK1);
325 
326  /* */ DPRINTFTS(rank, "before writeh");
327  _sion_write_header(sion_filedesc);
328  /* */ DPRINTFTS(rank, "after writeh");
329 
330  /* needed for writing pointer to var part of metadata at the end of the file */
331  sion_filedesc->end_of_header = _sion_file_get_position(sion_filedesc->fileptr);
332  sion_filedesc->start_of_data = sion_filedesc->all_startpointers[0];
333  /*set max. file size */
334  lstartpointer = sion_filedesc->all_startpointers[ntasks - 1]
335  + sion_filedesc->all_chunksizes[ntasks - 1];
336  /* */ DPRINTFTS(rank, "before setp(0)");
337  _sion_file_flush(sion_filedesc->fileptr);
338  _sion_file_set_position(sion_filedesc->fileptr, lstartpointer);
339  /* */ DPRINTFTS(rank, "after setp(0)");
340 
341  }
342 
343  /* distribute start_pos */
344  /* */ DPRINTFTS(rank, "before scatter");
345  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_startpointers, &sion_filedesc->startpos, comm_group, _SION_INT64, 1, 0);
346  /* */ DPRINTFTS(rank, "after scatter");
347 
348  /* distribute chunksize */
349  /* */ DPRINTFTS(rank, "before scatter");
350  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_chunksizes, &sion_filedesc->chunksize, comm_group, _SION_INT64, 1, 0);
351  /* */ DPRINTFTS(rank, "after scatter");
352 
353  /* distribute information for collective operations */
354  if(sion_filedesc->usecoll) {
355  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_coll_collsize, &sion_filedesc->collsize, comm_group, _SION_INT32, 1, 0);
356  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_coll_collector, &sion_filedesc->collector, comm_group, _SION_INT32, 1, 0);
357 
358  _sion_free_filedesc_coll_arrays(sion_filedesc);
359  }
360 
361  /* distribute globalskip */
362  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->globalskip, comm_group, _SION_INT64, 1, 0);
363 
364  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, " start position is %10lld %10.4f MB chunksize=%10lld %10.4f MB\n",
365  sion_filedesc->startpos, sion_filedesc->startpos / 1024.0 / 1024.0,
366  sion_filedesc->chunksize, sion_filedesc->chunksize / 1024.0 / 1024.0
367  ));
368 
369  /* set filepointer on each task */
370  /* */ DPRINTFTS(rank, "before setp");
371  sion_gendata->apidesc->barrier_cb(comm_group);
372  if(do_open_file) {
373  _sion_file_flush(sion_filedesc->fileptr);
374  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->startpos);
375  }
376  sion_filedesc->currentpos = sion_filedesc->startpos;
377  /* given by calculate startpointers ...
378  sion_filedesc->chunksize = (sion_int64) *chunksize;
379  */
380  sion_gendata->apidesc->barrier_cb(comm_group);
381 
382  /* apply hint for first chunk */
383  _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
384 
385  /* */ DPRINTFTS(rank, "after setp");
386  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, " ending open for write #tasks=%d filepos=%lld\n", ntasks, _sion_file_get_position(sion_filedesc->fileptr)));
387 
388  }
389  else if (flags_store->mask&_SION_FMODE_READ) {
390  /* **************** READ mode **************** */
391  if (rank == 0)
392  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, " starting open for read #tasks=%d\n", ntasks));
393 
394  /* open not file on non-collector task if buddy-checkpointing */
395  if(do_open_file) {
396  /* */ DPRINTFTS(rank, "before openR");
397  sion_fileptr = _sion_file_open(fname,apiflag|SION_FILE_FLAG_READ,0);
398  /* */ DPRINTFTS(rank, "after openR");
399  if (!sion_fileptr) {
400  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, " cannot open %s for reading, aborting ...\n", fname));
401  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"_sion_paropen_generic_one_file: cannot open %s for reading, aborting ...\n", fname));
402  }
403  } else {
404  sion_fileptr=NULL;
405  }
406  sion_gendata->apidesc->barrier_cb(comm_group);
407 
408  /* store data in static data structure (sid) */
409  sion_filedesc->fileptr = sion_fileptr;
410  sion_filedesc->rank = rank;
411  sion_filedesc->ntasks = ntasks;
412  sion_filedesc->state = SION_FILESTATE_PAROPEN;
413  sion_filedesc->mode = SION_FILEMODE_READ;
414  sion_filedesc->nfiles = nfiles;
415  sion_filedesc->collmsa = !!_sion_flags_get(flags_store, "collmsa");
416  sion_filedesc->usebuddy = (flags_store->mask&_SION_FMODE_BUDDY)>0;
417  if(sion_filedesc->usebuddy) {
418  sion_filedesc->buddylevel = atoi(_sion_flags_get(flags_store,"buddy")->val);
419  if (sion_filedesc->buddylevel==0) sion_filedesc->buddylevel=1; /* default */
420  }
421 
422  /* creating of mapping from file ranks to rank used in buddy read */
423  if ( flag&_SION_INTERNAL_FLAG_BUDDY_READ ) {
424 
425  /* overwrite collective info if not set*/
426  if(!sion_filedesc->usecoll) {
427  sion_filedesc->usecoll=1;
428  sion_filedesc->collsize=sion_filedesc->ntasks;
429  }
430 
431  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, " create buddy mapping ntasks=%d filentasks=%d\n",ntasks,sion_filedesc->ntasks));
432 
433  if (rank == 0) {
434  sion_tmpintfield_buddy32 = (sion_int32 *) malloc(ntasks * sizeof(sion_int32));
435  if (sion_tmpintfield_buddy32 == NULL) {
436  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"_sion_paropen_generic_one_file: cannot allocate temporary memory of size %lu (sion_tmpintfield_buddy), aborting ...\n",
437  (unsigned long) ntasks * sizeof(sion_int32)));
438  }
439  for (j = 0; j < ntasks; j++) sion_tmpintfield_buddy32[j]=-1;
440  sion_tmpintfield_buddy64 = (sion_int64 *) malloc(ntasks * sizeof(sion_int64));
441  if (sion_tmpintfield_buddy64 == NULL) {
442  free(sion_tmpintfield_buddy32);
443  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"_sion_paropen_generic_one_file: cannot allocate temporary memory of size %lu (sion_tmpintfield_buddy), aborting ...\n",
444  (unsigned long) ntasks * sizeof(sion_int64)));
445  }
446  for (j = 0; j < ntasks; j++) sion_tmpintfield_buddy64[j]=-1;
447  sion_tmpintfield_map = (sion_int32 *) malloc(ntasks * sizeof(sion_int32));
448  if (sion_tmpintfield_map == NULL) {
449  free(sion_tmpintfield_buddy32);
450  free(sion_tmpintfield_buddy64);
451  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"_sion_paropen_generic_one_file: cannot allocate temporary memory of size %lu (sion_tmpintfield_map), aborting ...\n",
452  (unsigned long) ntasks * sizeof(sion_int32)));
453  }
454  for (j = 0; j < ntasks; j++) sion_tmpintfield_map[j]=-1;
455 
456  }
457  helpint32=buddy_data->groups[buddy_data->currentgroup]->filelrank;
458  sion_gendata->apidesc->gatherr_cb(&helpint32, sion_tmpintfield_map, comm_group, _SION_INT32, 1, 0);
459 
460 
461  if (rank == 0) {
462  for (j = 0; j < ntasks; j++)
463  DPRINTFP((64, "_sion_paropen_generic_one_file", rank, " buddy map[%d]=%d\n", j, (int) sion_tmpintfield_map[j]));
464  }
465 
466  }
467 
468  if (rank == 0) {
469  rc = _sion_read_header_fix_part(sion_filedesc); /* overwrites sion_filedesc->ntasks */
470  if (rc!=SION_SUCCESS) {
471  free(sion_tmpintfield_buddy32);
472  free(sion_tmpintfield_buddy64);
473  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"_sion_paropen_generic_one_file: cannot read header from file %s, aborting ...\n", fname));
474  }
475  DPRINTFP((32, "_sion_paropen_generic_one_file", rank,
476  " read, after read of fix header part endianness=0x%x blksize=%d ntasks=%d\n", sion_filedesc->endianness, sion_filedesc->fsblksize, sion_filedesc->ntasks));
477 
478  /* */ DPRINTFTS(rank, "before alloc");
479  /* memory allocation */
480  _sion_alloc_filedesc_arrays(sion_filedesc);
481  /* */ DPRINTFTS(rank, "after alloc");
482 
483  rc = _sion_read_header_var_part(sion_filedesc);
484  if (rc!=SION_SUCCESS) {
485  free(sion_tmpintfield_buddy32);
486  free(sion_tmpintfield_buddy64);
487  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"_sion_paropen_generic_one_file: cannot read header from file %s, aborting ...\n", fname));
488  }
489 
490  if ((flags_entry = _sion_flags_get(flags_store, "collsize"))) {
491  sion_filedesc->collsize = atoi(flags_entry->val);
492  }
493  _sion_coll_check_env(sion_filedesc);
494  if(sion_filedesc->usecoll) _sion_alloc_filedesc_coll_arrays(sion_filedesc);
495 
496  /* collective */
497  if (!sion_filedesc->usecoll) _sion_calculate_startpointers(sion_filedesc);
498  else {
499  if (sion_filedesc->collmergemode) _sion_calculate_startpointers_collective_merge(sion_filedesc);
500  else if (sion_filedesc->collmsa) _sion_calculate_startpointers_collective_msa(sion_filedesc);
501  else _sion_calculate_startpointers_collective(sion_filedesc);
502  }
503  /* */ DPRINTFTS(rank, "after calculate");
504 
505  /* check for keyval parameter, needed at this point to set flag before writing header (flag1) */
506  _sion_keyval_check_env(sion_filedesc, flags_store->mask);
507 
508  } /* rank==0 */
509 
510  /* distribute keyvalmode */
511  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->keyvalmode, comm_group, _SION_INT32, 1, 0);
512 
513  /* distribute collective options */
514  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->usecoll, comm_group, _SION_INT32, 1, 0);
515  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->collsize, comm_group, _SION_INT32, 1, 0);
516 
517 
518  DPRINTFP((32, "_sion_paropen_generic_one_file", rank," usecoll=%d\n", sion_filedesc->usecoll));
519 
520  if(sion_filedesc->usecoll) {
521 
522  if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
523  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_coll_collsize, &sion_filedesc->collsize, comm_group, _SION_INT32, 1, 0);
524  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_coll_collector, &sion_filedesc->collector, comm_group, _SION_INT32, 1, 0);
525  } else {
526 
527  /* remap data */
528  if(rank==0) for (j = 0; j < ntasks; j++) if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy32[j]=sion_filedesc->all_coll_collsize[sion_tmpintfield_map[j]];
529  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy32, &sion_filedesc->collsize, comm_group, _SION_INT32, 1, 0);
530  /* remap data */
531  if(rank==0) for (j = 0; j < ntasks; j++) if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy32[j]=sion_filedesc->all_coll_collector[sion_tmpintfield_map[j]];
532  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy32, &sion_filedesc->collector, comm_group, _SION_INT32, 1, 0);
533  }
534 
535 
536  _sion_free_filedesc_coll_arrays(sion_filedesc);
537  }
538 
539  /* distribute globalskip */
540  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->globalskip, comm_group, _SION_INT64, 1, 0);
541 
542  /* broadcast information read from file */
543  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->endianness, comm_group, _SION_INT32, 1, 0);
544  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->swapbytes, comm_group, _SION_INT32, 1, 0);
545  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->fsblksize, comm_group, _SION_INT32, 1, 0);
546  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->ntasks, comm_group, _SION_INT32, 1, 0);
547  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->fileversion, comm_group, _SION_INT32, 1, 0);
548  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->nfiles, comm_group, _SION_INT32, 1, 0);
549  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->filenumber, comm_group, _SION_INT32, 1, 0);
550  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->flag1, comm_group, _SION_INT32, 1, 0);
551  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->flag2, comm_group, _SION_INT32, 1, 0);
552  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->maxusedchunks, comm_group, _SION_INT32, 1, 0);
553 
554  DPRINTFP((32, "_sion_paropen_generic_one_file", rank,
555  " read, after read of maxusedchunks=%d maxchunks=%d (%d)\n", sion_filedesc->maxusedchunks,sion_filedesc->maxchunks, MAXCHUNKS));
556  if (sion_filedesc->maxusedchunks > MAXCHUNKS) _sion_realloc_filedesc_blocklist(sion_filedesc, sion_filedesc->maxusedchunks);
557  /* */ DPRINTFTS(rank, "after bcast");
558 
559  /* scatter per task information read from file */
560  /* */ DPRINTFTS(rank, "before scatter");
561  if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
562  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_chunksizes, &sion_filedesc->chunksize, comm_group, _SION_INT64, 1, 0);
563  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_startpointers, &sion_filedesc->startpos, comm_group, _SION_INT64, 1, 0);
564  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_globalranks, &helpint64, comm_group, _SION_INT64, 1, 0);sion_filedesc->globalrank=(sion_int32) helpint64;
565  } else {
566  /* remap data */
567  if(rank==0) for (j = 0; j < ntasks; j++) if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_filedesc->all_chunksizes[sion_tmpintfield_map[j]];
568  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &sion_filedesc->chunksize, comm_group, _SION_INT64, 1, 0);
569  /* remap data */
570  if(rank==0) for (j = 0; j < ntasks; j++) if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_filedesc->all_startpointers[sion_tmpintfield_map[j]];
571  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &sion_filedesc->startpos, comm_group, _SION_INT64, 1, 0);
572  /* remap data */
573  if(rank==0) for (j = 0; j < ntasks; j++) if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_filedesc->all_globalranks[sion_tmpintfield_map[j]];
574  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);sion_filedesc->globalrank=(sion_int32) helpint64;
575  }
576 
577  /* */ DPRINTFTS(rank, "after scatter");
578 
579  /* read number of blocks for each task */
580  if (rank == 0) {
581  sion_tmpintfield = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
582  if (sion_tmpintfield == NULL) {
583  free(sion_tmpintfield_buddy32);
584  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"_sion_paropen_generic_one_file: cannot allocate temporary memory of size %lu (sion_tmpintfield), aborting ...\n",
585  (unsigned long) ntasks * sizeof(sion_int64)));
586  }
587  _sion_read_header_var_part_blockcount_to_field(sion_filedesc, sion_filedesc->ntasks, sion_tmpintfield);
588 
589  for (j = 0; j < sion_filedesc->ntasks; j++)
590  DPRINTFP((2048, "_sion_paropen_generic_one_file", rank, " read, blockcount on task %02d is %10ld\n", j, (long) sion_tmpintfield[j]));
591  }
592 
593  /* and distribute them */
594  /* */ DPRINTFTS(rank, "before scatter");
595  if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
596  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield, &helpint64, comm_group, _SION_INT64, 1, 0);
597  } else {
598  /* remap data */
599  if(rank==0) for (j = 0; j < ntasks; j++) if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_tmpintfield[sion_tmpintfield_map[j]];
600  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);
601  }
602  /* */ DPRINTFTS(rank, "after scatter");
603  sion_filedesc->lastchunknr = helpint64-1;
604  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, " lastchunknr on task %02d is %10ld\n", rank, (long) sion_filedesc->lastchunknr));
605 
606  for (i = 0; i < sion_filedesc->maxusedchunks; i++) {
607  if (rank == 0) _sion_read_header_var_part_nextblocksizes_to_field(sion_filedesc, sion_filedesc->ntasks, sion_tmpintfield);
608  /* */ DPRINTFTS(rank, "before scatter");
609  if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
610  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield, &helpint64, comm_group, _SION_INT64, 1, 0);
611  } else {
612  /* remap data */
613  if(rank==0) for (j = 0; j < ntasks; j++) if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_tmpintfield[sion_tmpintfield_map[j]];
614  sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);
615  }
616  /* */ DPRINTFTS(rank, "after scatter");
617  sion_filedesc->blocksizes[i] = helpint64;
618  }
619 
620 #define BGFLUSH
621 #ifdef BGFLUSH
622  if(do_open_file) {
623  _sion_file_flush(sion_filedesc->fileptr);
624  }
625 #endif
626 
627  /* */ DPRINTFTS(rank, "before setp");
628  sion_gendata->apidesc->barrier_cb(comm_group);
629  if(do_open_file) {
630  _sion_file_purge(sion_filedesc->fileptr);
631  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->startpos);
632  }
633  sion_filedesc->currentpos = sion_filedesc->startpos;
634  sion_filedesc->currentblocknr = 0;
635 
636  /* OUTPUT parameters */
637  *fsblksize = sion_filedesc->fsblksize;
638  *chunksize = sion_filedesc->chunksize;
639  *globalrank = sion_filedesc->globalrank;
640 
641  /* free tmp field */
642  if(sion_tmpintfield) free(sion_tmpintfield);
643  if(sion_tmpintfield_map) free(sion_tmpintfield_map);
644  if(sion_tmpintfield_buddy32) free(sion_tmpintfield_buddy32);
645  if(sion_tmpintfield_buddy64) free(sion_tmpintfield_buddy64);
646 
647  sion_gendata->apidesc->barrier_cb(comm_group);
648  /* */ DPRINTFTS(rank, "after setp");
649  /* end of read */
650  } else {
651  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_paropen_multi_mpi: unknown file mode"));
652  }
653 
654  if(do_open_file) {
655  if(fileptr!=NULL) {
656  if(sion_filedesc->fileptr->flags&SION_FILE_FLAG_ANSI) {
657  *fileptr=sion_filedesc->fileptr->fileptr;
658  sion_filedesc->fileptr_exported=1;
659  } else {
660  *fileptr=NULL;
661  sion_filedesc->fileptr_exported=0;
662  }
663  }
664  } else {
665  if(fileptr!=NULL) *fileptr=NULL;
666  sion_filedesc->fileptr_exported=0;
667  }
668 
669  if (rank == 0) {
670  /* not needed for rest of sionlib function calls */
671  _sion_free_filedesc_arrays(sion_filedesc);
672  }
673 
674  _sion_print_filedesc(sion_filedesc, 512, "_sion_paropen_generic_one_file", 1);
675 
676  DPRINTFP((32, "_sion_paropen_generic_one_file", rank, " start position on task %02d is at end of sion_paropen_generic %10lld\n", rank,
677  _sion_file_get_position(sion_filedesc->fileptr)));
678 
679  DPRINTFP((2, "_sion_paropen_generic_one_file", rank, "leave parallel open of file %s in mode 0x%lx #tasks=%d\n", fname, (long) flags_store->mask, ntasks));
680 
681  return (sid);
682 
683 
684 }
685 
686 
687 
702 int _sion_parclose_generic(int sid,
703  int rank,
704  int ntasks,
705  int mapping_size,
706  sion_int32 *mapping,
707  int flag,
708  _sion_generic_gendata *sion_gendata,
709  _sion_generic_buddy *buddy_data)
710 {
711 
712  int rc = SION_SUCCESS;
713  int blknum, lrank;
714  sion_int64 helpint64;
715  sion_int64 *sion_tmpintfield = NULL;
716  _sion_filedesc *sion_filedesc;
717  void *comm_group=NULL;
718  int do_close_file;
719 
720  if ((_sion_vcdtype(sid) != SION_FILEDESCRIPTOR) || !(sion_filedesc = _sion_vcdtovcon(sid))) {
721  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_parclose_generic: invalid sion_filedesc, aborting %d ...\n", sid));
722  }
723 
724  if (sion_filedesc->state != SION_FILESTATE_PAROPEN) {
725  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_parclose_generic: sion file with sid=%d was not opened by a sion_paropen\n", sid));
726  }
727 
728  DPRINTFP((2, "_sion_parclose_generic", rank, "enter parallel close sid=%d\n", sid));
729 
730  /* select local communicator */
731  if(flag& _SION_INTERNAL_FLAG_NORMAL ) comm_group=sion_gendata->comm_data_local;
732  if(flag& _SION_INTERNAL_FLAG_BUDDY_SEND ) comm_group=buddy_data->buddy_send.commgroup;
733  if(flag& _SION_INTERNAL_FLAG_BUDDY_COLL ) comm_group=buddy_data->buddy_coll.commgroup;
734  if(flag& _SION_INTERNAL_FLAG_BUDDY_READ ) comm_group=buddy_data->groups[buddy_data->currentgroup]->commgroup;
735 
736  /* decide if file has to be opened physically */
737  do_close_file=1;
738  if (flag&_SION_INTERNAL_FLAG_BUDDY_SEND) do_close_file=0;
739  if ( (flag&_SION_INTERNAL_FLAG_BUDDY_COLL) && (rank>0) ) do_close_file=0;
740  if ( (flag&_SION_INTERNAL_FLAG_BUDDY_READ) && (rank>0) ) do_close_file=0;
741 
742  /* READ MODE: close file on all tasks */
743  if (sion_filedesc->mode == SION_FILEMODE_READ) {
744  if (sion_filedesc->state != SION_FILESTATE_CLOSE) {
745 
746  _sion_print_filedesc(sion_filedesc, 512, "_sion_parclose_generic", 1);
747  DPRINTFP((32, "_sion_parclose_generic", rank, " parallel close (read mode) sid=%d, call fclose on file\n", sid));
748 
749  if(do_close_file) {
750  _sion_file_close(sion_filedesc->fileptr);
751  }
752  sion_filedesc->fileptr = NULL;
753  sion_filedesc->state = SION_FILESTATE_CLOSE;
754  }
755  }
756  else {
757  /* WRITE MODE: collect data from all tasks, write metadata, and close file on all tasks */
758 
759  /* _sion_buffer_flush(sion_filedesc); */ /* clear internal buffer */
760  _sion_flush_block(sion_filedesc);
761 
762  if (sion_filedesc->usebuffer) {
763  _sion_buffer_flush(sion_filedesc);
764  }
765 
766  _sion_print_filedesc(sion_filedesc, 512, "_sion_parclose_generic", 1);
767 
768  /* close file on all other task, except 0 */
769  if (rank != 0) {
770  if (sion_filedesc->state != SION_FILESTATE_CLOSE) {
771  DPRINTFP((32, "_sion_parclose_generic", rank, " parallel close (write mode) sid=%d, call fclose on file\n", sid));
772  if(do_close_file) {
773  _sion_file_close(sion_filedesc->fileptr);
774  }
775  sion_filedesc->fileptr = NULL;
776  sion_filedesc->state = SION_FILESTATE_CLOSE;
777  }
778  }
779 
780  sion_gendata->apidesc->barrier_cb(comm_group);
781 
782  DPRINTFP((32, "_sion_parclose_generic", rank, " parallel close sid=%d: lastchunknr=%d globalskip=%lld\n", sid, sion_filedesc->lastchunknr,
783  sion_filedesc->globalskip));
784  for (blknum = 0; blknum <= sion_filedesc->lastchunknr; blknum++) {
785  DPRINTFP((1024, "_sion_parclose_generic", rank, " parallel close sid=%d: local block %02d -> %10lld bytes\n", sid, blknum,
786  sion_filedesc->blocksizes[blknum]));
787  }
788 
789  if (rank == 0) {
790  sion_tmpintfield = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
791  if (sion_tmpintfield == NULL) {
792  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield), aborting ...\n",
793  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
794  }
795  }
796 
797  /* gather number of blocks of each tasks, and search maxusedchunks */
798  /* */ DPRINTFTS2(rank, "before gather");
799  helpint64 = sion_filedesc->lastchunknr + 1;
800  sion_gendata->apidesc->gatherr_cb(&helpint64, sion_tmpintfield, comm_group, _SION_INT64, 1, 0);
801 
802  if (rank == 0) {
803  sion_filedesc->maxusedchunks = -1;
804  for (blknum = 0; blknum < sion_filedesc->ntasks; blknum++)
805  if (sion_tmpintfield[blknum] > sion_filedesc->maxusedchunks)
806  sion_filedesc->maxusedchunks = (int) sion_tmpintfield[blknum];
807  }
808  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->maxusedchunks, comm_group, _SION_INT32, 1, 0);
809  /* */ DPRINTFTS2(rank, "after gather");
810 
811  /* calculate and set start_of_varheader */
812  sion_filedesc->start_of_varheader = sion_filedesc->start_of_data + sion_filedesc->maxusedchunks * sion_filedesc->globalskip;
813 
814  /* write rest of first meta data block on rank 0 */
815  if (rank == 0) {
816  _sion_write_header_var_info(sion_filedesc);
817 
818  _sion_write_header_var_part_blockcount_from_field(sion_filedesc,sion_filedesc->ntasks,sion_tmpintfield);
819 
820  }
821 
822  /* collect chunksizes of each block from each task and write it to file */
823  for (blknum = 0; blknum < sion_filedesc->maxusedchunks; blknum++) {
824  if (blknum <= sion_filedesc->lastchunknr) {
825  helpint64 = sion_filedesc->blocksizes[blknum];
826  }
827  else {
828  helpint64 = 0;
829  }
830 
831  /* */ DPRINTFTS2(rank, "before gather");
832  sion_gendata->apidesc->gatherr_cb(&helpint64, sion_tmpintfield, comm_group, _SION_INT64, 1, 0);
833  /* */ DPRINTFTS2(rank, "after gather");
834 
835  if (rank == 0) {
836  for (lrank = 0; lrank < ntasks; lrank++)
837  DPRINTFP((2048, "_sion_parclose_generic", rank, " parallel close sid=%d: write total chunksize for block %d: %2lld rank=%d\n", sid, blknum,
838  sion_tmpintfield[lrank], lrank));
839 
840  _sion_write_header_var_part_nextblocksizes_from_field(sion_filedesc,sion_filedesc->ntasks,sion_tmpintfield);
841 
842  }
843  }
844 
845  /* write mapping to file if more than one physical file is used, mapping_size is the number of global tasks */
846  if (mapping != NULL) {
847  _sion_write_header_var_part_mapping(sion_filedesc, mapping_size, mapping);
848  }
849 
850  /* close file on task 0 */
851  if (rank == 0) {
852  DPRINTFP((32, "_sion_parclose_generic", rank, " parallel close (write mode) sid=%d, call fclose on file\n", sid));
853  if(do_close_file) {
854  _sion_file_close(sion_filedesc->fileptr);
855  }
856  sion_filedesc->fileptr = NULL;
857  sion_filedesc->state = SION_FILESTATE_CLOSE;
858 
859  /* free tmp field */
860  if(sion_tmpintfield) free(sion_tmpintfield);
861  }
862 
863  } /* write */
864 
865  _sion_free_filedesc(sion_filedesc);
866  sion_filedesc = NULL;
867 
868 
869  DPRINTFP((2, "_sion_parclose_generic", rank, "leave parallel close sid=%d\n", sid));
870 
871  return (rc);
872 }
873 
879  int sid,
880  sion_int64 chunksize,
881  int rank,
882  int ntasks,
883  _sion_generic_gendata *sion_gendata)
884 {
885 
886  int rc = SION_SUCCESS;
887  _sion_filedesc *sion_filedesc;
888  sion_int64 lchunksize, lstartpointer, lglobalrank;
889  void *comm_group=NULL;
890 
891  if ((_sion_vcdtype(sid) != SION_FILEDESCRIPTOR) || !(sion_filedesc = _sion_vcdtovcon(sid))) {
892  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_parreinit_generic: invalid sion_filedesc, aborting %d ...\n", sid));
893  }
894 
895  if (sion_filedesc->state != SION_FILESTATE_PAROPEN) {
896  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_parreinit_generic: sion file with sid=%d was not opened by a sion_paropen\n", sid));
897  }
898 
899  DPRINTFP((2, "_sion_parreinit_generic", sion_filedesc->rank, "enter parallel reinit sid=%d\n", sid));
900 
901  comm_group=sion_gendata->comm_data_local;
902 
903  if (sion_filedesc->mode == SION_FILEMODE_READ) {
904  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_parreinit_generic: sion file with sid=%d only allowed for files openend for write\n", sid));
905  }
906 
907  /* */ DPRINTFTS(sion_filedesc->rank, "before alloc");
908  if (sion_filedesc->rank == 0) {
909  /* memory allocation for internal fields */
910  _sion_alloc_filedesc_arrays(sion_filedesc);
911  }
912  /* */ DPRINTFTS(sion_filedesc->rank, "after alloc");
913 
914  /* collect new chunksize data and init startpointers on PE 0 */
915  lchunksize = (sion_int64) chunksize;
916  lglobalrank = (sion_int64) sion_filedesc->globalrank;
917 
918  /* */ DPRINTFTS2(sion_filedesc->rank, "before gather");
919  sion_gendata->apidesc->gatherr_cb(&lchunksize, sion_filedesc->all_chunksizes, comm_group, _SION_INT64, 1, 0);
920  sion_gendata->apidesc->gatherr_cb(&lglobalrank, sion_filedesc->all_globalranks, comm_group, _SION_INT64, 1, 0);
921 
922  /* */ DPRINTFTS2(sion_filedesc->rank, "after gather");
923 
924  if(sion_filedesc->usecoll) _sion_alloc_filedesc_coll_arrays(sion_filedesc);
925 
926  if (sion_filedesc->rank == 0) {
927  /* */ DPRINTFTS(sion_filedesc->rank, "before calculate");
928  if (!sion_filedesc->usecoll) _sion_calculate_startpointers(sion_filedesc);
929  else _sion_calculate_startpointers_collective(sion_filedesc);
930  /* */ DPRINTFTS(sion_filedesc->rank, "after calculate");
931  }
932 
933  /* write header again */
934  if (sion_filedesc->rank == 0) {
935 
936  /* apply hint for first meta data block */
937  _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_METADATABLOCK1);
938 
939  _sion_file_flush(sion_filedesc->fileptr);
940  lstartpointer=0;
941  _sion_file_set_position(sion_filedesc->fileptr, lstartpointer);
942 
943  /* */ DPRINTFTS(sion_filedesc->rank, "before writeh");
944  _sion_write_header(sion_filedesc);
945  /* */ DPRINTFTS(sion_filedesc->rank, "after writeh");
946 
947  /* needed for writing pointer to var part of metadata at the end of the file */
948  sion_filedesc->end_of_header = _sion_file_get_position(sion_filedesc->fileptr);
949  sion_filedesc->start_of_data = sion_filedesc->all_startpointers[0];
950 
951  /*set max. file size */
952  lstartpointer = sion_filedesc->all_startpointers[sion_filedesc->ntasks - 1]
953  + sion_filedesc->all_chunksizes[sion_filedesc->ntasks - 1];
954  /* */ DPRINTFTS(sion_filedesc->rank, "before setp(0)");
955  _sion_file_flush(sion_filedesc->fileptr);
956  _sion_file_set_position(sion_filedesc->fileptr, lstartpointer);
957  /* */ DPRINTFTS(sion_filedesc->rank, "after setp(0)");
958 
959  }
960 
961  /* distribute start_pos */
962  /* */ DPRINTFTS(sion_filedesc->rank, "before scatter");
963  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_startpointers, &sion_filedesc->startpos, comm_group, _SION_INT64, 1, 0);
964  /* */ DPRINTFTS(sion_filedesc->rank, "after scatter");
965 
966  /* distribute information for collective operations */
967  if(sion_filedesc->usecoll) {
968  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_coll_collsize, &sion_filedesc->collsize, comm_group, _SION_INT32, 1, 0);
969  sion_gendata->apidesc->scatterr_cb(sion_filedesc->all_coll_collector, &sion_filedesc->collector, comm_group, _SION_INT32, 1, 0);
970 
971  _sion_free_filedesc_coll_arrays(sion_filedesc);
972  }
973 
974  /* distribute globalskip */
975  sion_gendata->apidesc->bcastr_cb(&sion_filedesc->globalskip, comm_group, _SION_INT64, 1, 0);
976 
977  DPRINTFP((32, "_sion_parreinit_generic", sion_filedesc->rank, " start position is %10lld %10.4f MB\n",
978  sion_filedesc->startpos, sion_filedesc->startpos / 1024.0 / 1024.0));
979 
980  /* set filepointer on each task */
981  /* */ DPRINTFTS(sion_filedesc->rank, "before setp");
982  sion_gendata->apidesc->barrier_cb(comm_group);
983  _sion_file_flush(sion_filedesc->fileptr);
984  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->startpos);
985  sion_filedesc->currentpos = sion_filedesc->startpos;
986  sion_filedesc->chunksize = (sion_int64) chunksize;
987  sion_gendata->apidesc->barrier_cb(comm_group);
988 
989  /* apply hint for first chunk */
990  _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
991 
992  if (sion_filedesc->rank == 0) {
993  /* not needed for rest of sionlib function calls */
994  _sion_free_filedesc_arrays(sion_filedesc);
995  }
996 
997  /* */ DPRINTFTS(sion_filedesc->rank, "after setp");
998  DPRINTFP((32, "_sion_parreinit_generic", sion_filedesc->rank, " ending open for write #tasks=%d filepos=%lld\n",
999  sion_filedesc->ntasks, _sion_file_get_position(sion_filedesc->fileptr)));
1000 
1001  DPRINTFP((2, "_sion_parreinit_generic", sion_filedesc->rank, "leave parallel reinit of file %s in #tasks=%d\n",
1002  sion_filedesc->fname, sion_filedesc->ntasks));
1003 
1004  return (rc);
1005 
1006 
1007 }
1008 
1009 
1014 #define DFUNCTION "_sion_generic_collect_mapping"
1015 int _sion_generic_collect_mapping( _sion_filedesc *sion_filedesc,
1016  int *mapping_size,
1017  sion_int32 **mapping ) {
1018  int rc=SION_SUCCESS;
1019  int t;
1020  _sion_generic_gendata *sion_gendata;
1021  _sion_generic_apidesc *sion_apidesc;
1022  sion_int32 lpos[2], *receivemap=NULL, iamreceiver, receiver = -1;
1023 
1024 
1025  sion_gendata=sion_filedesc->dataptr;
1026  sion_apidesc=sion_gendata->apidesc;
1027 
1028  *mapping = NULL; *mapping_size = 0;
1029 
1030  if ((sion_filedesc->mode == SION_FILEMODE_WRITE) && (sion_filedesc->nfiles > 1)) {
1031  /* collect mapping to files to task 0 */
1032 
1033  /* mapping data will be collected by master of first physical file */
1034  if((sion_filedesc->filenumber==0) && (sion_filedesc->rank==0)) {
1035  /* allocate data */
1036  *mapping_size=sion_gendata->gsize;
1037  *mapping = (sion_int32 *) malloc(*mapping_size * 2 * sizeof(sion_int32));
1038  if (*mapping == NULL) {
1039  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_generic_parclose: Cannot allocate memory for mapping"));
1040  }
1041  }
1042 
1043  /* gather info about send about global rank of master of first file on grank 0 */
1044  if(sion_gendata->grank==0) {
1045  receivemap = (sion_int32 *) malloc(sion_gendata->gsize * sizeof(sion_int32));
1046  if (receivemap == NULL) {
1047  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_generic_parclose: Cannot allocate memory for receivemap"));
1048  }
1049  }
1050 
1051  if((sion_filedesc->filenumber==0) && (sion_filedesc->rank==0)) iamreceiver=sion_gendata->grank;
1052  else iamreceiver=-1;
1053  sion_apidesc->gatherr_cb(&iamreceiver, receivemap, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
1054  if(sion_gendata->grank==0) {
1055  for(t=0;t<sion_gendata->gsize;t++) {
1056  if(receivemap[t]>=0) {
1057  receiver=receivemap[t];
1058  break;
1059  }
1060  }
1061  DPRINTFP((1, DFUNCTION, sion_gendata->grank, "receiver of mapping grank=%d\n", receiver));
1062  }
1063  sion_apidesc->bcastr_cb(&receiver, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
1064 
1065  /* receive global rank of master of first file on grank 0 */
1066  lpos[0] = sion_filedesc->filenumber;
1067  lpos[1] = sion_filedesc->rank;
1068  sion_apidesc->gatherr_cb(&lpos, *mapping, sion_gendata->comm_data_global, _SION_INT32, 2, receiver);
1069  }
1070 
1071  if(receivemap!=NULL) free(receivemap);
1072 
1073  return(rc);
1074 }
1075 #undef DFUNCTION
1076 
1077 /* END OF _sion_parclose_generic */
1078 
1086 {
1087  int grank = comm->grank;
1088  int gsize = comm->gsize;
1089 
1090  DPRINTFP((2, __func__, grank, "enter\n"));
1091 
1092  if (0 != strcmp(comm->apidesc->name, "SIONlib_MPI_API")) {
1093  return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN, "MSA Collectives: not supported for generic API \"%s\"\n", comm->apidesc->name);
1094  }
1095 
1096  _sion_filedesc fd;
1097  _sion_init_filedesc(&fd);
1098  fd.ntasks = gsize;
1099  _sion_flags_entry *flags_entry = _sion_flags_get(flags, "collsize");
1100  if (flags_entry) {
1101  fd.collsize = atoi(flags_entry->val);
1102  }
1103  _sion_coll_check_env(&fd);
1104  sion_int32 collsize = fd.collsize;
1105  if (collsize < 2) {
1106  return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN, "MSA Collectives: size of collective groups should be 2 or more, but is %d\n", collsize);
1107  }
1108  sion_int32 n_groups = gsize / collsize + ((gsize % collsize) ? 1 : 0);
1109 
1110  if (!fd.usecoll) {
1111  return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN, "MSA Collectives: usecoll == false\n");
1112  }
1113 
1114  int is_candidate = _sion_generic_is_candidate(comm);
1115  int n_candidates = 0;
1116  int candidates_before = 0;
1117  // bring your own Allreduce and Exscan
1118  {
1119  int *candidates = NULL;
1120  if (0 == comm->grank) {
1121  candidates = calloc(gsize, sizeof(int));
1122  if (!candidates) {
1123  _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_ABORT, "MSA Collectives: malloc returned NULL\n");
1124  }
1125  }
1126 
1127  comm->apidesc->gatherr_cb(&is_candidate, candidates, comm->comm_data_global, _SION_INT32, 1, 0);
1128 
1129  if (0 == comm->grank) {
1130  for (size_t i = 0; i < gsize; i++) {
1131  int tmp = candidates[i];
1132  candidates[i] = n_candidates;
1133  n_candidates += tmp;
1134  }
1135  }
1136 
1137  comm->apidesc->bcastr_cb(&n_candidates, comm->comm_data_global, _SION_INT32, 1, 0);
1138  comm->apidesc->scatterr_cb(candidates, &candidates_before, comm->comm_data_global, _SION_INT32, 1, 0);
1139 
1140  if (0 == comm->grank) {
1141  free(candidates);
1142  }
1143  }
1144 
1145  if ((n_candidates < n_groups) || (n_candidates < comm->numfiles)) {
1146  return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN, "MSA Collectives: insufficient number of candidates %d, number of groups %d, number of files %d\n", n_groups, comm->numfiles);
1147 
1148  }
1149 
1150  int groups_per_file = n_groups / comm->numfiles;
1151  int is_collector = is_candidate && (candidates_before < n_groups);
1152  if (is_collector) {
1153  int rank_collector = candidates_before;
1154  comm->filenumber = rank_collector % comm->numfiles;
1155  comm->lrank = (rank_collector / comm->numfiles) * collsize;
1156  } else {
1157  int collectors_before = (candidates_before < n_groups) ? candidates_before : n_groups;
1158  int rank_sender = grank - collectors_before;
1159  int group_number = rank_sender / (collsize - 1);
1160  comm->filenumber = group_number % comm->numfiles;
1161  comm->lrank = (group_number / comm->numfiles) * collsize + rank_sender % (collsize - 1) + 1;
1162  }
1163  comm->lsize = collsize * (groups_per_file + ((comm->filenumber < n_groups % comm->numfiles) ? 1 : 0));
1164  if (comm->filenumber == comm->numfiles - 1) {
1165  comm->lsize += gsize - n_groups * collsize;
1166  }
1167 
1168  DPRINTFP((32, __func__, grank, "MSA Collectives: global rank %d of %d, is candidate %d, is collector %d, file no %d, local rank %d, local size %d\n", grank, gsize, is_candidate, is_collector, comm->filenumber, comm->lrank, comm->lsize));
1169  DPRINTFP((2, __func__, grank, "exit\n"));
1170  return SION_SUCCESS;
1171 }
1172 
1173 int _sion_generic_is_candidate(_sion_generic_gendata *comm) {
1174 #if defined(_SION_MSA_DEEP_EST_SDV)
1175  char hostname[1024];
1176  if (0 == gethostname(hostname, 1024)) {
1177  if (0 == strncmp("knl", hostname, 3)) {
1178  return 0;
1179  } else {
1180  return 1;
1181  }
1182  } else {
1183  return 0;
1184  }
1185 #elif defined(_SION_MSA_HOSTNAME_REGEX)
1186  char *regex;
1187  regex_t compiled;
1188  int compile_error;
1189  if ((regex = _sion_getenv("SION_MSA_COLLECTOR_HOSTNAME_EREGEX"))) {
1190  compile_error = regcomp(&compiled, regex, REG_EXTENDED|REG_ICASE|REG_NOSUB);
1191  } else if ((regex = _sion_getenv("SION_MSA_COLLECTOR_HOSTNAME_REGEX"))) {
1192  compile_error = regcomp(&compiled, regex, REG_ICASE|REG_NOSUB);
1193  } else {
1194  return 1;
1195  }
1196  if (compile_error) {
1197  char error_msg[1024];
1198  size_t error_size = regerror(compile_error, &compiled, error_msg, 1024);
1199  regfree(&compiled);
1200  _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_ABORT, "MSA Collectives: error compiling regex \"%s\": %s%s\n", regex, error_msg, (error_size > 1024) ? "..." : "");
1201  }
1202 
1203  char hostname[1024];
1204  int hostname_error = gethostname(hostname, 1023);
1205  hostname[1023] = '\0';
1206  if (hostname_error) {
1207  regfree(&compiled);
1208  _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_ABORT, "MSA Collectives: error getting host name\n");
1209  }
1210 
1211  int exec_status = regexec(&compiled, hostname, 0, NULL, 0);
1212  if (exec_status == 0) {
1213  regfree(&compiled);
1214  return 1;
1215  } else if (exec_status == REG_NOMATCH) {
1216  regfree(&compiled);
1217  return 0;
1218  } else {
1219  char error_msg[1024];
1220  size_t error_size = regerror(exec_status, &compiled, error_msg, 1024);
1221  regfree(&compiled);
1222  _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_ABORT, "MSA Collectives: error matching regex \"%s\": %s%s\n", regex, error_msg, (error_size > 1024) ? "..." : "");
1223  return 0; // NOT REACHED
1224  }
1225 #elif defined(_SION_MSA_TEST)
1226  return comm->grank %2;
1227 #else
1228  return 1;
1229 #endif
1230 }
_sion_filedesc_struct::usebuddy
sion_int32 usebuddy
Definition: sion_filedesc.h:191
SION_FILE_FLAG_ANSI
#define SION_FILE_FLAG_ANSI
Definition: sion_file.h:21
_sion_write_header
int _sion_write_header(_sion_filedesc *sion_filedesc)
Write the SION Meta Block 1.
Definition: sion_metadata.c:37
_sion_generic_renumber_collmsa
int _sion_generic_renumber_collmsa(_sion_generic_gendata *comm, _sion_flags_store *flags)
Splits a Communicator in numfiles different communicators.
Definition: sion_generic_internal.c:1084
_sion_filedesc_struct::usehints
sion_int32 usehints
Definition: sion_filedesc.h:197
_sion_filedesc_struct::usebuffer
sion_int32 usebuffer
Definition: sion_filedesc.h:88
_sion_filedesc_struct::all_coll_collector
sion_int32 * all_coll_collector
Definition: sion_filedesc.h:149
_sion_read_header_var_part_nextblocksizes_to_field
int _sion_read_header_var_part_nextblocksizes_to_field(_sion_filedesc *sion_filedesc, int field_size, sion_int64 *field)
Read the next set of blocksizes from Meta Block 2 Assuming that filepointer is at the correct positio...
Definition: sion_metadata.c:606
_sion_cache_check_env
int _sion_cache_check_env(_sion_filedesc *sion_filedesc)
Check if environment variables are set to use cache.
Definition: sion_cache.c:57
_sion_file_close
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
Definition: sion_file.c:139
_sion_filedesc_struct::usecoll
sion_int32 usecoll
Definition: sion_filedesc.h:180
_sion_filedesc_struct::filenumber
sion_int32 filenumber
Definition: sion_filedesc.h:128
_sion_write_header_var_info
int _sion_write_header_var_info(_sion_filedesc *sion_filedesc)
Write the SION Meta Block 1.
Definition: sion_metadata.c:183
_sion_filedesc_struct::compress
sion_int32 compress
Definition: sion_filedesc.h:166
SION_FILESTATE_PAROPEN
#define SION_FILESTATE_PAROPEN
Definition: sion_filedesc.h:27
_sion_generic_gendata_struct
Definition: sion_generic_apidesc.h:59
_sion_filedesc_struct::currentblocknr
sion_int32 currentblocknr
Definition: sion_filedesc.h:96
_sion_vcdtype
int _sion_vcdtype(int sid)
Definition: sion_fd.c:57
_sion_filedesc_struct::maxusedchunks
sion_int32 maxusedchunks
Definition: sion_filedesc.h:129
sion_filedesc.h
_sion_filedesc_struct::fileptr
_sion_fileptr * fileptr
Definition: sion_filedesc.h:81
sion_internal.h
sion_buffer.h
_sion_file_set_position
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
Definition: sion_file.c:292
sion_generic_internal.h
_sion_filedesc_struct::collsize
sion_int32 collsize
Definition: sion_filedesc.h:181
_sion_filedesc_struct::all_startpointers
sion_int64 * all_startpointers
Definition: sion_filedesc.h:146
_sion_filedesc_struct::blocksizes
sion_int64 * blocksizes
Definition: sion_filedesc.h:99
_sion_filedesc_struct::sid
sion_int32 sid
Definition: sion_filedesc.h:85
_sion_filedesc_struct::mode
sion_int32 mode
Definition: sion_filedesc.h:108
MAXCHUNKS
#define MAXCHUNKS
Definition: sion_common.h:34
_sion_filedesc_struct::all_coll_collsize
sion_int32 * all_coll_collsize
Definition: sion_filedesc.h:150
SION_FILE_FLAG_SIONFWD
#define SION_FILE_FLAG_SIONFWD
Definition: sion_file.h:27
_sion_filedesc_struct::rank
sion_int32 rank
Definition: sion_filedesc.h:94
_sion_buffer_flush
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
Definition: sion_buffer.c:177
_sion_free_filedesc_arrays
int _sion_free_filedesc_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
Definition: sion_filedesc.c:429
_sion_getenv
char * _sion_getenv(const char *name)
Definition: sion_internal.c:1169
_sion_flush_block
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
Definition: sion_internal.c:1032
SION_FILEMODE_WRITE
#define SION_FILEMODE_WRITE
Definition: sion_filedesc.h:37
_sion_free_filedesc_coll_arrays
int _sion_free_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
Definition: sion_filedesc.c:494
_sion_filedesc_struct::chunksize_req
sion_int64 chunksize_req
Definition: sion_filedesc.h:122
_sion_alloc_filedesc_coll_arrays
int _sion_alloc_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
Definition: sion_filedesc.c:447
_sion_print_filedesc
int _sion_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
Print the initialized sion file description.
Definition: sion_filedesc.c:656
_sion_filedesc_struct::flag2
sion_int64 flag2
Definition: sion_filedesc.h:120
sion_cache.h
_sion_filedesc_struct::fsblksize
sion_int32 fsblksize
Definition: sion_filedesc.h:117
_sion_read_header_var_part
int _sion_read_header_var_part(_sion_filedesc *sion_filedesc)
Read the second part of SION Meta Block 1.
Definition: sion_metadata.c:502
sion_fd.h
_sion_alloc_filedesc_arrays
int _sion_alloc_filedesc_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
Definition: sion_filedesc.c:336
_sion_filedesc_struct::all_globalranks
sion_int64 * all_globalranks
Definition: sion_filedesc.h:144
_sion_filedesc_struct::prefix
char * prefix
Definition: sion_filedesc.h:162
sion.h
sion_debug.h
_sion_vcdtovcon
void * _sion_vcdtovcon(int sid)
Definition: sion_fd.c:52
_sion_file_purge
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
Definition: sion_file.c:371
DFUNCTION
#define DFUNCTION
collect mapping information on rank 0 of first file, mapping=NULL for all others
Definition: sion_generic_internal.c:1013
_sion_filedesc_struct::globalskip
sion_int64 globalskip
Definition: sion_filedesc.h:123
_sion_filedesc_struct::fileptr_exported
sion_int32 fileptr_exported
Definition: sion_filedesc.h:186
_sion_write_header_var_part_blockcount_from_field
int _sion_write_header_var_part_blockcount_from_field(_sion_filedesc *sion_filedesc, int field_size, sion_int64 *field)
Write the block sizes from Meta Block 2.
Definition: sion_metadata.c:875
_sion_filedesc_struct
Sion File Descriptor Structure.
Definition: sion_filedesc.h:78
sion_internal_startptr.h
_sion_filedesc_struct::currentpos
sion_int64 currentpos
Definition: sion_filedesc.h:95
_sion_filedesc_struct::all_chunksizes
sion_int64 * all_chunksizes
Definition: sion_filedesc.h:143
_sion_filedesc_struct::hinttype
sion_int32 hinttype
Definition: sion_filedesc.h:198
_sion_filedesc_struct::keyvalmode
sion_int32 keyvalmode
Definition: sion_filedesc.h:169
SION_FILEDESCRIPTOR
#define SION_FILEDESCRIPTOR
Definition: sion_fd.h:16
_sion_filedesc_struct::flag1
sion_int64 flag1
Definition: sion_filedesc.h:119
_sion_file_get_opt_blksize
long _sion_file_get_opt_blksize(_sion_fileptr *sion_fileptr)
Get optional file system block size for a file.
Definition: sion_file.c:229
_sion_file_get_position
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
Definition: sion_file.c:319
_sion_filedesc_struct::maxchunks
sion_int32 maxchunks
Definition: sion_filedesc.h:118
sion_generic_collective.h
_sion_write_header_var_part_nextblocksizes_from_field
int _sion_write_header_var_part_nextblocksizes_from_field(_sion_filedesc *sion_filedesc, int field_size, sion_int64 *field)
Write the next set of blocksizes from Meta Block 2 Assuming that filepointer is at the correct positi...
Definition: sion_metadata.c:915
_sion_read_header_fix_part
int _sion_read_header_fix_part(_sion_filedesc *sion_filedesc)
Read part of the SION Meta Block 1.
Definition: sion_metadata.c:316
_sion_filedesc_struct::fname
char * fname
Definition: sion_filedesc.h:104
_sion_buffer_check_env
int _sion_buffer_check_env(_sion_filedesc *sion_filedesc)
Checks if environment variables are set to use buffer.
Definition: sion_buffer.c:60
_sion_file_open
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
Definition: sion_file.c:45
_sion_filedesc_struct::ntasks
sion_int32 ntasks
Definition: sion_filedesc.h:106
_sion_generic_buddy_struct
Definition: sion_buddy_common.h:40
_sion_filedesc_struct::globalrank
sion_int32 globalrank
Definition: sion_filedesc.h:105
SION_FILE_FLAG_CREATE
#define SION_FILE_FLAG_CREATE
Definition: sion_file.h:24
_sion_filedesc_struct::start_of_varheader
sion_int64 start_of_varheader
Definition: sion_filedesc.h:125
_sion_filedesc_struct::collmsa
sion_int32 collmsa
Definition: sion_filedesc.h:188
_sion_init_filedesc
int _sion_init_filedesc(_sion_filedesc *sion_filedesc)
Initialize the sion file description.
Definition: sion_filedesc.c:37
_sion_file_flush
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
Definition: sion_file.c:345
sion_file.h
sion_metadata.h
SION_FILESTATE_CLOSE
#define SION_FILESTATE_CLOSE
Definition: sion_filedesc.h:34
_sion_filedesc_struct::fileversion
sion_int32 fileversion
Definition: sion_filedesc.h:116
_sion_flags_entry_struct
Definition: sion_flags.h:30
_sion_filedesc_struct::swapbytes
sion_int32 swapbytes
Definition: sion_filedesc.h:113
_sion_filedesc_struct::dataptr
void * dataptr
Definition: sion_filedesc.h:82
_sion_filedesc_struct::nfiles
sion_int32 nfiles
Definition: sion_filedesc.h:127
SION_FILE_FLAG_POSIX
#define SION_FILE_FLAG_POSIX
Definition: sion_file.h:23
_sion_parreinit_generic
int _sion_parreinit_generic(int sid, sion_int64 chunksize, int rank, int ntasks, _sion_generic_gendata *sion_gendata)
change chunksize for an already opened SION file (write)
Definition: sion_generic_internal.c:877
_sion_get_endianness_with_flags
sion_int32 _sion_get_endianness_with_flags(sion_int64 flags)
Return endianness including possible choice via flags.
Definition: sion_internal.c:1140
_sion_read_header_var_part_blockcount_to_field
int _sion_read_header_var_part_blockcount_to_field(_sion_filedesc *sion_filedesc, int field_size, sion_int64 *field)
Read the block sizes from Meta Block 2.
Definition: sion_metadata.c:565
_sion_generic_apidesc_struct
Definition: sion_generic_apidesc.h:24
_sion_parclose_generic
int _sion_parclose_generic(int sid, int rank, int ntasks, int mapping_size, sion_int32 *mapping, int flag, _sion_generic_gendata *sion_gendata, _sion_generic_buddy *buddy_data)
Internal function to close parallel opened SION file.
Definition: sion_generic_internal.c:701
_sion_filedesc_struct::state
sion_int32 state
Definition: sion_filedesc.h:107
_sion_filedesc_struct::collmergemode
sion_int32 collmergemode
Definition: sion_filedesc.h:187
_sion_flags_store_struct
Definition: sion_flags.h:23
_sion_paropen_generic_one_file
int _sion_paropen_generic_one_file(int sid, char *fname, _sion_flags_store *flags_store, char *prefix, int *numFiles, int *filenumber, sion_int64 *chunksize, sion_int32 *fsblksize, int rank, int ntasks, int *globalrank, int flag, FILE **fileptr, _sion_generic_gendata *sion_gendata, _sion_generic_buddy *buddy_data)
Generic parallel open of one direct access file.
Definition: sion_generic_internal.c:72
_sion_write_header_var_part_mapping
int _sion_write_header_var_part_mapping(_sion_filedesc *sion_filedesc, sion_int32 mapping_size, sion_int32 *mapping)
Write mapping into the SION Meta Block 2.
Definition: sion_metadata.c:263
_sion_filedesc_struct::coll_capability
sion_int32 coll_capability
Definition: sion_filedesc.h:183
_sion_filedesc_struct::buddylevel
sion_int32 buddylevel
Definition: sion_filedesc.h:192
_sion_alloc_filedesc
_sion_filedesc * _sion_alloc_filedesc(void)
Allocates memory for internal sion structure.
Definition: sion_filedesc.c:168
_sion_filedesc_struct::collector
sion_int32 collector
Definition: sion_filedesc.h:182
_sion_filedesc_struct::end_of_header
sion_int64 end_of_header
Definition: sion_filedesc.h:124
_sion_filedesc_struct::chunksize
sion_int64 chunksize
Definition: sion_filedesc.h:121
_sion_filedesc_struct::start_of_data
sion_int64 start_of_data
Definition: sion_filedesc.h:126
SION_FILE_FLAG_WRITE
#define SION_FILE_FLAG_WRITE
Definition: sion_file.h:25
sion_flags.h
_sion_filedesc_struct::startpos
sion_int64 startpos
Definition: sion_filedesc.h:101
_sion_reassignvcd
int _sion_reassignvcd(int sid, void *data, int type)
Definition: sion_fd.c:62
SION_FILE_FLAG_READ
#define SION_FILE_FLAG_READ
Definition: sion_file.h:26
SION_FILEMODE_READ
#define SION_FILEMODE_READ
Definition: sion_filedesc.h:36
_sion_filedesc_struct::endianness
sion_int32 endianness
Definition: sion_filedesc.h:109
sion_printts.h
Sion Time Stamp Header.
sion_keyvalue.h
_sion_fileptr_s
Definition: sion_file.h:29
_sion_realloc_filedesc_blocklist
int _sion_realloc_filedesc_blocklist(_sion_filedesc *sion_filedesc, sion_int32 maxchunks)
Increase the memory used by the internal sion structure for the blocklist.
Definition: sion_filedesc.c:191
_sion_filedesc_struct::lastchunknr
sion_int32 lastchunknr
Definition: sion_filedesc.h:100
_sion_filedesc_struct::all_coll_capability
sion_int32 * all_coll_capability
Definition: sion_filedesc.h:151