22 #include <sys/types.h> 37 int _sion_generic_collective_process_write(
const void *data, sion_int64 *spec,
int sid );
38 int _sion_generic_collective_process_read(
void *data, sion_int64 *spec,
int sid );
41 #define DFUNCTION "sion_coll_fwrite" 42 size_t sion_coll_fwrite(
const void *data,
size_t size,
size_t nitems,
int sid) {
46 sion_int64 bwrote=0, spec[2], ownnewposition, items_wrote;
47 int rc_own=SION_STD_SUCCESS,rc_cb=SION_STD_SUCCESS;
48 int collector, firstsender, lastsender;
51 return(
_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"sion_coll_fwrite: invalid sion_filedesc %d", sid));
53 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"enter usecoll=%d collector=%d collsize=%d (%d tasks, %d files)\n",
56 sion_gendata=sion_filedesc->
dataptr;
57 sion_apidesc=sion_gendata->apidesc;
66 return(_sion_coll_fwrite_merge(data,size,nitems,sid));
75 return(
_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"sion_coll_fwrite: collsize=%d <= 0, returning ...\n", (
int) sion_filedesc->
collsize));
80 firstsender=collector+1;
81 lastsender=collector+sion_filedesc->
collsize-1;
82 if(lastsender>sion_filedesc->
ntasks) lastsender=sion_filedesc->
ntasks-1;
83 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"collector=%d collsize=%d firstsender=%d lastsender=%d\n",
84 collector, sion_filedesc->
collsize, firstsender, lastsender));
88 _sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"could not ensure free space for this block, returning %d ...\n", sid);
97 rc_own=_sion_generic_collective_process_write(data,spec,sid);
102 if(!sion_apidesc->gather_execute_cb ) {
103 return(
_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"sion_coll_fwrite: API %s not correctly initalized, collective I/O calls missing, aborting",sion_apidesc->name));
105 rc_cb=sion_apidesc->gather_execute_cb(data,spec,2, sion_filedesc->
fsblksize,
106 sion_gendata->comm_data_local,collector,firstsender,lastsender,sid,
107 _sion_generic_collective_process_write);
124 if( (rc_own == SION_STD_SUCCESS) && (rc_cb == SION_STD_SUCCESS) ) {
130 items_wrote = size ? bwrote / size : 0;
132 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"leave usecoll=%d collector=%d collsize=%d (%d tasks, %d files) rc=%d\n",
139 #define DFUNCTION "sion_coll_fread" 140 size_t sion_coll_fread(
void *data,
size_t size,
size_t nitems,
int sid) {
144 sion_int64 bread=-1, spec[2], ownnewposition, items_read;
145 int rc_own=SION_STD_SUCCESS,rc_cb=SION_STD_SUCCESS;
146 int collector, firstsender, lastsender;
149 return(
_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"sion_coll_fread: invalid sion_filedesc %d", sid));
151 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"enter usecoll=%d collector=%d collsize=%d (%d tasks, %d files)\n",
154 sion_gendata=sion_filedesc->
dataptr;
155 sion_apidesc=sion_gendata->apidesc;
167 return(
_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"sion_coll_fread: collsize=%d <= 0, returning ...\n",
172 collector=(int) sion_filedesc->
collector;
173 firstsender=collector+1;
174 lastsender=sion_filedesc->
rank+sion_filedesc->
collsize-1;
175 if(lastsender>sion_filedesc->
ntasks) lastsender=sion_filedesc->
ntasks-1;
180 _sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"early eof found for this block, returning %d ...\n", sid);
194 rc_own=_sion_generic_collective_process_read(data,spec,sid);
200 if(!sion_apidesc->execute_scatter_cb ) {
202 "sion_coll_fread: API %s not correctly initalized, collective I/O calls missing, aborting",sion_apidesc->name));
204 rc_cb=sion_apidesc->execute_scatter_cb(data,spec,2, sion_filedesc->
fsblksize,
205 sion_gendata->comm_data_local,collector,firstsender,lastsender,sid,
206 _sion_generic_collective_process_read);
222 if( (rc_own == SION_STD_SUCCESS) && (rc_cb == SION_STD_SUCCESS) ) {
228 items_read = size ? bread / size : 0;
230 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"leave usecoll=%d collector=%d collsize=%d (%d tasks, %d files) rc=%d\n",
239 #define DFUNCTION "_sion_generic_collective_process_write" 240 int _sion_generic_collective_process_write(
const void *data, sion_int64 *spec,
int sid ) {
242 int rc=SION_STD_SUCCESS;
243 sion_int64 bwrote=0, destpos, bytestowrite;
245 return(
_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_generic_collective_process_write: invalid sion_filedesc %d", sid));
247 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"enter spec[0]=%d spec[1]=%d sid=%d\n", (
int) spec[0],(
int) spec[1],sid));
251 bytestowrite=spec[1];
252 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"currentpos=%d destpos=%d\n", (
int) sion_filedesc->
currentpos,(
int) destpos));
259 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"collector start to write data of size %lld at position %lld\n",
260 (
long long) bytestowrite, (
long long) destpos));
262 if(bwrote != bytestowrite) {
263 return(
_sion_errorprint(SION_STD_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_generic_collective_process_write: problems writing data ...\n"));
268 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"collector wrote data block (bwrote=%d) of size %ld new pos %lld, %lld\n",
277 #define DFUNCTION "_sion_generic_collective_process_read" 278 int _sion_generic_collective_process_read(
void *data, sion_int64 *spec,
int sid ) {
280 int rc=SION_STD_SUCCESS;
281 sion_int64 bread=0, destpos, bytestoread;
284 return(
_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_generic_collective_process_read: invalid sion_filedesc %d", sid));
286 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"enter spec[0]=%d spec[1]=%d sid=%d\n", (
int) spec[0],(
int) spec[1],sid));
297 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"collector start to read data of size %lld at position %lld\n",
298 (
long long) bytestoread, (
long long) destpos));
300 if(bread != bytestoread) {
301 return(
_sion_errorprint(SION_STD_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_generic_collective_process_read: problems reading data ...\n"));
305 ONLY_DEBUG(
char *p=data;)
306 DPRINTFP((128,
DFUNCTION, _SION_DEFAULT_RANK,
"data[0]=%c data[%d]=%c\n",(
char) p[0], (
int) bytestoread, (
char) p[bytestoread-1]));
311 DPRINTFP((4,
DFUNCTION, _SION_DEFAULT_RANK,
"collector read data block (bread=%d) of size %ld new pos %lld, %lld\n",
330 #define DFUNCTION "_sion_coll_check_env" 335 int rc = SION_SUCCESS, numcoll;
349 fprintf(stderr,
"collective statistics: SION_COLLSIZE=%11d\n",sion_filedesc->
collsize);
354 if(numcoll>sion_filedesc->
ntasks) numcoll=sion_filedesc->
ntasks;
359 fprintf(stderr,
"collective statistics: SION_COLLNUM=%11d\n",numcoll);
360 fprintf(stderr,
"collective statistics: collsize=%11d\n",sion_filedesc->
collsize);
373 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"usecoll=%d collsize=%d (%d tasks, %d files) colldebug=%d\n", sion_filedesc->
usecoll, sion_filedesc->
collsize,sion_filedesc->
ntasks,sion_filedesc->
nfiles,sion_filedesc->
colldebug));
int sion_feof(int sid)
Function that indicates whether the end of file is reached for this task.
sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Write data to file.
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
Sion File Descriptor Structure.
int sion_ensure_free_space(int sid, sion_int64 bytes)
Funtion to ensure that enough space is available for writing.
sion_int64 _sion_file_read(void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Read data from file.
int _sion_vcdtype(int sid)
sion_int32 fileptr_exported
char * _sion_getenv(const char *name)
size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid)
Write data to sion file.
void * _sion_vcdtovcon(int sid)
int _sion_errorprint(int rc, int level, const char *format,...)
Internal SION error.
#define SION_FILEDESCRIPTOR
#define DFUNCTION
checks if environment variables are set to use collective I/O SION_COLLSIZE = -1 -> number of collect...
size_t sion_fread(void *data, size_t size, size_t nitems, int sid)
Read data from sion file.
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.