14 #define _XOPEN_SOURCE 700
25 #include <sys/types.h>
34 #include "sion_error_handler.h"
41 #include "sion_hints.h"
48 #define DFUNCTION "_sion_calculate_set_alignment"
49 sion_int64 _sion_calculate_set_alignment(
_sion_filedesc *sion_filedesc,
int t) {
50 sion_int64 lsize=SION_SIZE_NOT_VALID;
61 DPRINTFP((2048,
DFUNCTION, _SION_DEFAULT_RANK,
"old file version (<=3) task=%d lsize=%ld\n", t, (
long) lsize));
69 DPRINTFP((2048,
DFUNCTION, _SION_DEFAULT_RANK,
"new file version (>3) task=%d lsize=%ld, WRITE chunksize set\n", t, (
long) lsize));
72 DPRINTFP((2048,
DFUNCTION, _SION_DEFAULT_RANK,
"new file version (>3) task=%d lsize=%ld, READ no align\n", t, (
long) lsize));
86 #define DFUNCTION "_sion_get_size_metadatablock1"
93 firstsize = strlen(
SION_ID) + 8 *
sizeof(sion_int32)
95 + SION_FILENAME_LENGTH
96 + sion_filedesc->
ntasks *
sizeof(sion_int64) + sion_filedesc->
ntasks *
sizeof(sion_int64)
97 +
sizeof(sion_int32) + 3 *
sizeof(sion_int64);
110 #define DFUNCTION "_sion_calculate_startpointers"
111 int _sion_calculate_startpointers(
_sion_filedesc *sion_filedesc )
114 int rc = SION_SUCCESS;
118 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"enter ntasks=%d fsblksize=%d chunksizes[0]=%lld\n",
121 firstsize=_sion_get_size_metadatablock1(sion_filedesc);
123 #ifdef WFLARGEMETABLOCK
124 if (firstsize<4*1024*1024) firstsize=4*1024*1024;
127 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"firstsize=%d\n", firstsize));
134 DPRINTFP((2048,
DFUNCTION, _SION_DEFAULT_RANK,
" startpointers[%2d]=%10lld (%10.4fMB) chunksizes[%2d]=%8lld\n",
137 for (i = 1; i < sion_filedesc->
ntasks; i++) {
139 lsize=_sion_calculate_set_alignment(sion_filedesc,i-1);
145 DPRINTFP((2048,
DFUNCTION, _SION_DEFAULT_RANK,
" startpointers[%2d]=%10lld (%10.4fMB) chunksizes[%2d]=%8lld chunksizes[%2d]=%8lld\n",
149 lsize=_sion_calculate_set_alignment(sion_filedesc,sion_filedesc->
ntasks - 1);
152 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"leave globalskip is %lld\n", sion_filedesc->
globalskip));
165 #define DFUNCTION "_sion_calculate_num_collector"
167 int rc = SION_SUCCESS;
168 int max_num_collectors;
172 max_num_collectors = (int) (collstat->gsize/sion_filedesc->
fsblksize);
173 if(collstat->gsize%sion_filedesc->
fsblksize>0) max_num_collectors++;
174 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"max_num_collectors=%d\n", max_num_collectors));
178 *num_collectors = (int) (sion_filedesc->
ntasks/sion_filedesc->
collsize);
179 if(sion_filedesc->
ntasks%sion_filedesc->
collsize>0) (*num_collectors)++;
182 if(*num_collectors > max_num_collectors) *num_collectors=max_num_collectors;
184 DPRINTFP((32,
DFUNCTION, _SION_DEFAULT_RANK,
"user given collsize %d -> set num_collectors to %d\n",
185 sion_filedesc->
collsize,*num_collectors));
189 *num_collectors = max_num_collectors;
192 if(*num_collectors>sion_filedesc->
ntasks) *num_collectors=sion_filedesc->
ntasks;
195 if ((sion_filedesc->
ntasks>=512) && (*num_collectors>32)) *num_collectors=32;
196 else if((sion_filedesc->
ntasks>=256) && (*num_collectors>16)) *num_collectors=16;
197 else if((sion_filedesc->
ntasks>=128) && (*num_collectors>8)) *num_collectors=8;
198 else if((sion_filedesc->
ntasks>=64) && (*num_collectors>8)) *num_collectors=8;
199 else if((sion_filedesc->
ntasks>=32) && (*num_collectors>8)) *num_collectors=8;
200 else if((sion_filedesc->
ntasks>=16) && (*num_collectors>4)) *num_collectors=4;
204 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"SIONlib heuristic collsize=%d num_collectors=%d\n",
205 sion_filedesc->
collsize, *num_collectors));
209 collstat->avg_data_per_collector = (
210 (sion_int64) (collstat->gsize / *num_collectors)
215 if((collstat->gsize / *num_collectors)%sion_filedesc->
fsblksize>0) collstat->avg_data_per_collector+=sion_filedesc->
fsblksize;
216 DPRINTFP((32,
DFUNCTION, _SION_DEFAULT_RANK,
"avg_data_per_collectors=%ld\n",(
long) collstat->avg_data_per_collector));
229 #define DFUNCTION "_sion_calculate_startpointers_collective"
230 int _sion_calculate_startpointers_collective(
_sion_filedesc *sion_filedesc )
233 int rc = SION_SUCCESS;
234 int i, firstsize, num_collectors, numsender, lastcoll, s;
236 sion_int64 currentsize, aligned_size, startpointer;
239 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"enter ntasks=%d fsblksize=%d chunksizes[0]=%lld\n",
243 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
244 "_sion_calculate_startpointers_collective: files with old sionlib file format (<3) can not be read by collective calls, please use standard read calls, aborting ...\n"));
248 collstat=_sion_create_and_init_collstat(sion_filedesc);
251 collstat->firstsize=firstsize=_sion_get_size_metadatablock1(sion_filedesc);
252 _sion_calculate_num_collector(sion_filedesc, collstat, &num_collectors);
253 collstat->req_num_collectors=num_collectors;
255 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"firstsize=%d collsize=%d num_collectors=%d\n",
256 firstsize, sion_filedesc->
collsize, num_collectors));
258 numsender=1;lastcoll=0;
262 for (i = 1; i < sion_filedesc->
ntasks; i++) {
263 if( (currentsize+sion_filedesc->
all_chunksizes[i]<=collstat->avg_data_per_collector) ||
271 for(s=lastcoll;s<i;s++) {
278 aligned_size = ((sion_int64) currentsize/sion_filedesc->
fsblksize) * sion_filedesc->
fsblksize;
281 DPRINTFP((128,
DFUNCTION, _SION_DEFAULT_RANK,
" align chunksizes[%2d]=%8lld + %lld\n",
282 i-1, sion_filedesc->
all_chunksizes[i-1], aligned_size-currentsize));
288 numsender = 1; lastcoll= i; currentsize = sion_filedesc->
all_chunksizes[i];
294 aligned_size = ((sion_int64) currentsize/sion_filedesc->
fsblksize) * sion_filedesc->
fsblksize;
296 DPRINTFP((128,
DFUNCTION, _SION_DEFAULT_RANK,
" align chunksizes[%2d]=%8lld + %lld\n",
302 for(s=lastcoll;s<sion_filedesc->
ntasks;s++) {
311 startpointer = (firstsize % sion_filedesc->
fsblksize == 0) ? firstsize : ((firstsize / sion_filedesc->
fsblksize) + 1) * sion_filedesc->
fsblksize;
314 for (i = 0; i < sion_filedesc->
ntasks; i++) {
322 _sion_update_collstat(collstat,sion_filedesc);
323 _sion_print_collstat(collstat, sion_filedesc);
326 _sion_debugprint_collstat(collstat, sion_filedesc);
328 _sion_destroy_collstat(collstat);
330 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"leave globalskip is %lld\n", sion_filedesc->
globalskip));
335 int _sion_calculate_startpointers_collective_msa(
_sion_filedesc *fd)
337 DPRINTFP((2, __func__, _SION_DEFAULT_RANK,
"enter ntasks=%d fsblksize=%d chunksizes[0]=%lld\n", fd->
ntasks, fd->
fsblksize, fd->
all_chunksizes[0]));
340 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
341 "_sion_calculate_startpointers_collective_msa: files with old sionlib file format (<3) can not be read by collective calls, please use standard read calls, aborting ...\n"));
344 sion_int64 firstsize = _sion_get_size_metadatablock1(fd);
346 for (
int i = 0; i < fd->
ntasks; i++) {
362 DPRINTFP((2, __func__, _SION_DEFAULT_RANK,
"chunk: %d, collector: %d, collsize: %d, start: %lld, chunksize: %lld\n", i, fd->
all_coll_collector[i], fd->
all_coll_collsize[i], fd->
all_startpointers[i], fd->
all_chunksizes[i]));
366 DPRINTFP((2, __func__, _SION_DEFAULT_RANK,
"leave globalskip is %lld\n", fd->
globalskip));
378 #define DFUNCTION "_sion_calculate_startpointers_collective_merge"
379 int _sion_calculate_startpointers_collective_merge(
_sion_filedesc *sion_filedesc )
382 int rc = SION_SUCCESS;
383 int i, firstsize, num_collectors, numsender, lastcoll, s;
385 sion_int64 currentsize, newsize, aligned_size, startpointer;
388 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"enter ntasks=%d fsblksize=%d chunksizes[0]=%lld\n",
392 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
393 "_sion_calculate_startpointers_collective: files with old sionlib file format (<3) can not be read by collective calls, please use standard read calls, aborting ...\n"));
397 collstat=_sion_create_and_init_collstat(sion_filedesc);
400 collstat->firstsize=firstsize=_sion_get_size_metadatablock1(sion_filedesc);
401 _sion_calculate_num_collector(sion_filedesc, collstat, &num_collectors);
402 collstat->req_num_collectors=num_collectors;
404 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"firstsize=%d collsize=%d num_collectors=%d\n",
405 firstsize, sion_filedesc->
collsize, num_collectors));
407 numsender=1;lastcoll=0;
410 DPRINTFP((128,
DFUNCTION, _SION_DEFAULT_RANK,
" currentsize=%lld chunksizes[%2d]=%8lld\n",
414 for (i = 1; i < sion_filedesc->
ntasks; i++) {
415 if( (currentsize+sion_filedesc->
all_chunksizes[i]<=collstat->avg_data_per_collector) ||
420 DPRINTFP((128,
DFUNCTION, _SION_DEFAULT_RANK,
" currentsize=%lld chunksizes[%2d]=%8lld\n",
430 aligned_size = ((sion_int64) newsize/sion_filedesc->
fsblksize) * sion_filedesc->
fsblksize;
433 DPRINTFP((128,
DFUNCTION, _SION_DEFAULT_RANK,
" resize chunksizes[%2d]=%8lld + %lld\n",
437 for(s=lastcoll+1;s<i;s++) {
441 _sion_calculate_set_alignment(sion_filedesc,s);
450 for(s=lastcoll;s<i;s++) {
456 numsender = 1; lastcoll= i; currentsize = sion_filedesc->
all_chunksizes[i];
465 aligned_size = ((sion_int64) newsize/sion_filedesc->
fsblksize) * sion_filedesc->
fsblksize;
468 DPRINTFP((128,
DFUNCTION, _SION_DEFAULT_RANK,
" resize chunksizes[%2d]=%8lld + %lld\n",
473 for(s=lastcoll+1;s<i;s++) {
477 _sion_calculate_set_alignment(sion_filedesc,s);
485 for(s=lastcoll;s<sion_filedesc->
ntasks;s++) {
494 startpointer = (firstsize % sion_filedesc->
fsblksize == 0) ? firstsize : ((firstsize / sion_filedesc->
fsblksize) + 1) * sion_filedesc->
fsblksize;
497 for (i = 0; i < sion_filedesc->
ntasks; i++) {
505 _sion_update_collstat(collstat,sion_filedesc);
506 _sion_print_collstat(collstat, sion_filedesc);
509 _sion_debugprint_collstat(collstat, sion_filedesc);
511 _sion_destroy_collstat(collstat);
513 DPRINTFP((2,
DFUNCTION, _SION_DEFAULT_RANK,
"leave globalskip is %lld\n", sion_filedesc->
globalskip));
#define SION_FILEMODE_WRITE
#define SION_CAPABILITY_ONLY_SENDER
#define DFUNCTION
Calculates the size of the first meta data block.
Sion File Descriptor Structure.
sion_int32 * all_coll_collsize
sion_int32 * all_coll_collector
sion_int64 * all_chunksizes
sion_int32 * all_coll_capability
sion_int64 * all_startpointers