27 #include <sys/types.h> 33 #include "sion_debug.h" 34 #include "sion_internal.h" 36 #include "sion_filedesc.h" 38 #include "sion_flags.h" 45 #include "sion_ompi_internal_gen.h" 46 #include "sion_ompi_cb_gen.h" 47 #include "sion_lock.h" 51 int _sion_ompi_api_aid = -1;
52 static omp_lock_t _sion_ompi_lock_data;
54 static void * __ompi_thread_sync_struct;
56 int _sion_ompi_user_lock(
void * data) {
58 omp_set_lock(&_sion_ompi_lock_data);
61 int _sion_ompi_user_unlock(
void * data) {
63 omp_unset_lock(&_sion_ompi_lock_data);
87 #define DFUNCTION "sion_paropen_ompi" 88 int sion_paropen_ompi(
const char* fname,
89 const char* file_mode,
92 const MPI_Comm* lComm,
93 sion_int64* chunksize,
94 sion_int32* fsblksize,
102 int filenumber, gRank, lRank, lSize, gSize;
106 _ompi_api_commdata *gen_gcomm;
107 _ompi_api_commdata *gen_lcomm=NULL;
109 int num_threads, thread_num;
110 __ompi_thread_sync *thread_sync;
114 thread_num = omp_get_thread_num();
119 _sion_debug_set_query_thread_num_function(omp_get_thread_num);
120 omp_init_lock(&_sion_ompi_lock_data);
123 MPI_Comm_size(gComm, &gSize);
124 MPI_Comm_rank(gComm, &gRank);
125 num_threads = omp_get_num_threads();
127 thread_sync = malloc(
sizeof(__ompi_thread_sync));
128 if(thread_sync==NULL) (_sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_ABORT,
"sion_paropen_ompi: cannot allocate struct of size %lu (__ompi_thread_sync), aborting...",
129 sizeof(__ompi_thread_sync)));
131 thread_sync->grank_master_mpi = gRank;
132 thread_sync->gsize_mpi = gSize;
133 thread_sync->grank_master_ompi = _sion_map_rank_mpi_to_ompi(gRank,num_threads,thread_num);
134 thread_sync->gsize_ompi = _sion_get_size_ompi(gSize,num_threads);
135 thread_sync->num_threads = num_threads;
136 thread_sync->numFiles = *numFiles;
137 __ompi_thread_sync_struct = thread_sync;
146 thread_sync = (__ompi_thread_sync *) __ompi_thread_sync_struct;
148 DPRINTFP((1,
"sion_paropen_ompi", thread_sync->grank_master_ompi+thread_num,
"thread %d enters parallel open of file %s\n", thread_num, fname));
153 return(_sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_ABORT,
"sion_paropen_ompi: No lComm variable given"));
155 if (numFiles == NULL) {
156 return(_sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_ABORT,
"sion_paropen_ompi: No numFiles variable given"));
159 if ( ! flags_store ) {
160 return(_sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: could not parse file mode in %s, aborting ...\n", file_mode));
167 if(_sion_ompi_api_aid<0) _sion_ompi_api_aid=_sion_register_callbacks_ompi();
171 gen_gcomm = (_ompi_api_commdata *) malloc(
sizeof(_ompi_api_commdata));
172 if (gen_gcomm != NULL) {
173 gen_gcomm->commset=0;
175 gen_gcomm->rank=thread_sync->grank_master_ompi+thread_num;
176 gen_gcomm->size=thread_sync->gsize_ompi;
177 gen_gcomm->num_threads=thread_sync->num_threads;
178 gen_gcomm->thread_num=thread_num;
179 gen_gcomm->lcommgroup=NULL;
181 _sion_flags_destroy_store(flags_store);
182 return(_sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
183 "cannot allocate ompi internal data structure of size %lu (_omp_api_commdata), aborting ...\n",
184 (
unsigned long)
sizeof(_ompi_api_commdata)));
190 gen_gcomm->comm=gComm;
200 if (flags_store->mask&_SION_FMODE_WRITE) {
204 if (*numFiles <= 0) {
205 gen_lcomm = (_ompi_api_commdata *) malloc(
sizeof(_ompi_api_commdata));
206 if (gen_lcomm != NULL) {
207 gen_lcomm->commset=1;
208 gen_lcomm->commcreated=0;
210 gen_lcomm->num_threads=gen_gcomm->num_threads;
211 gen_lcomm->thread_num=thread_num;
212 gen_gcomm->lcommgroup=gen_lcomm;
214 _sion_flags_destroy_store(flags_store);
215 return(_sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate ompi internal data structure of size %lu (_ompi_api_commdata), aborting ...\n",
216 (
unsigned long)
sizeof(_ompi_api_commdata)));
223 if (*numFiles <= 0) {
226 rc = _sion_get_info_from_splitted_comm_ompi(gComm, *lComm, numFiles, &filenumber, &lRank, &lSize);
227 if(rc != SION_SUCCESS) _sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_ompi: error in _sion_get_info_from_splitted_comm_ompi");
228 DPRINTFP((1, DFUNCTION, gRank,
"%d local communicators found\n", *numFiles));
230 gen_lcomm->comm=*lComm;
234 rc = _sion_gen_info_from_gcomm_ompi(*numFiles, gComm, &filenumber, &lRank, &lSize);
235 if(rc != SION_SUCCESS) _sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_ompi: error in _sion_gen_info_from_gcomm_ompi");
236 DPRINTFP((1,
"sion_paropen_ompi", gRank,
"Global communicator divided in %d local communicators\n", *numFiles));
239 thread_sync->filenumber = filenumber;
240 thread_sync->numFiles = *numFiles;
241 thread_sync->lrank_master_mpi = lRank;
242 thread_sync->lsize_mpi = lSize;
243 thread_sync->lrank_master_ompi = _sion_map_rank_mpi_to_ompi(lRank,num_threads,thread_num);
244 thread_sync->lsize_ompi = _sion_get_size_ompi(lSize,num_threads);
254 gRank = thread_sync->grank_master_ompi+thread_num;
255 gSize = thread_sync->gsize_ompi;
256 lRank = thread_sync->lrank_master_ompi+thread_num;
257 lSize = thread_sync->lsize_ompi;
258 filenumber = thread_sync->filenumber;
259 *numFiles = thread_sync->numFiles;
261 if (gen_lcomm != NULL) {
262 gen_lcomm->rank=thread_sync->lrank_master_ompi+thread_num;
263 gen_lcomm->size=thread_sync->lsize_ompi;
266 }
else if (flags_store->mask&_SION_FMODE_READ) {
270 gRank = thread_sync->grank_master_ompi+thread_num;
271 gSize = thread_sync->gsize_ompi;
278 _sion_flags_destroy_store(flags_store);
279 return(_sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_ompi: unknown file mode"));
281 _sion_flags_destroy_store(flags_store);
284 DPRINTFP((1, DFUNCTION, gRank,
"enter parallel open of %d files (current name %s) in %s mode\n", *numFiles, fname, file_mode));
285 DPRINTFP((2, DFUNCTION, gRank,
"enter parallel parameters: grank=%d gsize=%d fnum=%d numfiles=%d lrank=%d lsize=%d chunksize=%d\n",
286 gRank, gSize,filenumber, *numFiles, lRank, lSize, (
int) *chunksize));
287 sid =
sion_generic_paropen(_sion_ompi_api_aid, fname, file_mode, chunksize, fsblksize, gen_gcomm,
288 gRank, gSize, &filenumber, numFiles, &lRank, &lSize,
290 DPRINTFP((1, DFUNCTION, gRank,
"leave parallel open of %d files in %s mode #tasks=%d sid=%d\n", *numFiles, file_mode, lSize, sid));
293 if ( sid == SION_ID_NOT_VALID ) {
294 return(_sion_errorprint_ompi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: invalid return code from internal open %d", rc));
300 DPRINTFP((1,
"sion_paropen_ompi", gRank,
"leave parallel open of file %s sid=%d globalrank=%d\n", fname, sid,*globalrank));
313 int sion_parclose_ompi(
int sid)
317 DPRINTFP((1,
"sion_parclose_ompi", _SION_DEFAULT_RANK,
"enter parallel close of sid %d\n", sid));
319 rc = sion_generic_parclose(sid);
321 DPRINTFP((1,
"sion_parclose_ompi", _SION_DEFAULT_RANK,
"leave parallel close of sid %d rc=%d\n", sid, rc));
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_lock_register_lock_callbacks(int lock(void *), int unlock(void *), void *lock_data)
Function which registers callback funtions for lock and unlock internal access to shared data structu...
_sion_flags_store * _sion_parse_flags(const char *flags)
Parse flags and return a flags store with key value pairs.