15 #define _XOPEN_SOURCE 700 24 #include "sion_error_handler.h" 41 #define _SION_CONST_MAX_INT32 2147483647 69 sion_int64 file_mode_flags,
74 sion_int64 **chunksizes,
75 int **mapping_filenrs,
77 sion_int32 *fsblksize,
84 int filenr, root, task;
88 sion_int64 helpint64, apiflag, new_fsblocksize, lstartpointer;
90 sion_int32 *sion_count = NULL;
92 sion_int64 *sion_tmpintfield2 = NULL;
93 sion_int64 *sion_tmpintfield3 = NULL;
96 int *lfilecounter,*lfilemanager, ltask, tmpsize, blknum;
101 DPRINTFP((2,
"_sion_paropen_mapped_generic", rank,
"enter parallel open sid=%d\n", sid));
104 if (sion_filedesc_master == NULL) {
105 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate filedescriptor structure of size %lu (sion_filedesc_master), aborting ...\n",
106 (
unsigned long)
sizeof(sion_filedesc_master)));
110 sion_filedesc_master->
fname = strdup(fname);
114 if (file_mode_flags&_SION_FMODE_WRITE) {
117 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" starting open for write #tasks=%d\n", ntasks));
120 for(ltask=0;ltask<*nlocaltasks;ltask++) {
121 DPRINTFP((128,
"_sion_paropen_mapped_generic", rank,
"input: %2d: f=%d gtask=%2d ltask=%d --> %d\n", ltask,
122 (
int) (*mapping_filenrs)[ltask],
123 (
int) (*globalranks)[ltask],
124 (
int) (*mapping_lranks)[ltask],
125 (
int) (*chunksizes)[ltask]
133 sion_filedesc_master->
sid=sid;
134 sion_filedesc_master->
nfiles=*numFiles;
137 if (sion_filedesc_master->
multifiles == NULL) {
138 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (chunksizes), aborting ...\n",
148 lfilecounter = (
int *) malloc(*numFiles *
sizeof(
int));
149 if (lfilecounter == NULL) {
150 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilecounter), aborting ...\n",
151 (
unsigned long) *numFiles *
sizeof(int)));
153 lfilemanager = (
int *) malloc(*numFiles *
sizeof(
int));
154 if (lfilemanager == NULL) {
156 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilemanager), aborting ...\n",
157 (
unsigned long) *numFiles *
sizeof(
int)));
160 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
161 if (sion_count == NULL) {
164 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_count), aborting ...\n",
165 (
unsigned long) ntasks *
sizeof(sion_int32)));
170 for(filenr=0;filenr<*numFiles;filenr++) lfilecounter[filenr]=lfilemanager[filenr]=0;
171 for(ltask=0;ltask<*nlocaltasks;ltask++) {
172 filenr=(*mapping_filenrs)[ltask];
173 if((filenr<0) || (filenr>=*numFiles)){
177 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: on task %d: wrong file number index (%d) in mapping for task %d, aborting ...\n",
180 lfilecounter[filenr]++;
181 if((*mapping_lranks)[ltask]==0) {
182 lfilemanager[filenr]=1;
189 _sion_keyval_check_env(sion_filedesc_master, file_mode_flags);
192 for(filenr=0;filenr<*numFiles;filenr++) {
194 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" starting init of SION #%d of %d (%d local tasks) \n", filenr,*numFiles,lfilecounter[filenr]));
198 helpint32 = lfilemanager[filenr];
199 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
201 for(task=0;task<ntasks;task++) {
202 if(sion_count[task]==1) root=task;
206 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64,1 , 0); root=helpint64;
208 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: on task %d: local rank 0 of file number index (%d) will not used by any tasks, aborting ...\n",
212 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" file #%d will be managed by task %d \n", filenr,root));
216 if (sion_filedesc_sub == NULL) {
217 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n",
218 (
unsigned long)
sizeof(sion_filedesc_sub)));
220 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
224 sion_filedesc_sub->
fname = (sion_gendata->apidesc->get_multi_filename_cb?sion_gendata->apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname, filenr);
233 sion_filedesc_sub->
fsblksize = *fsblksize;
235 sion_filedesc_sub->
nfiles = *numFiles;
237 sion_filedesc_sub->
prefix = strdup(prefix);
238 sion_filedesc_sub->
compress = file_mode_flags&_SION_FMODE_COMPRESS;
239 sion_filedesc_sub->
usecoll = file_mode_flags&_SION_FMODE_COLLECTIVE;
243 _sion_keyval_check_env(sion_filedesc_sub, file_mode_flags);
256 helpint32 = lfilecounter[filenr];
258 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, root);
261 for(task=0;task<ntasks;task++) helpint64 += sion_count[task];
263 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, root);
266 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
"mapping size increased to %d\n",sion_filedesc_master->
mapping_size));
270 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" file #%d (%s) will store chunks from %d tasks (%d local) \n",
271 filenr,sion_filedesc_sub->
fname,
276 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" create file #%d (%s) \n", filenr,sion_filedesc_sub->
fname));
279 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
284 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
285 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" found new_fsblksize of %d\n", (
int) new_fsblocksize));
292 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
294 sion_gendata->apidesc->bcastr_cb(&new_fsblocksize, sion_gendata->comm_data_global, _SION_INT64, 1, root);
295 sion_filedesc_sub->
fsblksize = new_fsblocksize;
296 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" setting fsblksize to %d\n", (
int) new_fsblocksize));
303 sion_tmpintfield2 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
304 if (sion_tmpintfield2 == NULL) {
305 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield2), aborting ...\n",
306 (
unsigned long) tmpsize *
sizeof(sion_int64)));
310 sion_tmpintfield3 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
311 if (sion_tmpintfield3 == NULL) {
312 free(sion_tmpintfield2);
313 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield3), aborting ...\n",
314 (
unsigned long) tmpsize *
sizeof(sion_int64)));
316 }
else sion_tmpintfield3 = NULL;
320 for(ltask=0;ltask<*nlocaltasks;ltask++) {
321 lfilenr=(int) (*mapping_filenrs)[ltask];
322 if(lfilenr==filenr) {
323 sion_tmpintfield2[p*3+0]=(sion_int64) (*mapping_lranks)[ltask];
324 sion_tmpintfield2[p*3+1]=(sion_int64) (*globalranks)[ltask];
325 sion_tmpintfield2[p*3+2]=(sion_int64) (*chunksizes)[ltask];
326 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" prepare %d --> lrank=%d %d %d\n", p,(
int) sion_tmpintfield2[p*3+0],(
int) sion_tmpintfield2[p*3+1],(
int) sion_tmpintfield2[p*3+2]));
335 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]*=3;
336 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield2, sion_tmpintfield3, sion_gendata->comm_data_global, _SION_INT64,sion_count,3*sion_filedesc_sub->
nlocaltasksinfile, root);
337 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]/=3;
354 lrank=(int) sion_tmpintfield3[ltask*3+0];
355 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" sort in ltask=%d --> lrank=%d\n", ltask,lrank));
356 sion_filedesc_sub->
all_globalranks[lrank]=sion_tmpintfield3[ltask*3+1];
357 sion_filedesc_sub->
all_chunksizes[lrank] =sion_tmpintfield3[ltask*3+2];
361 _sion_calculate_startpointers(sion_filedesc_sub);
366 DPRINTFTS(rank,
"before open");
369 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for reading, aborting ...\n", fname));
371 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
372 DPRINTFTS(rank,
"after open");
375 sion_filedesc_sub->
fileptr = sion_fileptr;
377 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store for file %s fileprt=%x\n",sion_filedesc_sub->
fname, sion_fileptr ));
382 DPRINTFTS(rank,
"before writeh");
385 DPRINTFTS(rank,
"after writeh");
394 DPRINTFTS(rank,
"before setp(0)");
397 DPRINTFTS(rank,
"after setp(0)");
400 _sion_free_filedesc_all_globalranks(sion_filedesc_sub);
404 _sion_alloc_filedesc_all_globalranks(sion_filedesc_sub);
405 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
413 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
418 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc_sub);
423 sion_filedesc_sub->
all_localranks[ltask] = sion_tmpintfield2[ltask*3+0];
424 sion_filedesc_sub->
all_globalranks[ltask] = sion_tmpintfield2[ltask*3+1];
432 lrank=(int) sion_tmpintfield3[ltask*3+0];
434 sion_tmpintfield3[ltask*3+2]=sion_filedesc_sub->
all_chunksizes[lrank];
435 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" sort out ltask=%d --> lrank=%d startptr=%ld chunksize=%ld\n",
436 ltask,lrank,(
long) sion_tmpintfield3[ltask*3+1],sion_tmpintfield3[ltask*3+2]));
439 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]*=3;
440 sion_gendata->apidesc->scattervr_cb(sion_tmpintfield2, sion_tmpintfield3, sion_gendata->comm_data_global, _SION_INT64,sion_count,3*sion_filedesc_sub->
nlocaltasksinfile, root);
441 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]/=3;
445 _sion_free_filedesc_all_startpointers(sion_filedesc_sub);
446 _sion_free_filedesc_all_chunksizes(sion_filedesc_sub);
448 _sion_alloc_filedesc_all_startpointers(sion_filedesc_sub);
449 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
454 sion_filedesc_sub->
all_chunksizes[ltask] = sion_tmpintfield2[ltask*3+2];
455 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" get startpointer[%d] --> %ld\n", ltask, sion_filedesc_sub->
all_startpointers[ltask]));
459 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
globalskip, sion_gendata->comm_data_global, _SION_INT64, 1, root);
463 DPRINTFTS(rank,
"before setp");
464 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
467 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" allocating block arrays of size %d\n", sion_filedesc_sub->
ntasks));
472 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" set all_currentpos[%d]=%d\n",ltask,sion_filedesc_sub->
all_currentpos[ltask] ));
478 sion_filedesc_sub->
rank = 0;
489 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
491 if(sion_tmpintfield2) free(sion_tmpintfield2);
492 if(sion_tmpintfield3) free(sion_tmpintfield3);
494 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" ending init of SION #%d of %d \n", filenr,*numFiles));
503 {
int lfile=-1, lrank=-1, blknum;
504 sion_filedesc_sub=NULL;
505 for(filenr=0;filenr<*numFiles;filenr++) {
506 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
516 if((sion_filedesc_sub) && (lrank>=0) && (lfile>=0)) {
521 sion_filedesc_master->
rank = lrank;
538 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
548 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"set startpointer to %d\n",(
int) sion_filedesc_master->
currentpos));
553 *fileptr=sion_filedesc_master->
fileptr->fileptr;
565 if(sion_count) free(sion_count);
567 if(lfilecounter) free(lfilecounter);
568 if(lfilemanager) free(lfilemanager);
572 }
else if (file_mode_flags&_SION_FMODE_READ) {
575 int mapping_size,mapsid=-1, rootcounter;
577 sion_int32 lfsblksize;
581 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"read mode ntasks=%d\n",ntasks));
583 for(ltask=0;ltask<*nlocaltasks;ltask++) {
584 DPRINTFP((128,
"_sion_paropen_mapped_generic", rank,
"input: %2d: gtask=%2d \n", ltask, (
int) (*globalranks)[ltask]));
590 sion_filedesc_master->
sid=sid;
593 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
594 if (sion_count == NULL) {
595 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_count), aborting ...\n",
596 (
unsigned long) ntasks *
sizeof(sion_int32)));
604 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"before open\n"));
605 mapsid=
_sion_open_read(fname,_SION_FMODE_READ|_SION_FMODE_ANSI,_SION_READ_MASTER_ONLY_OF_MULTI_FILES,
606 &lntasks,&lnfiles,NULL,&lfsblksize,NULL,&lfileptr);
608 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"after open\n"));
610 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"sion file %d files #tasks=%d rc=%d\n", *numFiles,mapping_size,rc));
613 lfilemanager = (
int *) malloc(*numFiles *
sizeof(
int));
614 if (lfilemanager == NULL) {
615 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilemanager), aborting ...\n",
616 (
unsigned long) *numFiles *
sizeof(
int)));
623 for(task=0;task<mapping_size;task++) {
624 if(mapping[task*2+1]==0) {
625 lfilemanager[mapping[task*2+0]]=task;
626 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" manager of file %d is grank=%d\n",mapping[task*2+0],task));
640 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot find file %s , aborting ...\n",fname));
645 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_master->
mapping_size, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
646 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" mapping_size is=%d\n",sion_filedesc_master->
mapping_size));
650 if (mapsid>=0) _sion_close_sid(mapsid);
657 int tasks_per_task = sion_filedesc_master->
mapping_size / ntasks;
658 int startpos = rank*tasks_per_task;
659 int endpos = (rank+1)*tasks_per_task;
662 if(endpos<sion_filedesc_master->mapping_size) endpos=sion_filedesc_master->
mapping_size;
664 *nlocaltasks=endpos-startpos;
665 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"pre-compute distribution: startpos=%d endpos=%d nlocaltasks=%d\n",startpos, endpos, (
int) *nlocaltasks ));
667 if (globalranks == NULL) {
669 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate globalranks, not pointer parameter given, aborting ...\n"));
671 if (mapping_filenrs == NULL) {
673 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_filenrs, not pointer parameter given, aborting ...\n"));
675 if (mapping_lranks == NULL) {
677 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_lranks, not pointer parameter given, aborting ...\n"));
679 if ((*globalranks) != NULL) {
681 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate globalranks, memory allready allocated (unknown size), aborting ...\n"));
683 if ((*mapping_filenrs) != NULL) {
685 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_filenrs, memory allready allocated (unknown size), aborting ...\n"));
687 if ((*mapping_lranks) != NULL) {
689 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_lranks, memory allready allocated (unknown size), aborting ...\n"));
693 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate globalranks field for parameter size=%d\n",(
int) *nlocaltasks ));
694 *globalranks = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
695 if (*globalranks == NULL) {
697 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate memory of size %lu (globalranks), aborting ...\n", (
unsigned long)
sizeof(sion_int32)));
701 for(task=startpos;task<endpos;task++) {
702 (*globalranks)[ltask]=task;
703 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"set *globalranks[%d]=%d\n",(
int) ltask,(*globalranks)[ltask]));
710 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_master->
keyvalmode, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
711 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" keyvalmode is=%d\n",sion_filedesc_master->
keyvalmode));
714 _sion_keyval_check_env(sion_filedesc_master, file_mode_flags);
717 if (rank == 0) helpint64=*numFiles;
718 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0); *numFiles=helpint64;
719 sion_filedesc_master->
nfiles=*numFiles;
723 if (sion_filedesc_master->
multifiles == NULL) {
724 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (chunksizes), aborting ...\n",
730 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
732 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" starting init of SION #%d of %d\n", filenr,*numFiles));
734 #ifdef _SION_FIND_ROOT_LRANK_NULL_DO_NOT_USE 741 helpint64=lfilemanager[filenr];
743 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0);
748 for(task=0;task<*nlocaltasks;task++) {
749 if((*globalranks)[task]==grankroot) helpint32=1;
753 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
755 for(task=0;task<ntasks;task++) {
756 if(sion_count[task]==1) {
767 rootcounter=( (rootcounter+1) % ntasks);
768 helpint64=rootcounter;
771 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0);
773 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" manager of file %d is rank=%d\n",filenr,root));
777 if (sion_filedesc_sub == NULL) {
778 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n",
779 (
unsigned long)
sizeof(sion_filedesc_sub)));
781 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
783 sion_filedesc_sub->
fname = (sion_gendata->apidesc->get_multi_filename_cb?sion_gendata->apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname, filenr);
792 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" starting open for read on file %s\n", sion_filedesc_sub->
fname));
793 DPRINTFTS(rank,
"before open");
794 sion_filedesc_sub->
fileptr=NULL;
798 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot open %s for reading, aborting ...\n", fname));
800 sion_filedesc_sub->
fileptr = sion_fileptr;
802 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
803 DPRINTFTS(rank,
"after open root");
808 if (rc!=SION_SUCCESS) {
809 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot read header from file %s, aborting ...\n", fname));
811 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
812 " read, after read of fix header part endianness=0x%x blksize=%d ntasks=%d\n", sion_filedesc_sub->
endianness, sion_filedesc_sub->
fsblksize, sion_filedesc_sub->
ntasks));
814 DPRINTFTS(rank,
"before alloc");
817 DPRINTFTS(rank,
"after alloc");
820 if (rc != SION_SUCCESS) {
821 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot read header from file %s, aborting ...\n", fname));
824 _sion_coll_check_env(sion_filedesc_sub);
828 if (!sion_filedesc_sub->
usecoll) _sion_calculate_startpointers(sion_filedesc_sub);
829 else _sion_calculate_startpointers_collective(sion_filedesc_sub);
830 DPRINTFTS(rank,
"after calculate");
833 _sion_keyval_check_env(sion_filedesc_sub, file_mode_flags);
838 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
globalskip, sion_gendata->comm_data_global, _SION_INT64, 1, root);
841 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
endianness, sion_gendata->comm_data_global, _SION_INT32, 1, root);
842 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
swapbytes, sion_gendata->comm_data_global, _SION_INT32, 1, root);
843 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
fsblksize, sion_gendata->comm_data_global, _SION_INT32, 1, root);
844 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
ntasks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
847 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
fileversion, sion_gendata->comm_data_global, _SION_INT32, 1, root);
848 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
nfiles, sion_gendata->comm_data_global, _SION_INT32, 1, root);
849 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
filenumber, sion_gendata->comm_data_global, _SION_INT32, 1, root);
850 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
flag1, sion_gendata->comm_data_global, _SION_INT64, 1, root);
851 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
flag2, sion_gendata->comm_data_global, _SION_INT64, 1, root);
852 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
maxusedchunks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
853 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
start_of_varheader, sion_gendata->comm_data_global, _SION_INT64, 1, root);
854 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
857 DPRINTFTS(rank,
"after bcast");
864 sion_tmpintfield2 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
865 if (sion_tmpintfield2 == NULL) {
866 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield2), aborting ...\n",
867 (
unsigned long) tmpsize *
sizeof(sion_int64)));
872 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
877 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" scan for gtask=%d\n", (
int) sion_tmpintfield2[task]));
878 for(ltask=0;ltask<*nlocaltasks;ltask++) {
879 if( (
int) sion_tmpintfield2[task]==(*globalranks)[ltask]) {
880 sion_tmpintfield2[task]=-1 * (sion_tmpintfield2[task] + 1);
885 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" found %d globalranks for file %s\n", sion_filedesc_sub->
nlocaltasksinfile, sion_filedesc_sub->
fname));
887 DPRINTFTS(rank,
"before open non-root");
892 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot open %s for reading, aborting ...\n", fname));
894 sion_filedesc_sub->
fileptr = sion_fileptr;
897 DPRINTFTS(rank,
"after open non-root");
903 _sion_free_filedesc_all_globalranks(sion_filedesc_sub);
906 _sion_alloc_filedesc_all_globalranks(sion_filedesc_sub);
907 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
912 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
918 if(sion_tmpintfield2[task]<0) {
920 sion_filedesc_sub->
all_globalranks[ltask]= (-1 * sion_tmpintfield2[task]) - 1;
921 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" all_globalranks[%d]=%d all_localranks[%d]=%d\n",
931 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
933 _sion_free_filedesc_all_chunksizes(sion_filedesc_sub);
934 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
946 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
948 _sion_free_filedesc_all_startpointers(sion_filedesc_sub);
949 _sion_alloc_filedesc_all_startpointers(sion_filedesc_sub);
966 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" got from file blockcount[%d]=%d\n",task,(
int) sion_tmpintfield2[task]));
968 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
973 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store blockcount task=%d -> ltask=%d cnt=%d\n",task,ltask,(
int) sion_tmpintfield2[task]));
978 for (blknum = 0; blknum < sion_filedesc_sub->
maxusedchunks; blknum++) {
984 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
993 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
keyvalmode, sion_gendata->comm_data_global, _SION_INT32, 1, root);
996 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
usecoll, sion_gendata->comm_data_global, _SION_INT32, 1, root);
997 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
collsize, sion_gendata->comm_data_global, _SION_INT32, 1, root);
999 if(sion_filedesc_sub->
usecoll) {
1003 sion_tmpintfield2[task]= (sion_int64) (sion_filedesc_sub->
all_coll_collector[task]*_SION_CONST_MAX_INT32) + sion_filedesc_sub->
collsize;
1005 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
1009 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
1012 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store collsize+collector for %d elements\n",sion_filedesc_sub->
nlocaltasksinfile));
1027 sion_filedesc_sub->
rank = 0;
1037 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc_sub);
1044 if(sion_tmpintfield2) free(sion_tmpintfield2);
1052 int lfile=-1,lrank=-1, blknum;
1053 sion_filedesc_sub=NULL;
1054 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1055 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1063 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"init to first local rank in first file (%d, %d)\n",lfile,lrank));
1065 if((sion_filedesc_sub) && (lrank>=0) && (lfile>=0)) {
1066 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"sion_filedesc_master->mapping_size=%d\n",sion_filedesc_master->
mapping_size));
1075 sion_filedesc_master->
rank = lrank;
1093 for(filenr=0;filenr<sion_filedesc_sub->
nfiles;filenr++) {
1098 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
1109 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"set startpointer to %d\n",(
int) sion_filedesc_master->
currentpos));
1118 *fileptr=sion_filedesc_master->
fileptr->fileptr;
1127 sion_int64 *helpptr_chunksize = NULL;
1128 sion_int32 *helpptr_mapping_filenrs = NULL;
1129 sion_int32 *helpptr_mapping_lranks = NULL;
1132 if (chunksizes != NULL) {
1133 if ((*chunksizes) == NULL) {
1134 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate chunksizes field for parameter size=%d\n",(
int) *nlocaltasks ));
1135 helpptr_chunksize = (sion_int64 *) malloc(*nlocaltasks *
sizeof(sion_int64));
1136 if (helpptr_chunksize == NULL) {
1137 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
1139 *chunksizes = helpptr_chunksize;
1141 helpptr_chunksize = *chunksizes;
1145 if (mapping_filenrs != NULL) {
1146 if ((*mapping_filenrs) == NULL) {
1147 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate mapping_filenrs field for parameter size=%d\n",(
int) *nlocaltasks ));
1148 helpptr_mapping_filenrs = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
1149 if (helpptr_mapping_filenrs == NULL) {
1150 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (mapping_filenrs), aborting ...\n", (
unsigned long)
sizeof(sion_int32)));
1152 *mapping_filenrs = helpptr_mapping_filenrs;
1154 helpptr_mapping_filenrs = *mapping_filenrs;
1158 if (mapping_lranks != NULL) {
1159 if ((*mapping_lranks) == NULL) {
1160 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate mapping_lranks field for parameter size=%d\n",(
int) *nlocaltasks ));
1161 helpptr_mapping_lranks = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
1162 if (helpptr_mapping_lranks == NULL) {
1163 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (mapping_lranks), aborting ...\n", (
unsigned long)
sizeof(sion_int32)));
1165 *mapping_lranks = helpptr_mapping_lranks;
1167 helpptr_mapping_lranks = *mapping_lranks;
1172 if(helpptr_chunksize || helpptr_mapping_filenrs || helpptr_mapping_lranks) {
1173 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1174 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1176 for(task=0;task<*nlocaltasks;task++) {
1178 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
" set chunksizes[%d]=%4d (filenr=%d, ltask=%d lrank=%d)\n",
1180 if(helpptr_chunksize) helpptr_chunksize[task] = sion_filedesc_sub->
all_chunksizes[ltask];
1181 if(helpptr_mapping_filenrs) helpptr_mapping_filenrs[task] = filenr;
1182 if(helpptr_mapping_lranks) helpptr_mapping_lranks[task] = sion_filedesc_sub->
all_localranks[ltask];
1191 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_paropen_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1194 if(sion_count) free(sion_count);
1196 if(lfilemanager) free(lfilemanager);
1201 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_multi_mpi: unknown file mode"));
1208 int _sion_parclose_mapped_generic(
int sid,
1212 int rc=SION_SUCCESS;
1213 int lfile, grank, lrank, blknum, filenr, tmpsize, root, ltask, mappingroot, task;
1216 sion_int64 *sion_tmpintfield_send = NULL;
1217 sion_int64 *sion_tmpintfield_lrank_recv = NULL;
1218 sion_int64 *sion_tmpintfield_data_recv = NULL;
1219 sion_int64 *sion_tmpintfield_data = NULL;
1220 sion_int32 *mapping = NULL;
1221 sion_int32 *sion_tmpint32field_send = NULL;
1222 sion_int32 *sion_tmpint32field_data_recv = NULL;
1223 sion_int32 *sion_count = NULL;
1224 sion_int32 helpint32;
1226 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"enter parallel close sid=%d\n", sid));
1229 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: invalid sion_filedesc_master, aborting %d ...\n", sid));
1234 int numbytes, numfds;
1236 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"internal data size of sid %2d (%d bytes, %d fds) \n", sid,numbytes, numfds));
1244 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc_master->
rank,
"sion_parclose_mapped: invalid file open state (!PAROPENMAPPED), aborting %d ...", sid));
1250 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_parclose_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1258 lrank=sion_filedesc_master->
rank;
1259 if((lrank>=0) && (lfile>=0)) {
1260 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
1266 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1267 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1269 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
" parallel close (read mode) call fclose on file %s (fileptr=%x)\n", sion_filedesc_sub->
fname,sion_filedesc_sub->
fileptr));
1271 if(sion_filedesc_sub->
fileptr!=NULL) {
1273 sion_filedesc_sub->
fileptr = NULL;
1279 _sion_free_filedesc(sion_filedesc_sub);
1282 _SION_SAFE_FREE(mapping, NULL);
1283 _SION_SAFE_FREE(sion_filedesc_master->
multifiles, NULL);
1288 _sion_free_filedesc(sion_filedesc_master);
1289 sion_filedesc_master = NULL;
1301 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_parclose_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1305 lrank=sion_filedesc_master->
rank;
1306 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
1318 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
"on file %d: sub,maxchunk=%d master,maxchunk=%d \n", lfile,sion_filedesc_sub->
maxchunks, sion_filedesc_master->
maxchunks));
1324 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
1328 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
1333 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
1334 if (sion_count == NULL) {
1335 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_count), aborting ...\n",
1336 (
unsigned long) ntasks *
sizeof(sion_int32)));
1340 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1342 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1343 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" starting close for file %d: %s \n", filenr,sion_filedesc_sub->
fname));
1350 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
">parallel close (write mode, not managed) call fclose on file %s (fileptr=%x)\n", sion_filedesc_sub->
fname,sion_filedesc_sub->
fileptr));
1352 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
"<parallel close (write mode, not managed) call fclose on file %s (fileptr=%x)\n", sion_filedesc_sub->
fname,sion_filedesc_sub->
fileptr));
1353 sion_filedesc_sub->
fileptr = NULL;
1358 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
1362 sion_tmpintfield_send = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1363 if (sion_tmpintfield_send == NULL) {
1364 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_send), aborting ...\n",
1365 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1367 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: allocate send field for all local tasks of file (%d) --> %x\n", filenr, tmpsize, sion_tmpintfield_send));
1374 sion_tmpintfield_lrank_recv = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1375 if (sion_tmpintfield_lrank_recv == NULL) {
1376 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_lrank_recv), aborting ...\n",
1377 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1379 sion_tmpintfield_data_recv = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1380 if (sion_tmpintfield_data_recv == NULL) {
1381 free(sion_tmpintfield_lrank_recv);
1382 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_data_recv), aborting ...\n",
1383 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1385 sion_tmpintfield_data = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1386 if (sion_tmpintfield_data == NULL) {
1387 free(sion_tmpintfield_data_recv);
1388 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_data), aborting ...\n",
1389 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1391 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: allocate fields for all tasks of file (%d)\n", filenr,tmpsize));
1394 }
else sion_tmpintfield_lrank_recv=sion_tmpintfield_data_recv=sion_tmpintfield_data=NULL;
1398 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1402 sion_tmpintfield_send[ltask]=sion_filedesc_sub->
all_localranks[ltask];
1404 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: before call of gathervr_cb %x %x %x %d %d %d\n",
1405 filenr,sion_tmpintfield_lrank_recv, sion_tmpintfield_send, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
nlocaltasksinfile, root));
1407 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield_send, sion_tmpintfield_lrank_recv, sion_gendata->comm_data_global, _SION_INT64, sion_count, sion_filedesc_sub->
nlocaltasksinfile, root);
1411 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" send all_blockcount[%d]: %d\n", ltask, sion_filedesc_sub->
all_blockcount[ltask]));
1412 sion_tmpintfield_send[ltask]=sion_filedesc_sub->
all_blockcount[ltask];
1414 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield_send, sion_tmpintfield_data_recv, sion_gendata->comm_data_global, _SION_INT64, sion_count, sion_filedesc_sub->
nlocaltasksinfile, root);
1420 if (sion_tmpintfield_data_recv[ltask] > sion_filedesc_sub->
maxusedchunks) {
1421 sion_filedesc_sub->
maxusedchunks = (int) sion_tmpintfield_data_recv[ltask];
1426 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
maxusedchunks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1427 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: maxusedchunks=%d\n", filenr,sion_filedesc_sub->
maxusedchunks));
1433 lrank=(int) sion_tmpintfield_lrank_recv[ltask];
1434 DPRINTFP((64,
"_sion_parclose_mapped_generic", rank,
" sort in ltask=%d --> lrank=%d blkcount=%d\n",
1435 ltask,lrank,sion_tmpintfield_data_recv[ltask]));
1436 sion_tmpintfield_data[lrank]=sion_tmpintfield_data_recv[ltask];
1451 for (blknum = 0; blknum < sion_filedesc_sub->
maxusedchunks; blknum++) {
1453 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
" collect blocksize step %d of %d\n", blknum+1,sion_filedesc_sub->
maxusedchunks));
1456 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"sion_filedesc_sub->nlocaltasksinfile=%d\n",sion_filedesc_sub->
nlocaltasksinfile));
1459 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"sort in blksize[%d][%d]=%d\n",blknum, ltask, sion_tmpintfield_send[ltask]));
1461 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield_send, sion_tmpintfield_data_recv, sion_gendata->comm_data_global, _SION_INT64, sion_count, sion_filedesc_sub->
nlocaltasksinfile, root);
1468 lrank=(int) sion_tmpintfield_lrank_recv[ltask];
1469 sion_tmpintfield_data[lrank]=sion_tmpintfield_data_recv[ltask];
1470 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"prepare blksize[%d][%d]=%ld\n",blknum,lrank,sion_tmpintfield_data[lrank]));
1479 if(sion_tmpintfield_lrank_recv) free(sion_tmpintfield_lrank_recv);
1480 if(sion_tmpintfield_data_recv) free(sion_tmpintfield_data_recv);
1481 if(sion_tmpintfield_data) free(sion_tmpintfield_data);
1482 if(sion_tmpintfield_send) free(sion_tmpintfield_send);
1484 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" ending close for file %d: %s \n", filenr,sion_filedesc_sub->
fname));
1490 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"mappingroot=%d rank=%d\n", mappingroot, rank ));
1491 if(rank==mappingroot) {
1492 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"allocate mapping of size %d\n",sion_filedesc_master->
mapping_size));
1493 mapping = (sion_int32 *) malloc(sion_filedesc_master->
mapping_size * 2 *
sizeof(sion_int32));
1494 if (mapping == NULL) {
1496 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_ABORT,
"_sion_parclose_generic_mapped: Cannot allocate memory for mapping"));
1501 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1502 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1506 sion_tmpint32field_send = (sion_int32 *) malloc(tmpsize *
sizeof(sion_int32));
1507 if (sion_tmpint32field_send == NULL) {
1509 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic_mapped: cannot allocate temporary memory of size %lu (sion_tmpintfield_send), aborting ...\n",
1510 (
unsigned long) tmpsize *
sizeof(sion_int32)));
1515 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, mappingroot);
1517 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: allocate send field for all local tasks of file (%d) --> %x\n", filenr, tmpsize, sion_tmpint32field_send));
1519 if(rank==mappingroot) {
1522 sion_tmpint32field_data_recv = (sion_int32 *) malloc(tmpsize *
sizeof(sion_int32));
1523 if (sion_tmpint32field_data_recv == NULL) {
1524 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic_mapped: cannot allocate temporary memory of size %lu (sion_tmpintfield_data_recv), aborting ...\n",
1525 (
unsigned long) tmpsize *
sizeof(sion_int32)));
1527 }
else sion_tmpint32field_data_recv=NULL;
1531 sion_tmpint32field_send[ltask*2+0]= (int) sion_filedesc_sub->
all_localranks[ltask];
1532 sion_tmpint32field_send[ltask*2+1]= (
int) sion_filedesc_sub->
all_globalranks[ltask];
1533 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"local lrank[%d]=%d grank[%d]=%d\n",ltask,(
int) sion_filedesc_sub->
all_localranks[ltask],ltask,(
int) sion_filedesc_sub->
all_globalranks[ltask]));
1537 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
" sion_tmpint32field_send: %d -> %d \n",ltask, sion_tmpint32field_send[ltask]));
1540 if (rank == mappingroot)
for(task=0;task<ntasks;task++) sion_count[task]*=2;
1541 sion_gendata->apidesc->gathervr_cb(sion_tmpint32field_send, sion_tmpint32field_data_recv, sion_gendata->comm_data_global, _SION_INT32, sion_count, 2*sion_filedesc_sub->
nlocaltasksinfile, mappingroot);
1542 if (rank == mappingroot)
for(task=0;task<ntasks;task++) sion_count[task]/=2;
1544 if(rank==mappingroot) {
1547 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
" sion_tmpint32field_send: %d -> %d \n",ltask, sion_tmpint32field_data_recv[ltask]));
1550 lrank=(int) sion_tmpint32field_data_recv[ltask*2+0];
1551 grank=(int) sion_tmpint32field_data_recv[ltask*2+1];
1552 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"store mapping[%d]=(%d,%d)\n",grank,filenr,lrank));
1553 mapping[grank*2+0]=filenr;
1554 mapping[grank*2+1]=lrank;
1558 if(sion_tmpint32field_data_recv) free(sion_tmpint32field_data_recv);
1559 if(sion_tmpint32field_send) free(sion_tmpint32field_send);
1563 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1564 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1570 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"mapping size is %d\n",sion_filedesc_master->
mapping_size));
1574 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
" parallel close (write mode, managed) call fclose on file %s (fileptr=%x)\n", sion_filedesc_sub->
fname,sion_filedesc_sub->
fileptr));
1576 sion_filedesc_sub->
fileptr = NULL;
1585 _sion_free_filedesc(sion_filedesc_sub);
1587 if (sion_gendata->apidesc->free_lcg_cb && sion_gendata->comm_data_local) {
1588 sion_gendata->apidesc->free_lcg_cb(sion_gendata->comm_data_local);
1590 _SION_SAFE_FREE(mapping, NULL);
1591 _SION_SAFE_FREE(sion_count, NULL);
1592 _SION_SAFE_FREE(sion_filedesc_master->
multifiles, NULL);
1595 _sion_free_filedesc(sion_filedesc_master);
1596 sion_filedesc_master = NULL;
1600 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"leave parallel close sid=%d\n", sid));
long _sion_file_get_opt_blksize(_sion_fileptr *sion_fileptr)
Get optional file system block size for a file.
sion_int32 filemanagedbytask
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
int _sion_reassignvcd(int sid, void *data, int type)
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
Sion File Descriptor Structure.
sion_int64 * all_blockcount
#define SION_FILE_FLAG_WRITE
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
sion_int64 * all_currentpos
sion_int32 filesionpatchlevel
int _sion_paropen_mapped_generic(int sid, char *fname, sion_int64 file_mode_flags, char *prefix, int *numFiles, int *nlocaltasks, int **globalranks, sion_int64 **chunksizes, int **mapping_filenrs, int **mapping_lranks, sion_int32 *fsblksize, int rank, int ntasks, int flag, FILE **fileptr, _sion_generic_gendata *sion_gendata)
Generic parallel open of one direct access file. Mapping sion files to environment with less tasks.
sion_int64 * all_globalranks
int _sion_alloc_filedesc_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
sion_int64 * all_currentblocknr
#define SION_FILE_FLAG_READ
int _sion_realloc_filedesc_blocklist(_sion_filedesc *sion_filedesc, sion_int32 maxchunks)
Increase the memory used by the internal sion structure for the blocklist.
int _sion_vcdtype(int sid)
sion_int32 * all_coll_collector
sion_int32 fileptr_exported
sion_int32 _sion_get_endianness_with_flags(sion_int64 flags)
Return endianness including possible choice via flags.
#define SION_FILE_FLAG_POSIX
int sion_get_mapping(int sid, int *mapping_size, sion_int32 **mapping, int *numfiles)
Returns pointers to the internal field mapping.
void * _sion_vcdtovcon(int sid)
#define SION_FILE_FLAG_ANSI
#define SION_FILE_FLAG_CREATE
#define SION_FILEMODE_READ
sion_int64 * all_startpointers
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
#define SION_FILESTATE_PAROPENMAPPEDMANAGED
int sion_get_sizeof(int sid, int *numbytes, int *numfds)
Function returns size of internal data structure for sid.
int _sion_free_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
#define SION_FILESTATE_PAROPENMAPPEDMASTER
sion_int32 currentblocknr
int _sion_alloc_filedesc_block_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion structure, fields for all chunksizes of all tasks.
int sion_get_keyval_mode(int sid)
Return selected mode for key value.
char * _sion_get_multi_filename(const char *fname, int filenumber)
generates the multi filename
#define SION_FILEDESCRIPTOR
sion_int64 * all_chunksizes
int _sion_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
Print the initialized sion file description.
#define SION_FILESTATE_CLOSE
sion_int64 * all_localranks
_sion_filedesc * _sion_alloc_filedesc(void)
Allocates memory for internal sion structure.
int _sion_alloc_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int _sion_init_filedesc(_sion_filedesc *sion_filedesc)
Initialize the sion file description.
#define SION_FILEMODE_WRITE
sion_int32 filesionversion
sion_int32 * all_coll_collsize
sion_int64 start_of_varheader
sion_int64 * all_blocksizes
sion_int32 ntotaltasksinfile
sion_int32 nlocaltasksinfile
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
_sion_filedesc ** multifiles
#define SION_FILESTATE_PAROPENMAPPED
int _sion_open_read(const char *fname, sion_int64 file_mode_flags, int read_all, int *ntasks, int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize, int **globalranks, FILE **fileptr)
internal sion serial open function for reading on one or more files