37 #define _SION_CONST_MAX_INT32 2147483647 65 sion_int64 file_mode_flags,
70 sion_int64 **chunksizes,
71 int **mapping_filenrs,
73 sion_int32 *fsblksize,
80 int filenr, root, task;
84 sion_int64 helpint64, apiflag, new_fsblocksize, lstartpointer;
86 sion_int32 *sion_count = NULL;
88 sion_int64 *sion_tmpintfield2 = NULL;
89 sion_int64 *sion_tmpintfield3 = NULL;
92 int *lfilecounter,*lfilemanager, ltask, tmpsize, blknum;
97 DPRINTFP((2,
"_sion_paropen_mapped_generic", rank,
"enter parallel open sid=%d\n", sid));
100 if (sion_filedesc_master == NULL) {
101 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",
102 (
unsigned long)
sizeof(sion_filedesc_master)));
106 sion_filedesc_master->
fname = strdup(fname);
110 if (file_mode_flags&_SION_FMODE_WRITE) {
113 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" starting open for write #tasks=%d\n", ntasks));
116 for(ltask=0;ltask<*nlocaltasks;ltask++) {
117 DPRINTFP((128,
"_sion_paropen_mapped_generic", rank,
"input: %2d: f=%d gtask=%2d ltask=%d --> %d\n", ltask,
118 (
int) (*mapping_filenrs)[ltask],
119 (
int) (*globalranks)[ltask],
120 (
int) (*mapping_lranks)[ltask],
121 (
int) (*chunksizes)[ltask]
129 sion_filedesc_master->
sid=sid;
130 sion_filedesc_master->
nfiles=*numFiles;
133 if (sion_filedesc_master->
multifiles == NULL) {
134 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (chunksizes), aborting ...\n",
144 lfilecounter = (
int *) malloc(*numFiles *
sizeof(
int));
145 if (lfilecounter == NULL) {
146 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilecounter), aborting ...\n",
147 (
unsigned long) *numFiles *
sizeof(int)));
149 lfilemanager = (
int *) malloc(*numFiles *
sizeof(
int));
150 if (lfilemanager == NULL) {
151 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilemanager), aborting ...\n",
152 (
unsigned long) *numFiles *
sizeof(int)));
155 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
156 if (sion_count == NULL) {
157 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",
158 (
unsigned long) ntasks *
sizeof(sion_int32)));
163 for(filenr=0;filenr<*numFiles;filenr++) lfilecounter[filenr]=lfilemanager[filenr]=0;
164 for(ltask=0;ltask<*nlocaltasks;ltask++) {
165 filenr=(*mapping_filenrs)[ltask];
166 if((filenr<0) || (filenr>=*numFiles)){
167 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",
170 lfilecounter[filenr]++;
171 if((*mapping_lranks)[ltask]==0) {
172 lfilemanager[filenr]=1;
179 _sion_keyval_check_env(sion_filedesc_master, file_mode_flags);
182 for(filenr=0;filenr<*numFiles;filenr++) {
184 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" starting init of SION #%d of %d (%d local tasks) \n", filenr,*numFiles,lfilecounter[filenr]));
188 helpint32 = lfilemanager[filenr];
189 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
191 for(task=0;task<ntasks;task++) {
192 if(sion_count[task]==1) root=task;
196 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64,1 , 0); root=helpint64;
198 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",
202 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" file #%d will be managed by task %d \n", filenr,root));
206 if (sion_filedesc_sub == NULL) {
207 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",
208 (
unsigned long)
sizeof(sion_filedesc_sub)));
210 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
214 sion_filedesc_sub->
fname = (sion_gendata->apidesc->get_multi_filename_cb?sion_gendata->apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname, filenr);
223 sion_filedesc_sub->
fsblksize = *fsblksize;
225 sion_filedesc_sub->
nfiles = *numFiles;
227 sion_filedesc_sub->
prefix = strdup(prefix);
228 sion_filedesc_sub->
compress = file_mode_flags&_SION_FMODE_COMPRESS;
229 sion_filedesc_sub->
usecoll = file_mode_flags&_SION_FMODE_COLLECTIVE;
233 _sion_keyval_check_env(sion_filedesc_sub, file_mode_flags);
246 helpint32 = lfilecounter[filenr];
248 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, root);
251 for(task=0;task<ntasks;task++) helpint64 += sion_count[task];
253 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, root);
256 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
"mapping size increased to %d\n",sion_filedesc_master->
mapping_size));
260 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" file #%d (%s) will store chunks from %d tasks (%d local) \n",
261 filenr,sion_filedesc_sub->
fname,
266 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" create file #%d (%s) \n", filenr,sion_filedesc_sub->
fname));
269 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
274 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
275 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" found new_fsblksize of %d\n", (
int) new_fsblocksize));
282 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
284 sion_gendata->apidesc->bcastr_cb(&new_fsblocksize, sion_gendata->comm_data_global, _SION_INT64, 1, root);
285 sion_filedesc_sub->
fsblksize = new_fsblocksize;
286 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" setting fsblksize to %d\n", (
int) new_fsblocksize));
293 sion_tmpintfield2 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
294 if (sion_tmpintfield2 == NULL) {
295 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",
296 (
unsigned long) tmpsize *
sizeof(sion_int64)));
300 sion_tmpintfield3 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
301 if (sion_tmpintfield3 == NULL) {
302 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",
303 (
unsigned long) tmpsize *
sizeof(sion_int64)));
305 }
else sion_tmpintfield3 = NULL;
309 for(ltask=0;ltask<*nlocaltasks;ltask++) {
310 lfilenr=(int) (*mapping_filenrs)[ltask];
311 if(lfilenr==filenr) {
312 sion_tmpintfield2[p*3+0]=(sion_int64) (*mapping_lranks)[ltask];
313 sion_tmpintfield2[p*3+1]=(sion_int64) (*globalranks)[ltask];
314 sion_tmpintfield2[p*3+2]=(sion_int64) (*chunksizes)[ltask];
315 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]));
324 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]*=3;
325 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield2, sion_tmpintfield3, sion_gendata->comm_data_global, _SION_INT64,sion_count,3*sion_filedesc_sub->
nlocaltasksinfile, root);
326 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]/=3;
343 lrank=(int) sion_tmpintfield3[ltask*3+0];
344 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" sort in ltask=%d --> lrank=%d\n", ltask,lrank));
345 sion_filedesc_sub->
all_globalranks[lrank]=sion_tmpintfield3[ltask*3+1];
346 sion_filedesc_sub->
all_chunksizes[lrank] =sion_tmpintfield3[ltask*3+2];
350 _sion_calculate_startpointers(sion_filedesc_sub);
355 DPRINTFTS(rank,
"before open");
358 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for reading, aborting ...\n", fname));
360 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
361 DPRINTFTS(rank,
"after open");
364 sion_filedesc_sub->
fileptr = sion_fileptr;
366 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store for file %s fileprt=%x\n",sion_filedesc_sub->
fname, sion_fileptr ));
371 DPRINTFTS(rank,
"before writeh");
374 DPRINTFTS(rank,
"after writeh");
383 DPRINTFTS(rank,
"before setp(0)");
386 DPRINTFTS(rank,
"after setp(0)");
389 _sion_free_filedesc_all_globalranks(sion_filedesc_sub);
393 _sion_alloc_filedesc_all_globalranks(sion_filedesc_sub);
394 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
402 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
407 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc_sub);
412 sion_filedesc_sub->
all_localranks[ltask] = sion_tmpintfield2[ltask*3+0];
413 sion_filedesc_sub->
all_globalranks[ltask] = sion_tmpintfield2[ltask*3+1];
421 lrank=(int) sion_tmpintfield3[ltask*3+0];
423 sion_tmpintfield3[ltask*3+2]=sion_filedesc_sub->
all_chunksizes[lrank];
424 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" sort out ltask=%d --> lrank=%d startptr=%ld chunksize=%ld\n",
425 ltask,lrank,(
long) sion_tmpintfield3[ltask*3+1],sion_tmpintfield3[ltask*3+2]));
428 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]*=3;
429 sion_gendata->apidesc->scattervr_cb(sion_tmpintfield2, sion_tmpintfield3, sion_gendata->comm_data_global, _SION_INT64,sion_count,3*sion_filedesc_sub->
nlocaltasksinfile, root);
430 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]/=3;
434 _sion_free_filedesc_all_startpointers(sion_filedesc_sub);
435 _sion_free_filedesc_all_chunksizes(sion_filedesc_sub);
437 _sion_alloc_filedesc_all_startpointers(sion_filedesc_sub);
438 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
443 sion_filedesc_sub->
all_chunksizes[ltask] = sion_tmpintfield2[ltask*3+2];
444 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" get startpointer[%d] --> %ld\n", ltask, sion_filedesc_sub->
all_startpointers[ltask]));
448 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
globalskip, sion_gendata->comm_data_global, _SION_INT64, 1, root);
452 DPRINTFTS(rank,
"before setp");
453 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
456 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" allocating block arrays of size %d\n", sion_filedesc_sub->
ntasks));
461 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" set all_currentpos[%d]=%d\n",ltask,sion_filedesc_sub->
all_currentpos[ltask] ));
467 sion_filedesc_sub->
rank = 0;
478 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
480 if(sion_tmpintfield2) free(sion_tmpintfield2);
481 if(sion_tmpintfield3) free(sion_tmpintfield3);
483 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" ending init of SION #%d of %d \n", filenr,*numFiles));
492 {
int lfile=-1, lrank=-1, blknum;
493 sion_filedesc_sub=NULL;
494 for(filenr=0;filenr<*numFiles;filenr++) {
495 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
505 if((sion_filedesc_sub) && (lrank>=0) && (lfile>=0)) {
510 sion_filedesc_master->
rank = lrank;
527 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
537 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"set startpointer to %d\n",(
int) sion_filedesc_master->
currentpos));
542 *fileptr=sion_filedesc_master->
fileptr->fileptr;
554 if(sion_count) free(sion_count);
556 if(lfilecounter) free(lfilecounter);
557 if(lfilemanager) free(lfilemanager);
561 }
else if (file_mode_flags&_SION_FMODE_READ) {
564 int mapping_size,mapsid=-1, rootcounter;
566 sion_int32 lfsblksize;
570 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"read mode ntasks=%d\n",ntasks));
572 for(ltask=0;ltask<*nlocaltasks;ltask++) {
573 DPRINTFP((128,
"_sion_paropen_mapped_generic", rank,
"input: %2d: gtask=%2d \n", ltask, (
int) (*globalranks)[ltask]));
579 sion_filedesc_master->
sid=sid;
582 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
583 if (sion_count == NULL) {
584 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",
585 (
unsigned long) ntasks *
sizeof(sion_int32)));
593 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"before open\n"));
594 mapsid=
_sion_open_read(fname,_SION_FMODE_READ|_SION_FMODE_ANSI,_SION_READ_MASTER_ONLY_OF_MULTI_FILES,
595 &lntasks,&lnfiles,NULL,&lfsblksize,NULL,&lfileptr);
597 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"after open\n"));
599 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"sion file %d files #tasks=%d rc=%d\n", *numFiles,mapping_size,rc));
602 lfilemanager = (
int *) malloc(*numFiles *
sizeof(
int));
603 if (lfilemanager == NULL) {
604 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilemanager), aborting ...\n",
605 (
unsigned long) *numFiles *
sizeof(
int)));
612 for(task=0;task<mapping_size;task++) {
613 if(mapping[task*2+1]==0) {
614 lfilemanager[mapping[task*2+0]]=task;
615 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" manager of file %d is grank=%d\n",mapping[task*2+0],task));
628 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot find file %s , aborting ...\n",fname));
633 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_master->
mapping_size, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
634 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" mapping_size is=%d\n",sion_filedesc_master->
mapping_size));
638 if (mapsid>=0) _sion_close_sid(mapsid);
645 int tasks_per_task = sion_filedesc_master->
mapping_size / ntasks;
646 int startpos = rank*tasks_per_task;
647 int endpos = (rank+1)*tasks_per_task;
650 if(endpos<sion_filedesc_master->mapping_size) endpos=sion_filedesc_master->
mapping_size;
652 *nlocaltasks=endpos-startpos;
653 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"pre-compute distribution: startpos=%d endpos=%d nlocaltasks=%d\n",startpos, endpos, (
int) *nlocaltasks ));
655 if (globalranks == NULL)
return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate globalranks, not pointer parameter given, aborting ...\n"));
656 if (mapping_filenrs == NULL)
return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_filenrs, not pointer parameter given, aborting ...\n"));
657 if (mapping_lranks == NULL)
return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_lranks, not pointer parameter given, aborting ...\n"));
659 if ((*globalranks) != NULL)
return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate globalranks, memory allready allocated (unknown size), aborting ...\n"));
660 if ((*mapping_filenrs) != NULL)
return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_filenrs, memory allready allocated (unknown size), aborting ...\n"));
661 if ((*mapping_lranks) != NULL)
return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_lranks, memory allready allocated (unknown size), aborting ...\n"));
664 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate globalranks field for parameter size=%d\n",(
int) *nlocaltasks ));
665 *globalranks = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
666 if (*globalranks == NULL) {
667 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate memory of size %lu (globalranks), aborting ...\n", (
unsigned long)
sizeof(sion_int32)));
671 for(task=startpos;task<endpos;task++) {
672 (*globalranks)[ltask]=task;
673 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"set *globalranks[%d]=%d\n",(
int) ltask,(*globalranks)[ltask]));
680 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_master->
keyvalmode, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
681 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" keyvalmode is=%d\n",sion_filedesc_master->
keyvalmode));
684 _sion_keyval_check_env(sion_filedesc_master, file_mode_flags);
687 if (rank == 0) helpint64=*numFiles;
688 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0); *numFiles=helpint64;
689 sion_filedesc_master->
nfiles=*numFiles;
693 if (sion_filedesc_master->
multifiles == NULL) {
694 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (chunksizes), aborting ...\n",
700 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
702 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" starting init of SION #%d of %d\n", filenr,*numFiles));
704 #ifdef _SION_FIND_ROOT_LRANK_NULL_DO_NOT_USE 711 helpint64=lfilemanager[filenr];
713 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0);
718 for(task=0;task<*nlocaltasks;task++) {
719 if((*globalranks)[task]==grankroot) helpint32=1;
723 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
725 for(task=0;task<ntasks;task++) {
726 if(sion_count[task]==1) {
737 rootcounter=( (rootcounter+1) % ntasks);
738 helpint64=rootcounter;
741 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0);
743 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" manager of file %d is rank=%d\n",filenr,root));
747 if (sion_filedesc_sub == NULL) {
748 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",
749 (
unsigned long)
sizeof(sion_filedesc_sub)));
751 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
753 sion_filedesc_sub->
fname = (sion_gendata->apidesc->get_multi_filename_cb?sion_gendata->apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname, filenr);
762 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" starting open for read on file %s\n", sion_filedesc_sub->
fname));
763 DPRINTFTS(rank,
"before open");
764 sion_filedesc_sub->
fileptr=NULL;
768 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot open %s for reading, aborting ...\n", fname));
770 sion_filedesc_sub->
fileptr = sion_fileptr;
772 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
773 DPRINTFTS(rank,
"after open root");
778 if (rc!=SION_SUCCESS) {
779 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot read header from file %s, aborting ...\n", fname));
781 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
782 " 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));
784 DPRINTFTS(rank,
"before alloc");
787 DPRINTFTS(rank,
"after alloc");
790 if (rc != SION_SUCCESS) {
791 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot read header from file %s, aborting ...\n", fname));
794 _sion_coll_check_env(sion_filedesc_sub);
798 if (!sion_filedesc_sub->
usecoll) _sion_calculate_startpointers(sion_filedesc_sub);
799 else _sion_calculate_startpointers_collective(sion_filedesc_sub);
800 DPRINTFTS(rank,
"after calculate");
803 _sion_keyval_check_env(sion_filedesc_sub, file_mode_flags);
808 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
globalskip, sion_gendata->comm_data_global, _SION_INT64, 1, root);
811 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
endianness, sion_gendata->comm_data_global, _SION_INT32, 1, root);
812 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
swapbytes, sion_gendata->comm_data_global, _SION_INT32, 1, root);
813 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
fsblksize, sion_gendata->comm_data_global, _SION_INT32, 1, root);
814 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
ntasks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
817 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
fileversion, sion_gendata->comm_data_global, _SION_INT32, 1, root);
818 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
nfiles, sion_gendata->comm_data_global, _SION_INT32, 1, root);
819 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
filenumber, sion_gendata->comm_data_global, _SION_INT32, 1, root);
820 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
flag1, sion_gendata->comm_data_global, _SION_INT64, 1, root);
821 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
flag2, sion_gendata->comm_data_global, _SION_INT64, 1, root);
822 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
maxusedchunks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
823 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
start_of_varheader, sion_gendata->comm_data_global, _SION_INT64, 1, root);
824 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
827 DPRINTFTS(rank,
"after bcast");
834 sion_tmpintfield2 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
835 if (sion_tmpintfield2 == NULL) {
836 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",
837 (
unsigned long) tmpsize *
sizeof(sion_int64)));
842 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
847 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" scan for gtask=%d\n", (
int) sion_tmpintfield2[task]));
848 for(ltask=0;ltask<*nlocaltasks;ltask++) {
849 if( (
int) sion_tmpintfield2[task]==(*globalranks)[ltask]) {
850 sion_tmpintfield2[task]=-1 * (sion_tmpintfield2[task] + 1);
855 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" found %d globalranks for file %s\n", sion_filedesc_sub->
nlocaltasksinfile, sion_filedesc_sub->
fname));
857 DPRINTFTS(rank,
"before open non-root");
862 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot open %s for reading, aborting ...\n", fname));
864 sion_filedesc_sub->
fileptr = sion_fileptr;
867 DPRINTFTS(rank,
"after open non-root");
873 _sion_free_filedesc_all_globalranks(sion_filedesc_sub);
876 _sion_alloc_filedesc_all_globalranks(sion_filedesc_sub);
877 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
882 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
888 if(sion_tmpintfield2[task]<0) {
890 sion_filedesc_sub->
all_globalranks[ltask]= (-1 * sion_tmpintfield2[task]) - 1;
891 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" all_globalranks[%d]=%d all_localranks[%d]=%d\n",
901 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
903 _sion_free_filedesc_all_chunksizes(sion_filedesc_sub);
904 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
916 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
918 _sion_free_filedesc_all_startpointers(sion_filedesc_sub);
919 _sion_alloc_filedesc_all_startpointers(sion_filedesc_sub);
936 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" got from file blockcount[%d]=%d\n",task,(
int) sion_tmpintfield2[task]));
938 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
943 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store blockcount task=%d -> ltask=%d cnt=%d\n",task,ltask,(
int) sion_tmpintfield2[task]));
948 for (blknum = 0; blknum < sion_filedesc_sub->
maxusedchunks; blknum++) {
954 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
963 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
keyvalmode, sion_gendata->comm_data_global, _SION_INT32, 1, root);
966 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
usecoll, sion_gendata->comm_data_global, _SION_INT32, 1, root);
967 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
collsize, sion_gendata->comm_data_global, _SION_INT32, 1, root);
969 if(sion_filedesc_sub->
usecoll) {
973 sion_tmpintfield2[task]= (sion_int64) (sion_filedesc_sub->
all_coll_collector[task]*_SION_CONST_MAX_INT32) + sion_filedesc_sub->
collsize;
975 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
979 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
982 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store collsize+collector for %d elements\n",sion_filedesc_sub->
nlocaltasksinfile));
997 sion_filedesc_sub->
rank = 0;
1007 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc_sub);
1014 if(sion_tmpintfield2) free(sion_tmpintfield2);
1022 int lfile=-1,lrank=-1, blknum;
1023 sion_filedesc_sub=NULL;
1024 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1025 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1033 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"init to first local rank in first file (%d, %d)\n",lfile,lrank));
1035 if((sion_filedesc_sub) && (lrank>=0) && (lfile>=0)) {
1036 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"sion_filedesc_master->mapping_size=%d\n",sion_filedesc_master->
mapping_size));
1045 sion_filedesc_master->
rank = lrank;
1063 for(filenr=0;filenr<sion_filedesc_sub->
nfiles;filenr++) {
1068 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
1079 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"set startpointer to %d\n",(
int) sion_filedesc_master->
currentpos));
1088 *fileptr=sion_filedesc_master->
fileptr->fileptr;
1097 sion_int64 *helpptr_chunksize = NULL;
1098 sion_int32 *helpptr_mapping_filenrs = NULL;
1099 sion_int32 *helpptr_mapping_lranks = NULL;
1102 if (chunksizes != NULL) {
1103 if ((*chunksizes) == NULL) {
1104 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate chunksizes field for parameter size=%d\n",(
int) *nlocaltasks ));
1105 helpptr_chunksize = (sion_int64 *) malloc(*nlocaltasks *
sizeof(sion_int64));
1106 if (helpptr_chunksize == NULL) {
1107 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)));
1109 *chunksizes = helpptr_chunksize;
1111 helpptr_chunksize = *chunksizes;
1115 if (mapping_filenrs != NULL) {
1116 if ((*mapping_filenrs) == NULL) {
1117 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate mapping_filenrs field for parameter size=%d\n",(
int) *nlocaltasks ));
1118 helpptr_mapping_filenrs = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
1119 if (helpptr_mapping_filenrs == NULL) {
1120 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)));
1122 *mapping_filenrs = helpptr_mapping_filenrs;
1124 helpptr_mapping_filenrs = *mapping_filenrs;
1128 if (mapping_lranks != NULL) {
1129 if ((*mapping_lranks) == NULL) {
1130 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate mapping_lranks field for parameter size=%d\n",(
int) *nlocaltasks ));
1131 helpptr_mapping_lranks = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
1132 if (helpptr_mapping_lranks == NULL) {
1133 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)));
1135 *mapping_lranks = helpptr_mapping_lranks;
1137 helpptr_mapping_lranks = *mapping_lranks;
1142 if(helpptr_chunksize || helpptr_mapping_filenrs || helpptr_mapping_lranks) {
1143 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1144 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1146 for(task=0;task<*nlocaltasks;task++) {
1148 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
" set chunksizes[%d]=%4d (filenr=%d, ltask=%d lrank=%d)\n",
1150 if(helpptr_chunksize) helpptr_chunksize[task] = sion_filedesc_sub->
all_chunksizes[ltask];
1151 if(helpptr_mapping_filenrs) helpptr_mapping_filenrs[task] = filenr;
1152 if(helpptr_mapping_lranks) helpptr_mapping_lranks[task] = sion_filedesc_sub->
all_localranks[ltask];
1161 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_paropen_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1164 if(sion_count) free(sion_count);
1166 if(lfilemanager) free(lfilemanager);
1171 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_multi_mpi: unknown file mode"));
1178 int _sion_parclose_mapped_generic(
int sid,
1182 int rc=SION_SUCCESS;
1183 int lfile, grank, lrank, blknum, filenr, tmpsize, root, ltask, mappingroot, task;
1186 sion_int64 *sion_tmpintfield_send = NULL;
1187 sion_int64 *sion_tmpintfield_lrank_recv = NULL;
1188 sion_int64 *sion_tmpintfield_data_recv = NULL;
1189 sion_int64 *sion_tmpintfield_data = NULL;
1190 sion_int32 *mapping = NULL;
1191 sion_int32 *sion_tmpint32field_send = NULL;
1192 sion_int32 *sion_tmpint32field_data_recv = NULL;
1193 sion_int32 *sion_count = NULL;
1194 sion_int32 helpint32;
1196 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"enter parallel close sid=%d\n", sid));
1199 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: invalid sion_filedesc_master, aborting %d ...\n", sid));
1204 int numbytes, numfds;
1206 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"internal data size of sid %2d (%d bytes, %d fds) \n", sid,numbytes, numfds));
1214 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));
1220 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_parclose_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1228 lrank=sion_filedesc_master->
rank;
1229 if((lrank>=0) && (lfile>=0)) {
1230 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
1236 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1237 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1239 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));
1241 if(sion_filedesc_sub->
fileptr!=NULL) {
1243 sion_filedesc_sub->
fileptr = NULL;
1249 _sion_free_filedesc(sion_filedesc_sub);
1252 _SION_SAFE_FREE(mapping, NULL);
1253 _SION_SAFE_FREE(sion_filedesc_master->
multifiles, NULL);
1258 _sion_free_filedesc(sion_filedesc_master);
1259 sion_filedesc_master = NULL;
1271 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_parclose_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1275 lrank=sion_filedesc_master->
rank;
1276 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
1288 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));
1294 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
1298 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
1303 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
1304 if (sion_count == NULL) {
1305 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",
1306 (
unsigned long) ntasks *
sizeof(sion_int32)));
1310 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1312 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1313 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" starting close for file %d: %s \n", filenr,sion_filedesc_sub->
fname));
1320 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));
1322 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));
1323 sion_filedesc_sub->
fileptr = NULL;
1328 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
1332 sion_tmpintfield_send = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1333 if (sion_tmpintfield_send == NULL) {
1334 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_send), aborting ...\n",
1335 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1337 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));
1344 sion_tmpintfield_lrank_recv = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1345 if (sion_tmpintfield_lrank_recv == NULL) {
1346 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",
1347 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1349 sion_tmpintfield_data_recv = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1350 if (sion_tmpintfield_data_recv == NULL) {
1351 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",
1352 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1354 sion_tmpintfield_data = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1355 if (sion_tmpintfield_data == NULL) {
1356 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_data), aborting ...\n",
1357 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1359 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: allocate fields for all tasks of file (%d)\n", filenr,tmpsize));
1362 }
else sion_tmpintfield_lrank_recv=sion_tmpintfield_data_recv=sion_tmpintfield_data=NULL;
1366 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1370 sion_tmpintfield_send[ltask]=sion_filedesc_sub->
all_localranks[ltask];
1372 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: before call of gathervr_cb %x %x %x %d %d %d\n",
1373 filenr,sion_tmpintfield_lrank_recv, sion_tmpintfield_send, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
nlocaltasksinfile, root));
1375 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);
1379 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" send all_blockcount[%d]: %d\n", ltask, sion_filedesc_sub->
all_blockcount[ltask]));
1380 sion_tmpintfield_send[ltask]=sion_filedesc_sub->
all_blockcount[ltask];
1382 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);
1388 if (sion_tmpintfield_data_recv[ltask] > sion_filedesc_sub->
maxusedchunks) {
1389 sion_filedesc_sub->
maxusedchunks = (int) sion_tmpintfield_data_recv[ltask];
1394 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
maxusedchunks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1395 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: maxusedchunks=%d\n", filenr,sion_filedesc_sub->
maxusedchunks));
1401 lrank=(int) sion_tmpintfield_lrank_recv[ltask];
1402 DPRINTFP((64,
"_sion_parclose_mapped_generic", rank,
" sort in ltask=%d --> lrank=%d blkcount=%d\n",
1403 ltask,lrank,sion_tmpintfield_data_recv[ltask]));
1404 sion_tmpintfield_data[lrank]=sion_tmpintfield_data_recv[ltask];
1419 for (blknum = 0; blknum < sion_filedesc_sub->
maxusedchunks; blknum++) {
1421 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
" collect blocksize step %d of %d\n", blknum+1,sion_filedesc_sub->
maxusedchunks));
1424 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"sion_filedesc_sub->nlocaltasksinfile=%d\n",sion_filedesc_sub->
nlocaltasksinfile));
1427 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"sort in blksize[%d][%d]=%d\n",blknum, ltask, sion_tmpintfield_send[ltask]));
1429 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);
1436 lrank=(int) sion_tmpintfield_lrank_recv[ltask];
1437 sion_tmpintfield_data[lrank]=sion_tmpintfield_data_recv[ltask];
1438 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"prepare blksize[%d][%d]=%ld\n",blknum,lrank,sion_tmpintfield_data[lrank]));
1447 if(sion_tmpintfield_lrank_recv) free(sion_tmpintfield_lrank_recv);
1448 if(sion_tmpintfield_data_recv) free(sion_tmpintfield_data_recv);
1449 if(sion_tmpintfield_data) free(sion_tmpintfield_data);
1450 if(sion_tmpintfield_send) free(sion_tmpintfield_send);
1452 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" ending close for file %d: %s \n", filenr,sion_filedesc_sub->
fname));
1458 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"mappingroot=%d rank=%d\n", mappingroot, rank ));
1459 if(rank==mappingroot) {
1460 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"allocate mapping of size %d\n",sion_filedesc_master->
mapping_size));
1461 mapping = (sion_int32 *) malloc(sion_filedesc_master->
mapping_size * 2 *
sizeof(sion_int32));
1462 if (mapping == NULL) {
1463 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_ABORT,
"_sion_parclose_generic_mapped: Cannot allocate memory for mapping"));
1468 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1469 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1473 sion_tmpint32field_send = (sion_int32 *) malloc(tmpsize *
sizeof(sion_int32));
1474 if (sion_tmpint32field_send == NULL) {
1475 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",
1476 (
unsigned long) tmpsize *
sizeof(sion_int32)));
1481 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, mappingroot);
1483 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));
1485 if(rank==mappingroot) {
1488 sion_tmpint32field_data_recv = (sion_int32 *) malloc(tmpsize *
sizeof(sion_int32));
1489 if (sion_tmpint32field_data_recv == NULL) {
1490 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",
1491 (
unsigned long) tmpsize *
sizeof(sion_int32)));
1493 }
else sion_tmpint32field_data_recv=NULL;
1497 sion_tmpint32field_send[ltask*2+0]= (int) sion_filedesc_sub->
all_localranks[ltask];
1498 sion_tmpint32field_send[ltask*2+1]= (
int) sion_filedesc_sub->
all_globalranks[ltask];
1499 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]));
1503 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
" sion_tmpint32field_send: %d -> %d \n",ltask, sion_tmpint32field_send[ltask]));
1506 if (rank == mappingroot)
for(task=0;task<ntasks;task++) sion_count[task]*=2;
1507 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);
1508 if (rank == mappingroot)
for(task=0;task<ntasks;task++) sion_count[task]/=2;
1510 if(rank==mappingroot) {
1513 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
" sion_tmpint32field_send: %d -> %d \n",ltask, sion_tmpint32field_data_recv[ltask]));
1516 lrank=(int) sion_tmpint32field_data_recv[ltask*2+0];
1517 grank=(int) sion_tmpint32field_data_recv[ltask*2+1];
1518 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"store mapping[%d]=(%d,%d)\n",grank,filenr,lrank));
1519 mapping[grank*2+0]=filenr;
1520 mapping[grank*2+1]=lrank;
1524 if(sion_tmpint32field_data_recv) free(sion_tmpint32field_data_recv);
1525 if(sion_tmpint32field_send) free(sion_tmpint32field_send);
1529 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1530 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1536 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"mapping size is %d\n",sion_filedesc_master->
mapping_size));
1540 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));
1542 sion_filedesc_sub->
fileptr = NULL;
1551 _sion_free_filedesc(sion_filedesc_sub);
1553 if (sion_gendata->apidesc->free_lcg_cb && sion_gendata->comm_data_local) {
1554 sion_gendata->apidesc->free_lcg_cb(sion_gendata->comm_data_local);
1556 _SION_SAFE_FREE(mapping, NULL);
1557 _SION_SAFE_FREE(sion_count, NULL);
1558 _SION_SAFE_FREE(sion_filedesc_master->
multifiles, NULL);
1561 _sion_free_filedesc(sion_filedesc_master);
1562 sion_filedesc_master = NULL;
1566 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.
_sion_filedesc * _sion_alloc_filedesc()
Allocates memory for internal sion structure.
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.
int _sion_errorprint(int rc, int level, const char *format,...)
Internal SION error.
#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
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