15 #define _XOPEN_SOURCE 700
25 #include <sys/types.h>
32 #include "sion_error_handler.h"
42 #include "sion_generic_buddy.h"
46 int sion_generic_create_api(
char *name ) {
47 int apiid = SION_ID_UNDEF;
52 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_generic_create_api: problems to alloc apidesc, aborting ...\n"));
57 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_generic_create_api: name for API not given, aborting ...\n"));
60 sion_apidesc->name=strdup(name);
63 sion_apidesc->aid=apiid;
64 sion_apidesc->level=SION_GENERIC_API_LEVEL_NONE;
66 DPRINTFP((2,
"_sion_generic_create_api", _SION_DEFAULT_RANK,
"API created with name %s apiid=%d\n", sion_apidesc->name, apiid));
71 int sion_generic_free_api(
int aid ) {
73 int rc = SION_SUCCESS;
76 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_free_api: invalid sion_apidesc %d", aid));
84 int sion_generic_register_create_local_commgroup_cb(
int aid,
int create_lcg_cb(
void **,
void *,
int,
int,
int,
int,
int,
int)) {
86 int rc = SION_SUCCESS;
89 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_create_local_commgroup_cb: invalid sion_apidesc %d", aid));
92 if(sion_apidesc->create_lcg_cb!=NULL) {
93 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_create_local_commgroup_cb: update_cb already registered for apiid=%d", aid));
95 sion_apidesc->create_lcg_cb=create_lcg_cb;
99 DPRINTFP((2,
"sion_generic_register_create_local_commgroup_cb", _SION_DEFAULT_RANK,
"create_lcg_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
104 int sion_generic_register_free_local_commgroup_cb(
int aid,
int free_lcg_cb(
void *)) {
106 int rc = SION_SUCCESS;
109 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_free_local_commgroup_cb: invalid sion_apidesc %d", aid));
112 if(sion_apidesc->free_lcg_cb!=NULL) {
113 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_free_local_commgroup_cb: update_cb already registered for apiid=%d", aid));
115 sion_apidesc->free_lcg_cb=free_lcg_cb;
119 DPRINTFP((2,
"sion_generic_register_free_local_commgroup_cb", _SION_DEFAULT_RANK,
"free_lcg_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
125 int sion_generic_register_barrier_cb(
int aid,
int barrier_cb(
void *)) {
127 int rc = SION_SUCCESS;
130 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_barrier_cb: invalid sion_apidesc %d", aid));
133 if(sion_apidesc->barrier_cb!=NULL) {
134 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_barrier_cb: barrier_cb already registered for apiid=%d", aid));
136 sion_apidesc->barrier_cb=barrier_cb;
140 DPRINTFP((2,
"sion_generic_register_barrier_cb", _SION_DEFAULT_RANK,
"barrier_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
145 int sion_generic_register_bcastr_cb(
int aid,
int bcastr_cb(
void *,
void *,
int,
int,
int)) {
147 int rc = SION_SUCCESS;
150 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_bcastr_cb: invalid sion_apidesc %d", aid));
153 if(sion_apidesc->bcastr_cb!=NULL) {
154 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_bcastr_cb: bcastr_cb already registered for apiid=%d", aid));
156 sion_apidesc->bcastr_cb=bcastr_cb;
160 DPRINTFP((2,
"sion_generic_register_bcastr_cb", _SION_DEFAULT_RANK,
"bcastr_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
165 int sion_generic_register_gatherr_cb(
int aid,
int gatherr_cb(
void *,
void *,
void *,
int,
int,
int)) {
167 int rc = SION_SUCCESS;
170 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_gatherr_cb: invalid sion_apidesc %d", aid));
173 if(sion_apidesc->gatherr_cb!=NULL) {
174 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_gatherr_cb: gatherr_cb already registered for apiid=%d", aid));
176 sion_apidesc->gatherr_cb=gatherr_cb;
180 DPRINTFP((2,
"sion_generic_register_gatherr_cb", _SION_DEFAULT_RANK,
"gatherr_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
185 int sion_generic_register_gathervr_cb(
int aid,
int gathervr_cb(
void *,
void *,
void *,
int,
int *,
int,
int)) {
187 int rc = SION_SUCCESS;
190 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_gathervr_cb: invalid sion_apidesc %d", aid));
193 if(sion_apidesc->gathervr_cb!=NULL) {
194 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_gathervr_cb: gathervr_cb already registered for apiid=%d", aid));
196 sion_apidesc->gathervr_cb=gathervr_cb;
200 DPRINTFP((2,
"sion_generic_register_gathervr_cb", _SION_DEFAULT_RANK,
"gathervr_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
205 int sion_generic_register_scatterr_cb(
int aid,
int scatterr_cb(
void *,
void *,
void *,
int,
int,
int)) {
207 int rc = SION_SUCCESS;
210 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_scatterr_cb: invalid sion_apidesc %d", aid));
213 if(sion_apidesc->scatterr_cb!=NULL) {
214 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_scatterr_cb: scatterr_cb already registered for apiid=%d", aid));
216 sion_apidesc->scatterr_cb=scatterr_cb;
220 DPRINTFP((2,
"sion_generic_register_scatterr_cb", _SION_DEFAULT_RANK,
"scatterr_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
225 int sion_generic_register_scattervr_cb(
int aid,
int scattervr_cb(
void *,
void *,
void *,
int,
int *,
int,
int)) {
227 int rc = SION_SUCCESS;
230 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_scattervr_cb: invalid sion_apidesc %d", aid));
233 if(sion_apidesc->scattervr_cb!=NULL) {
234 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_scattervr_cb: scattervr_cb already registered for apiid=%d", aid));
236 sion_apidesc->scattervr_cb=scattervr_cb;
240 DPRINTFP((2,
"sion_generic_register_scattervr_cb", _SION_DEFAULT_RANK,
"scattervr_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
245 int sion_generic_register_gather_and_execute_cb(
int aid,
int gather_execute_cb(
const void *, sion_int64*,
int, sion_int64,
246 void *,
int,
int,
int,
int,
247 int process_cb(
const void *,sion_int64 *,
int))) {
249 int rc = SION_SUCCESS;
252 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_gather_and_execute_cb: invalid sion_apidesc %d", aid));
255 if(sion_apidesc->gather_execute_cb!=NULL) {
256 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_gather_and_execute_cb: scattervr_cb already registered for apiid=%d", aid));
258 sion_apidesc->gather_execute_cb=gather_execute_cb;
262 DPRINTFP((2,
"sion_generic_register_gather_and_execute_cb", _SION_DEFAULT_RANK,
"gather_execute_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
267 int sion_generic_register_execute_and_scatter_cb(
int aid,
int execute_scatter_cb(
void *, sion_int64*,
int, sion_int64,
268 void *,
int,
int,
int,
int,
269 int process_cb(
void *,sion_int64 *,
int))) {
271 int rc = SION_SUCCESS;
274 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_execute_and_scatter_cb: invalid sion_apidesc %d", aid));
277 if(sion_apidesc->execute_scatter_cb!=NULL) {
278 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_execute_and_scatter_cb: scattervr_cb already registered for apiid=%d", aid));
280 sion_apidesc->execute_scatter_cb=execute_scatter_cb;
282 DPRINTFP((2,
"sion_generic_register_execute_and_scatter_cb", _SION_DEFAULT_RANK,
"gather_execute_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
287 int sion_generic_register_get_multi_filename_cb(
int aid,
char *get_multi_filename_cb(
const char *,
int)) {
292 return(_sion_errorprint(-1,_SION_ERROR_RETURN,
"sion_generic_register_get_multi_filename_cb: invalid sion_apidesc %d", aid));
295 if(sion_apidesc->get_multi_filename_cb!=NULL) {
296 return(_sion_errorprint(-1,_SION_ERROR_RETURN,
"sion_generic_register_get_multi_filename_cb: get_multi_filename_cb already registered for apiid=%d", aid));
298 sion_apidesc->get_multi_filename_cb=get_multi_filename_cb;
302 DPRINTFP((2,
"sion_generic_register_get_multi_filename_cb", -1,
"get_multi_filename_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
307 int sion_generic_register_get_capability_cb(
int aid,
int get_capability_cb(
void *)) {
309 int rc = SION_SUCCESS;
312 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_get_capability_cb: invalid sion_apidesc %d", aid));
315 if(sion_apidesc->get_capability_cb!=NULL) {
316 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_generic_register_get_capability_cb: get_capability_cb already registered for apiid=%d", aid));
318 sion_apidesc->get_capability_cb=get_capability_cb;
322 DPRINTFP((2,
"sion_generic_register_get_capability_cb", _SION_DEFAULT_RANK,
"get_capability_cb registered for apiid=%s (%d)\n", sion_apidesc->name, aid));
353 const char* file_mode,
354 sion_int64* chunksize,
355 sion_int32* fsblksize,
367 int rc, sid = SION_ID_UNDEF;
368 sion_int32 lfsblksize;
369 sion_int64 lchunksize;
371 char *nfname=NULL,*lprefix=NULL;
377 DPRINTFTS(grank,
"enter sion_generic_paropen");
378 DPRINTFP((1,
"sion_generic_paropen", grank,
"enter generic parallel open of FILE %s (global: %d of %d, local: %d of %d, file: %d of %d )\n",
379 fname, grank, gsize, *lrank, *lsize, *filenumber, *numfiles));
382 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_register_scattervr_cb: invalid sion_apidesc %d", aid));
385 if ( (sion_apidesc->level!=SION_GENERIC_API_LEVEL_STD) &&
386 (sion_apidesc->level!=SION_GENERIC_API_LEVEL_FULL) ) {
387 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: API %s not correctly initalized, aborting",sion_apidesc->name));
391 if ( (grank < 0 ) || (grank >= gsize) ) {
392 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: global rank %d not valid (0..%d)",grank,gsize));
397 if(strstr(fname,
".def")!=NULL) {
402 lfsblksize=*fsblksize;
403 lchunksize=*chunksize;
407 DPRINTFP((1,
"sion_generic_paropen", grank,
"setting fsblksize = %d for file %s\n", lfsblksize, fname));
412 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: problems to alloc gendata, aborting ...\n"));
416 sion_gendata->aid=aid;
417 sion_gendata->apidesc=sion_apidesc;
418 sion_gendata->comm_data_global=gcommgroup;
419 sion_gendata->comm_data_local=NULL;
420 sion_gendata->grank=grank;
421 sion_gendata->gsize=gsize;
424 if ( ! flags_store ) {
425 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: could not parse file mode in %s, aborting ...\n", file_mode));
428 if (flags_store->mask&_SION_FMODE_WRITE) {
432 _sion_flags_destroy_store(&flags_store);
433 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: No lrank variable given"));
436 _sion_flags_destroy_store(&flags_store);
437 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: No lsize variable given"));
439 if ( !_sion_flags_get(flags_store,
"collmsa") && ((*lrank < 0 ) || (*lrank >= *lsize)) ) {
440 _sion_flags_destroy_store(&flags_store);
441 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: local rank %d not valid (0..%d)",*lrank,*lsize));
443 sion_gendata->lrank=*lrank;
444 sion_gendata->lsize=*lsize;
446 if (filenumber == NULL) {
447 _sion_flags_destroy_store(&flags_store);
448 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: No filenumber variable given"));
450 if (numfiles == NULL) {
451 _sion_flags_destroy_store(&flags_store);
452 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: No numfiles variable given"));
454 if ( !_sion_flags_get(flags_store,
"collmsa") && ((*filenumber < 0 ) || (*filenumber >= *numfiles)) ) {
455 _sion_flags_destroy_store(&flags_store);
456 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: file number %d not valid (0..%d)",*filenumber,*numfiles));
458 sion_gendata->filenumber=*filenumber;
459 sion_gendata->numfiles=*numfiles;
460 if (_sion_flags_get(flags_store,
"collmsa")) {
462 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: error in MSA aware collective renumbering, aborting ...\n"));
466 lprefix = calloc(SION_FILENAME_LENGTH,1);
467 if (lprefix == NULL) {
468 _sion_flags_destroy_store(&flags_store);
469 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: cannot allocate temporary memory of size %lu (lprefix), aborting ...\n", (
unsigned long) SION_FILENAME_LENGTH));
472 strcpy(lprefix, fname);
474 }
else if (flags_store->mask&_SION_FMODE_READ) {
477 DPRINTFP((1,
"sion_generic_paropen", grank,
"READ: buddy=%d\n", flags_store->mask&_SION_FMODE_BUDDY));
480 if(! (flags_store->mask&_SION_FMODE_BUDDY) ) {
482 rc = _sion_generic_get_and_distribute_info_from_file(sion_gendata, fname);
483 if (_sion_flags_get(flags_store,
"collmsa") && (sion_gendata->numfiles == 1)) {
485 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: error in MSA aware collective renumbering, aborting ...\n"));
488 *numfiles=sion_gendata->numfiles;
489 *filenumber=sion_gendata->filenumber;
490 if(rc != SION_SUCCESS) {
491 _sion_flags_destroy_store(&flags_store);
492 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: error in _sion_generic_get_and_distribute_info_from_file"));
498 sion_gendata->lrank=*lrank;
499 sion_gendata->lsize=*lsize;
501 if (filenumber == NULL)
return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: No filenumber variable given"));
502 if (numfiles == NULL)
return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: No numfiles variable given"));
503 if ( (*filenumber < 0 ) || (*filenumber >= *numfiles) ) {
504 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: file number %d not valid (0..%d)",*filenumber,*numfiles));
506 sion_gendata->filenumber=*filenumber;
507 sion_gendata->numfiles=*numfiles;
513 _sion_flags_destroy_store(&flags_store);
514 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: unknown file mode"));
518 rc=sion_apidesc->create_lcg_cb(&sion_gendata->comm_data_local,sion_gendata->comm_data_global,
519 sion_gendata->grank,sion_gendata->gsize,
520 sion_gendata->lrank,sion_gendata->lsize,
521 sion_gendata->filenumber,sion_gendata->numfiles);
523 _sion_flags_destroy_store(&flags_store);
524 if(lprefix) free(lprefix);
525 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: error in create_local_commgroup callback function"));
529 nfname=(sion_apidesc->get_multi_filename_cb?sion_apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname,sion_gendata->filenumber);
530 help_globalrank=sion_gendata->grank;
535 if(! (flags_store->mask&_SION_FMODE_BUDDY) ) {
538 DPRINTFP((1,
"sion_generic_paropen", grank,
"call parallel open of %d files (current name %s) in %s mode\n", sion_gendata->numfiles, nfname, file_mode));
539 rc=
_sion_paropen_generic_one_file(sid, nfname, flags_store, lprefix, &sion_gendata->numfiles, &sion_gendata->filenumber, &lchunksize, &lfsblksize,
540 sion_gendata->lrank, sion_gendata->lsize, &help_globalrank,
541 _SION_INTERNAL_FLAG_NORMAL, fileptr, sion_gendata, NULL);
542 DPRINTFP((1,
"sion_generic_paropen", sion_gendata->grank,
"leave parallel open of %d files in %s mode #tasks=%d sid=%d globalrank=%d\n", sion_gendata->numfiles,
543 file_mode, sion_gendata->lsize, sid, sion_gendata->grank));
548 DPRINTFP((1,
"sion_generic_paropen", grank,
"call parallel buddy open of %d files (current name %s) in %s mode\n", sion_gendata->numfiles, nfname, file_mode));
549 rc=_sion_paropen_generic_buddy(sid, fname, flags_store, lprefix, &sion_gendata->numfiles, &sion_gendata->filenumber, &lchunksize, &lfsblksize,
550 sion_gendata->lrank, sion_gendata->lsize, &help_globalrank,
551 fileptr, sion_gendata);
552 DPRINTFP((1,
"sion_generic_paropen", sion_gendata->grank,
"leave parallel buddy open of %d files in %s mode #tasks=%d sid=%d globalrank=%d rc=%d\n", sion_gendata->numfiles,
553 file_mode, sion_gendata->lsize, sid, sion_gendata->grank, rc));
557 _sion_flags_destroy_store(&flags_store);
561 DPRINTFP((1,
"sion_generic_paropen", sion_gendata->grank,
"invalid rc %d or sion_filedesc %d", rc, sid));
562 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen: invalid rc %d or sion_filedesc %d", rc, sid));
566 sion_filedesc->
dataptr=sion_gendata;
571 if(nfname) free(nfname);
575 *fsblksize = lfsblksize;
576 *chunksize = lchunksize;
580 DPRINTFP((64,
"sion_generic_paropen", grank,
"lprefix=%s (%x)\n", lprefix,lprefix));
581 if(lprefix) free(lprefix);
583 DPRINTFP((1,
"sion_generic_paropen", grank,
"leave parallel open of file %s sid=%d\n", fname, sid));
584 DPRINTFTS(-1,
"leave sion_generic_paropen");
590 int sion_generic_parclose(
int sid) {
591 ONLY_DEBUG(
int grank);
592 int mapping_size=0, rc=SION_SUCCESS;
593 sion_int32 *mapping=NULL;
599 DPRINTFTS(-1,
"enter sion_generic_parclose");
602 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_parclose: invalid sion_filedesc %d", sid));
604 sion_gendata=sion_filedesc->
dataptr;
605 sion_apidesc=sion_gendata->apidesc;
607 ONLY_DEBUG(grank=sion_gendata->grank);
609 DPRINTFP((1,
"sion_generic_parclose", grank,
"enter parallel close of sid %d (%d file)\n", sid, sion_filedesc->
nfiles));
612 _sion_generic_collect_mapping(sion_filedesc,&mapping_size,&mapping);
616 sion_gendata, NULL );
618 rc = _sion_parclose_generic_buddy( sid, sion_filedesc->
rank, sion_filedesc->
ntasks, mapping_size, mapping, sion_gendata );
622 if (sion_apidesc->free_lcg_cb && sion_gendata->comm_data_local) {
623 sion_apidesc->free_lcg_cb(sion_gendata->comm_data_local);
625 _SION_SAFE_FREE(mapping, NULL);
629 sion_apidesc->barrier_cb(sion_gendata->comm_data_global);
631 _SION_SAFE_FREE(sion_gendata, NULL);
633 DPRINTFP((1,
"sion_generic_parclose", grank,
"leave parallel close of sid %d\n", sid));
634 DPRINTFTS(-1,
"leave sion_generic_parclose");
640 int sion_generic_paropen_mapped(
int aid,
642 const char *file_mode,
649 sion_int64 **chunksizes,
650 int **mapping_filenrs,
651 int **mapping_lranks,
652 sion_int32 *fsblksize,
655 int rc, sid = SION_ID_UNDEF;
662 DPRINTFTS(grank,
"enter sion_generic_paropen_mapped");
663 DPRINTFP((1,
"sion_generic_paropen_mapped", grank,
"enter generic parallel mapped open of file %s (global: %d of %d, nlocaltasks %d)\n",
664 fname, grank, gsize, *nlocaltasks));
667 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_register_scattervr_cb: invalid sion_apidesc %d", aid));
670 if ((!sion_apidesc->create_lcg_cb) || (!sion_apidesc->free_lcg_cb) || (!sion_apidesc->barrier_cb) || (!sion_apidesc->bcastr_cb) ||
671 (!sion_apidesc->gatherr_cb) || (!sion_apidesc->gathervr_cb) || (!sion_apidesc->scatterr_cb) || (!sion_apidesc->scattervr_cb) ) {
672 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen_mapped: API %s not correctly initalized, aborting",sion_apidesc->name));
676 if ( (grank < 0 ) || (grank >= gsize) ) {
677 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen_mapped: global rank %d not valid (0..%d)",grank,gsize));
683 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen_mapped: problems to alloc gendata, aborting ...\n"));
687 sion_gendata->aid=aid;
688 sion_gendata->apidesc=sion_apidesc;
689 sion_gendata->comm_data_global=gcommgroup;
690 sion_gendata->grank=grank;
691 sion_gendata->gsize=gsize;
692 sion_gendata->lrank=-1;
693 sion_gendata->lsize=-1;
694 sion_gendata->filenumber=-1;
695 sion_gendata->numfiles=-1;
696 sion_gendata->comm_data_local=NULL;
699 if ( ! flags_store ) {
700 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen_mapped: could not parse file mode in %s, aborting ...\n", file_mode));
703 if (flags_store->mask&_SION_FMODE_WRITE) {
708 lprefix = calloc(SION_FILENAME_LENGTH,1);
709 if (lprefix == NULL) {
710 _sion_flags_destroy_store(&flags_store);
711 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen_mapped: cannot allocate temporary memory of size %lu (lprefix), aborting ...\n", (
unsigned long) SION_FILENAME_LENGTH));
713 strcpy(lprefix, fname);
715 }
else if (flags_store->mask&_SION_FMODE_READ) {
720 _sion_flags_destroy_store(&flags_store);
721 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen_mapped: unknown file mode"));
726 DPRINTFP((1,
"sion_generic_paropen_mapped", grank,
"enter parallel mapped open in %s mode\n", file_mode));
728 numFiles, nlocaltasks, globalranks, chunksizes, mapping_filenrs, mapping_lranks,
729 fsblksize, grank, gsize, _SION_INTERNAL_FLAG_NORMAL,
730 fileptr, sion_gendata);
731 sion_gendata->numfiles=*numFiles;
732 DPRINTFP((1,
"sion_generic_paropen_mapped", sion_gendata->grank,
"leave parallel open of %d files in %s mode #tasks=%d sid=%d globalrank=%d\n", sion_gendata->numfiles,
733 file_mode, sion_gendata->lsize, sid, sion_gendata->grank));
735 _sion_flags_destroy_store(&flags_store);
739 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_paropen_mapped: invalid sion_filedesc %d", sid));
743 sion_filedesc->
dataptr=sion_gendata;
747 DPRINTFP((1,
"sion_generic_paropen_mapped", grank,
"lprefix=%s (%x)\n", lprefix,lprefix));
748 if(lprefix) free(lprefix);
750 DPRINTFP((1,
"sion_generic_paropen_mapped", grank,
"leave parallel open of file %s sid=%d\n", fname, sid));
751 DPRINTFTS(-1,
"leave sion_generic_paropen_mapped");
757 int sion_generic_parclose_mapped(
int sid)
759 int grank, gsize, rc;
763 DPRINTFTS(-1,
"enter sion_generic_parclose_mapped");
765 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_parclose_mapped: invalid sion_filedesc %d", sid));
767 sion_gendata=sion_filedesc->
dataptr;
769 grank=sion_gendata->grank;
770 gsize=sion_gendata->gsize;
772 DPRINTFP((1,
"sion_generic_parclose_mapped", grank,
"enter parallel close of sid %d\n", sid));
774 DPRINTFP((1,
"sion_generic_parclose_mapped", grank,
"closing %d file(s)\n", sion_filedesc->
nfiles));
776 rc = _sion_parclose_mapped_generic(sid, grank, gsize,sion_gendata);
782 DPRINTFP((1,
"sion_generic_parclose_mapped", grank,
"leave parallel close of sid %d\n", sid));
783 DPRINTFTS(-1,
"leave sion_generic_parclose_mapped");
789 int _sion_generic_get_and_distribute_info_from_file(
_sion_generic_gendata *sion_gendata,
const char *fname)
791 int sid = -1, ntasks = -1, nfiles = -1, t = 0;
792 int rc = SION_SUCCESS;
794 sion_int32 fsblksize;
796 int mapping_size = -1;
797 sion_int32 *mapping = NULL;
801 sion_apidesc=sion_gendata->apidesc;
803 if(sion_gendata->grank == 0) {
805 DPRINTFP((1,
"_sion_generic_get_and_distribute_info_from_file", sion_gendata->grank,
"before open\n"));
806 sid=
_sion_open_read(fname,_SION_FMODE_READ|_SION_FMODE_ANSI,_SION_READ_MASTER_ONLY_OF_MULTI_FILES,
807 &ntasks,&nfiles,NULL,&fsblksize,NULL,&fileptr);
810 DPRINTFP((1,
"_sion_generic_get_and_distribute_info_from_file", sion_gendata->grank,
"after open\n"));
812 DPRINTFP((1,
"_sion_generic_get_and_distribute_info_from_file", sion_gendata->grank,
"sion file %d files\n", sion_gendata->numfiles));
814 sion_gendata->numfiles=-1;
819 sion_apidesc->bcastr_cb(&sion_gendata->numfiles, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
821 if((sion_gendata->grank == 0) && (sion_gendata->numfiles>1)) {
822 if(mapping_size!=sion_gendata->gsize) {
823 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_generic_get_and_distribute_info_from_file: Incorrect sum of ntasks of files %d <> %d\n", mapping_size, sion_gendata->gsize));
827 if(sion_gendata->numfiles<0) {
828 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_generic_get_and_distribute_info_from_file: could not get numfiles from sion file\n"));
831 if(sion_gendata->numfiles>1) {
832 DPRINTFP((1,
"_sion_generic_get_and_distribute_info_from_file", sion_gendata->grank,
"before scatter\n"));
833 if(sion_gendata->grank==0) {
834 for(t=0;t<mapping_size;t++) {
835 DPRINTFP((1,
"_sion_generic_get_and_distribute_info_from_file", sion_gendata->grank,
" %d -> (%d,%d)\n",t,mapping[t*2],mapping[t*2+1]));
839 sion_apidesc->scatterr_cb(mapping, lpos, sion_gendata->comm_data_global, _SION_INT32, 2, 0);
840 sion_gendata->filenumber=lpos[0];
841 sion_gendata->lrank =lpos[1];
842 DPRINTFP((1,
"_sion_generic_get_and_distribute_info_from_file", sion_gendata->grank,
"after scatter filenum+lrank (%d,%d)\n",sion_gendata->filenumber,sion_gendata->lrank));
844 if(sion_gendata->grank==0) {
845 tasksinfile = (
int *) malloc(sion_gendata->numfiles *
sizeof(
int));
846 if (tasksinfile == NULL) {
847 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_generic_get_and_distribute_info_from_file: Cannot allocate memory for tasksinfile counter vector"));
849 for(t=0;t<sion_gendata->numfiles;t++) tasksinfile[t]=0;
850 for(t=0;t<mapping_size;t++) tasksinfile[ mapping[t*2] ]++;
851 for(t=0;t<mapping_size;t++) mapping[t*2+1]=tasksinfile[ mapping[t*2] ];
853 sion_apidesc->scatterr_cb(mapping, lpos, sion_gendata->comm_data_global, _SION_INT32, 2, 0);
854 sion_gendata->lsize =lpos[1];
855 DPRINTFP((1,
"_sion_generic_get_and_distribute_info_from_file", sion_gendata->grank,
"after scatter lsize (%d, %d of %d)\n",sion_gendata->filenumber, sion_gendata->lrank, sion_gendata->lsize));
857 if(sion_gendata->grank==0) {
858 if(tasksinfile) free(tasksinfile);
863 sion_gendata->filenumber=0;
864 sion_gendata->lrank = sion_gendata->grank;
865 sion_gendata->lsize = sion_gendata->gsize;
866 DPRINTFP((1,
"_sion_generic_get_and_distribute_info_from_file", sion_gendata->grank,
"only one file -> filenumber=%d lRank=%d\n",sion_gendata->filenumber,sion_gendata->lrank));
869 if(sion_gendata->grank == 0) {
871 if (sid>=0) _sion_close_sid(sid);
877 int sion_generic_parreinit(
int sid, sion_int64 chunksize ) {
878 int grank, gsize, rc;
883 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_parreinit: invalid sion_filedesc %d", sid));
885 sion_gendata=sion_filedesc->
dataptr;
887 grank=sion_gendata->grank;
888 gsize=sion_gendata->gsize;
890 DPRINTFP((1,
"sion_generic_parreinit", grank,
"enter parallel reinit of sid %d\n", sid));
894 DPRINTFP((1,
"sion_generic_parreinit", grank,
"leave parallel reinit of sid %d\n", sid));
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)
int _sion_vcdtype(int sid)
int _sion_newvcd(void *data, int type)
int _sion_freevcd(int sid)
#define SION_APIDESCRIPTOR
#define SION_FILEDESCRIPTOR
_sion_flags_store * _sion_parse_flags(const char *flags)
Parse flags and return a flags store with key value pairs.
int sion_generic_paropen(int aid, const char *fname, const char *file_mode, sion_int64 *chunksize, sion_int32 *fsblksize, void *gcommgroup, int grank, int gsize, int *filenumber, int *numfiles, const int *lrank, const int *lsize, FILE **fileptr, char **newfname)
Open a sion file a generic interface.
int _sion_generic_free_apidesc(_sion_generic_apidesc *sion_apidesc)
free apidesc structure
int _sion_generic_free_gendata(_sion_generic_gendata *sion_gendata)
Free sion gendata description.
int _sion_generic_init_apidesc(_sion_generic_apidesc *sion_apidesc)
Initialize the sion api description.
int _sion_generic_update_api_level(_sion_generic_apidesc *sion_apidesc)
Update API level.
_sion_generic_gendata * _sion_generic_alloc_gendata(void)
Allocates memory for internal sion api data structure needed for each SION file.
int _sion_generic_init_gendata(_sion_generic_gendata *sion_gendata)
Initialize the sion file description.
_sion_generic_apidesc * _sion_generic_alloc_apidesc(void)
Allocates memory for internal sion api desc structure.
int _sion_parclose_generic(int sid, int rank, int ntasks, int mapping_size, sion_int32 *mapping, int flag, _sion_generic_gendata *sion_gendata, _sion_generic_buddy *buddy_data)
Internal function to close parallel opened SION file.
int _sion_generic_renumber_collmsa(_sion_generic_gendata *comm, _sion_flags_store *flags)
Splits a Communicator in numfiles different communicators.
int _sion_parreinit_generic(int sid, sion_int64 chunksize, int rank, int ntasks, _sion_generic_gendata *sion_gendata)
change chunksize for an already opened SION file (write)
int _sion_paropen_generic_one_file(int sid, char *fname, _sion_flags_store *flags_store, char *prefix, int *numFiles, int *filenumber, sion_int64 *chunksize, sion_int32 *fsblksize, int rank, int ntasks, int *globalrank, int flag, FILE **fileptr, _sion_generic_gendata *sion_gendata, _sion_generic_buddy *buddy_data)
Generic parallel open of one direct access file.
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.
char * _sion_get_multi_filename(const char *fname, int filenumber)
generates the multi filename
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
Sion File Descriptor Structure.