17 #define _XOPEN_SOURCE 700
27 #include <sys/types.h>
36 #include "sion_error_handler.h"
54 sion_int32 _sion_omp_api_aid = -1;
55 static omp_lock_t _sion_omp_lock_data;
57 int _sion_omp_user_lock(
void * data) {
59 omp_set_lock(&_sion_omp_lock_data);
62 int _sion_omp_user_unlock(
void * data) {
64 omp_unset_lock(&_sion_omp_lock_data);
85 int sion_paropen_omp(
const char *fname,
86 const char *file_mode,
87 sion_int64 *chunksize,
88 sion_int32 *fsblksize,
93 int sid = SION_ID_UNDEF;
94 int filenumber, num_threads, thread_num;
95 int numFiles=1,gtasks, gRank, lRank, lSize;
96 _omp_api_commdata *gen_gcomm;
99 thread_num = omp_get_thread_num();
100 num_threads = omp_get_num_threads();
104 _sion_debug_set_query_thread_num_function(omp_get_thread_num);
105 _sion_error_set_query_thread_num_function(omp_get_thread_num);
106 omp_init_lock(&_sion_omp_lock_data);
113 DPRINTFP((1,
"sion_paropen_omp", thread_num,
"enter parallel open of file %s\n", fname));
116 if ( ! flags_store ) {
117 return(_sion_errorprint_omp(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
118 "sion_paropen_omp: could not parse file mode in %s, aborting ...\n", file_mode));
121 if (flags_store->mask&_SION_FMODE_WRITE) {
123 *globalrank = thread_num;
125 if (_sion_flags_get(flags_store,
"collmsa")) {
126 _sion_flags_destroy_store(&flags_store);
127 return _sion_errorprint(SION_ID_NOT_VALID, _SION_ERROR_ABORT,
"sion_paropen_omp: MSA aware collective operations not supported with OpenMP API, aborting ...\n");
129 _sion_flags_destroy_store(&flags_store);
134 if(_sion_omp_api_aid<0) _sion_omp_api_aid=_sion_register_callbacks_omp();
138 gen_gcomm = (_omp_api_commdata *) malloc(
sizeof(_omp_api_commdata));
139 if (gen_gcomm == NULL) {
140 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
141 "cannot allocate omp internal data structure of size %lu (_omp_api_commdata), aborting ...\n",
142 (
unsigned long)
sizeof(_omp_api_commdata)));
144 gen_gcomm->commset=1;
145 gen_gcomm->thread_num=thread_num;
146 gen_gcomm->num_threads=num_threads;
149 _sion_omp_barrier_cb(gen_gcomm);
152 lRank=gRank=thread_num;
153 lSize=gtasks=num_threads;
157 DPRINTFP((1,
"sion_paropen_omp", gRank,
"enter parallel open of %d files (current name %s) in %s mode\n", numFiles, fname, file_mode));
158 sid =
sion_generic_paropen(_sion_omp_api_aid, fname, file_mode, chunksize, fsblksize, gen_gcomm, gRank, gtasks,
159 &filenumber, &numFiles, &lRank, &lSize, fileptr, newfname);
160 DPRINTFP((1,
"sion_paropen_omp", gRank,
"leave parallel open of %d files in %s mode #tasks=%d sid=%d\n", numFiles, file_mode, lSize, sid));
164 if ( sid == SION_ID_NOT_VALID ) {
165 return(_sion_errorprint_omp(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_omp: invalid return code from internal open %d", sid));
168 DPRINTFP((1,
"sion_paropen_omp", thread_num,
"leave parallel open of file %s sid=%d\n", fname, sid));
179 int sion_parclose_omp(
int sid)
181 int rc = SION_SUCCESS;
182 ONLY_DEBUG(
int thread_num;)
186 return(_sion_errorprint_omp(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_parclose_omp: invalid sion_filedesc %d", sid));
189 ONLY_DEBUG(thread_num = omp_get_thread_num();)
191 if(omp_get_num_threads()!=sion_filedesc->ntasks){
192 return(_sion_errorprint_omp(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
193 "sion_parclose_omp: invalid number of OpenMP threads, %d <> %d",
194 omp_get_num_threads(), sion_filedesc->ntasks));
197 DPRINTFP((1,
"sion_parclose_omp", thread_num,
"enter parallel close of sid %d\n", sid));
198 DPRINTFP((1,
"sion_parclose_omp", thread_num,
"closing %d file(s)\n", sion_filedesc->nfiles));
200 rc = sion_generic_parclose(sid);
202 DPRINTFP((1,
"sion_parclose_omp", thread_num,
"leave parallel close of sid %d rc=%d\n", sid, rc));
callback wrappers for OMP thread safe fd manipulation
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...
void * _sion_vcdtovcon(int sid)
int _sion_vcdtype(int sid)
#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.
Sion File Descriptor Structure.