SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
sion_metadata.c
Go to the documentation of this file.
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2019 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
14 #define _XOPEN_SOURCE 700
15 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <time.h>
20 #include <assert.h>
21 
22 #include "sion.h"
23 #include "sion_debug.h"
24 #include "sion_error_handler.h"
25 #include "sion_printts.h"
26 #include "sion_internal.h"
27 #include "sion_file.h"
28 #include "sion_filedesc.h"
29 #include "sion_metadata.h"
30 
31 #define DFUNCTION "_sion_write_header"
39 {
40  int rc = SION_SUCCESS;
41  size_t nwrite;
42  char *lprefix;
43 
44  char *sionstr = SION_ID;
45  sion_uint32 endianness_writeval;
46  sion_int32 sion_version, sion_version_patchlevel, sion_fileformat_version;
47 
48 
49  DPRINTFP((2, DFUNCTION, -1, "enter write\n"));
50  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
51 
52  /* SIONSTR */
53  nwrite = _sion_file_write(sionstr, strlen(sionstr), sion_filedesc->fileptr);
54  if (nwrite != strlen(sionstr)) {
55  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(SIONID) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
56  }
57  DPRINTFP((32, DFUNCTION, -1, " wrote sionstr nwrite=%lu\n", (unsigned long) nwrite));
58 
59  /* endianness */
60  endianness_writeval = sion_filedesc->endianness;
61  nwrite = _sion_file_write(&endianness_writeval, sizeof(endianness_writeval), sion_filedesc->fileptr);
62  if (nwrite != sizeof(endianness_writeval)) {
63  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(endianness) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
64  }
65  DPRINTFP((32, DFUNCTION, -1, " wrote endianness 0x%x nwrite=%lu\n", endianness_writeval, (unsigned long) nwrite));
66 
67  /* VERSION Information */
68  sion_version = 1000 * SION_MAIN_VERSION + SION_SUB_VERSION;
69  sion_version_patchlevel = SION_VERSION_PATCHLEVEL;
70  sion_fileformat_version = SION_FILEFORMAT_VERSION;
71 
72  nwrite = _sion_file_write(&sion_version, sizeof(sion_version), sion_filedesc->fileptr);
73  if (nwrite != sizeof(sion_version)) {
74  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(sion_version) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
75  }
76  DPRINTFP((32, DFUNCTION, -1, " wrote sion_version %ld nwrite=%lu\n", sion_version, (unsigned long) nwrite));
77 
78  nwrite = _sion_file_write(&sion_version_patchlevel, sizeof(sion_version_patchlevel), sion_filedesc->fileptr);
79  if (nwrite != sizeof(sion_version_patchlevel)) {
80  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(sion_version_patchlevel) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
81  }
82  DPRINTFP((32, DFUNCTION, -1, " wrote sion_version_patchlevel %ld nwrite=%lu\n", sion_version_patchlevel, (unsigned long) nwrite));
83 
84  nwrite = _sion_file_write(&sion_fileformat_version, sizeof(sion_fileformat_version), sion_filedesc->fileptr);
85  if (nwrite != sizeof(sion_fileformat_version)) {
86  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(sion_fileformat_version) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
87  }
88  DPRINTFP((32, DFUNCTION, -1, " wrote sion_fileformat_version %ld nwrite=%lu\n", sion_fileformat_version, (unsigned long) nwrite));
89 
90  /* fsblksize */
91  nwrite = _sion_file_write(&sion_filedesc->fsblksize, sizeof(sion_filedesc->fsblksize), sion_filedesc->fileptr);
92  if (nwrite != sizeof(sion_filedesc->fsblksize)) {
93  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(fsblksize) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
94  }
95  DPRINTFP((32, DFUNCTION, -1, " wrote fsblksize %ld nwrite=%lu\n", sion_filedesc->fsblksize, (unsigned long) nwrite));
96 
97  /* ntasks */
98  nwrite = _sion_file_write(&sion_filedesc->ntasks, sizeof(sion_filedesc->ntasks), sion_filedesc->fileptr);
99  if (nwrite != sizeof(sion_filedesc->ntasks)) {
100  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(ntasks) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
101  }
102  DPRINTFP((32, DFUNCTION, -1, " wrote ntasks %ld nwrite=%lu\n", sion_filedesc->ntasks, (unsigned long) nwrite));
103 
104  /* nfiles */
105  nwrite = _sion_file_write(&sion_filedesc->nfiles, sizeof(sion_filedesc->nfiles), sion_filedesc->fileptr);
106  if (nwrite != sizeof(sion_filedesc->nfiles)) {
107  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(nfiles) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
108  }
109  DPRINTFP((32, DFUNCTION, -1, " wrote nfiles %d nwrite=%lu\n", sion_filedesc->nfiles, (unsigned long) nwrite));
110 
111  /* filenumber */
112  nwrite = _sion_file_write(&sion_filedesc->filenumber, sizeof(sion_filedesc->filenumber), sion_filedesc->fileptr);
113  if (nwrite != sizeof(sion_filedesc->filenumber)) {
114  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(filenumber) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
115  }
116  DPRINTFP((32, DFUNCTION, -1, " wrote filenumber %d nwrite=%lu\n", sion_filedesc->filenumber, (unsigned long) nwrite));
117 
118  /* flag1 --> keyval-mode since file format version 5 (upper 32bit) */
119  sion_filedesc->flag1=(sion_int64) sion_filedesc->keyvalmode * 1<<32;
120  nwrite = _sion_file_write(&sion_filedesc->flag1, sizeof(sion_filedesc->flag1), sion_filedesc->fileptr);
121  if (nwrite != sizeof(sion_filedesc->flag1)) {
122  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(flag1) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
123  }
124  DPRINTFP((32, DFUNCTION, -1, " wrote flag1 %lld nwrite=%lu\n", sion_filedesc->flag1, (unsigned long) nwrite));
125 
126  /* flag2 */
127  nwrite = _sion_file_write(&sion_filedesc->flag2, sizeof(sion_filedesc->flag2), sion_filedesc->fileptr);
128  if (nwrite != sizeof(sion_filedesc->flag2)) {
129  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(flag2) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
130  }
131  DPRINTFP((32, DFUNCTION, -1, " wrote flag2 %d nwrite=%lu\n", sion_filedesc->flag2, (unsigned long) nwrite));
132 
133  /* prefix */
134  if (sion_filedesc->prefix==NULL) {
135  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(prefix) to file, data not available, aborting ...\n"));
136  }
137  lprefix = calloc(SION_FILENAME_LENGTH,1);
138  if (lprefix == NULL) {
139  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot allocate temporary memory of size %lu (lprefix), aborting ...\n", (unsigned long) SION_FILENAME_LENGTH));
140  }
141  strncpy(lprefix,sion_filedesc->prefix,SION_FILENAME_LENGTH);
142  nwrite = _sion_file_write(lprefix, SION_FILENAME_LENGTH, sion_filedesc->fileptr);
143  if (nwrite != SION_FILENAME_LENGTH) {
144  free(lprefix);
145  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(lprefix) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
146  }
147  free(lprefix); lprefix=NULL;
148  DPRINTFP((32, DFUNCTION, -1, " wrote prefix =%s\n", sion_filedesc->prefix));
149 
150  /* globalranks */
151  if (sion_filedesc->all_globalranks==NULL) {
152  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(globalranks) to file, data not available, aborting ...\n"));
153  }
154  nwrite = _sion_file_write(sion_filedesc->all_globalranks, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
155  if (nwrite != sizeof(sion_int64) * sion_filedesc->ntasks) {
156  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(globalranks) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
157  }
158  DPRINTFP((32, DFUNCTION, -1, " wrote globalranks nwrite=%lu\n", (unsigned long) nwrite));
159 
160  /* chunksizes */
161  if (sion_filedesc->all_chunksizes==NULL) {
162  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(chunksizes) to file, data not available, aborting ...\n"));
163  }
164  nwrite = _sion_file_write(sion_filedesc->all_chunksizes, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
165  if (nwrite != sizeof(sion_int64) * sion_filedesc->ntasks) {
166  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(chunksizes) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
167  }
168  DPRINTFP((32, DFUNCTION, -1, " wrote chunksizes nwrite=%lu\n", (unsigned long) nwrite));
169 
170  _sion_file_flush(sion_filedesc->fileptr);
171  DPRINTFP((2, DFUNCTION, -1, "leave write\n"));
172 
173  return (rc);
174 }
175 #undef DFUNCTION
176 
177 #define DFUNCTION "_sion_write_header_var_info"
185 {
186  int rc = SION_SUCCESS;
187  size_t nwrite;
188 
189  DPRINTFP((2, DFUNCTION, -1, "enter write\n"));
190 
191  _sion_file_flush(sion_filedesc->fileptr);
192  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->end_of_header);
193  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " after set fp to end_of_header, fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
194 
195  /* maxusedchunks */
196  nwrite = _sion_file_write(&sion_filedesc->maxusedchunks, sizeof(sion_filedesc->maxusedchunks), sion_filedesc->fileptr);
197  if (nwrite != sizeof(sion_filedesc->maxusedchunks)) {
198  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(maxusedchunks) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
199  }
200  DPRINTFP((32, DFUNCTION, -1, " wrote maxusedchunks %d nwrite=%lu\n", sion_filedesc->maxusedchunks, (unsigned long) nwrite));
201 
202  /* start_of_varheader */
203  nwrite = _sion_file_write(&sion_filedesc->start_of_varheader, sizeof(sion_filedesc->start_of_varheader), sion_filedesc->fileptr);
204  if (nwrite != sizeof(sion_filedesc->start_of_varheader)) {
205  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(start_of_varheader) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
206  }
207  DPRINTFP((32, DFUNCTION, -1, " wrote start_of_varheader %d nwrite=%lu\n", sion_filedesc->start_of_varheader, (unsigned long) nwrite));
208 
209  _sion_file_flush(sion_filedesc->fileptr);
210  DPRINTFP((2, DFUNCTION, -1, "leave write\n"));
211 
212  return (rc);
213 }
214 #undef DFUNCTION
215 
216 #define DFUNCTION "_sion_write_header_var_part_blocksizes"
224 {
225  int rc = SION_SUCCESS;
226  size_t nwrite;
227 
228  DPRINTFP((2, DFUNCTION, -1, "enter write\n"));
229 
230  _sion_file_flush(sion_filedesc->fileptr);
231  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->start_of_varheader);
232  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " after set fp to start_of_varheader, fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
233 
234  /* all_blockcount */
235  nwrite = _sion_file_write(sion_filedesc->all_blockcount, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
236  if (nwrite != sizeof(sion_int64) * sion_filedesc->ntasks) {
237  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(all_blockcount) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
238  }
239  DPRINTFP((32, DFUNCTION, -1, " wrote all_blockcount field %d elements nwrite=%lu\n", sion_filedesc->ntasks, (unsigned long) nwrite));
240 
241  /* all_blocksizes */
242  nwrite = _sion_file_write(sion_filedesc->all_blocksizes, sizeof(sion_int64) * sion_filedesc->ntasks * sion_filedesc->maxusedchunks, sion_filedesc->fileptr);
243  if (nwrite != sizeof(sion_int64) * sion_filedesc->ntasks * sion_filedesc->maxusedchunks) {
244  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(all_blocksizes) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
245  }
246  DPRINTFP((32, DFUNCTION, -1, " wrote all_blocksizes field %d elements nwrite=%lu\n", sion_filedesc->ntasks * sion_filedesc->maxusedchunks, (unsigned long) nwrite));
247 
248  _sion_file_flush(sion_filedesc->fileptr);
249  DPRINTFP((2, DFUNCTION, -1, "leave write\n"));
250 
251  return (rc);
252 }
253 #undef DFUNCTION
254 
255 #define DFUNCTION "_sion_write_header_var_part_mapping"
265  sion_int32 mapping_size,
266  sion_int32 *mapping )
267 {
268  int rc = SION_SUCCESS, lrank;
269  size_t nwrite;
270  sion_int64 position;
271 
272  DPRINTFP((2, DFUNCTION, -1, "enter write\n"));
273 
274  position=sion_filedesc->start_of_varheader
275  + sion_filedesc->ntasks * sizeof(sion_int64)
276  + sion_filedesc->ntasks * sion_filedesc->maxusedchunks *sizeof(sion_int64);
277 
278  _sion_file_flush(sion_filedesc->fileptr);
279  _sion_file_set_position(sion_filedesc->fileptr, position);
280  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " after set fp to start_of_varheader, fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
281 
282  /* mapping_size */
283  nwrite = _sion_file_write(&mapping_size, sizeof(sion_int32), sion_filedesc->fileptr);
284  if (nwrite != sizeof(sion_int32)) {
285  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(mapping_size) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
286  }
287  DPRINTFP((32, DFUNCTION, -1, " wrote mapping_size=%d elements nwrite=%lu\n", mapping_size, (unsigned long) nwrite));
288 
289  /* mapping */
290  if(mapping_size>0) {
291  nwrite = _sion_file_write(mapping, sizeof(sion_int32) * 2 * mapping_size, sion_filedesc->fileptr);
292  if (nwrite != sizeof(sion_int32) * 2 * mapping_size) {
293  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot write header(mapping) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
294  }
295  DPRINTFP((32, DFUNCTION, -1, " wrote mapping field %d elements nwrite=%lu\n", 2 * mapping_size, (unsigned long) nwrite*2*mapping_size));
296  for (lrank = 0; lrank < mapping_size; lrank++) {
297  DPRINTFP((2048, DFUNCTION, - 1, " mapping[%4d]=(%10ld,%10ld)\n", lrank,mapping[lrank*2],mapping[lrank*2+1]));
298  }
299  } else {
300  DPRINTFP((32, DFUNCTION, -1, " wrote no mapping field\n"));
301  }
302  _sion_file_flush(sion_filedesc->fileptr);
303  DPRINTFP((2, DFUNCTION, -1, "leave write\n"));
304 
305  return (rc);
306 }
307 #undef DFUNCTION
308 
309 
310 #define DFUNCTION "_sion_read_header_fix_part"
318 {
319  int rc = SION_SUCCESS;
320  size_t nread;
321  char *sionstr, *lprefix;
322  sion_uint32 lendianness;
323  sion_int32 lfsblksize;
324  sion_int32 Rsion_version, Rsion_version_patchlevel, Rsion_fileformat_version;
325 
326  DPRINTFP((2, DFUNCTION, -1, "enter read fix_part\n"));
327  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
328 
329  /* SION id string */
330  sionstr = (char *) malloc(strlen(SION_ID) * sizeof(char));
331  nread = _sion_file_read(sionstr, strlen(SION_ID), sion_filedesc->fileptr);
332  if (nread != strlen(SION_ID)) {
333  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(SION_ID) from file, aborting ... (%lu!=%lu)\n",
334  (unsigned long) nread, (unsigned long) strlen(SION_ID)));
335  }
336  DPRINTFP((32, DFUNCTION, -1, " sionstr =>%c%c%c%c<\n", sionstr[0], sionstr[1], sionstr[2], sionstr[3]));
337  /* Check if this is a sion file */
338  if (strncmp(sionstr, SION_ID, strlen(SION_ID))) {
339  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: not a sion file(ID: %c%c%c%c)\n", sionstr[0], sionstr[1], sionstr[2], sionstr[3]));
340  }
341  free(sionstr);
342 
343  /* endianness */
344  nread = _sion_file_read(&lendianness, sizeof(lendianness), sion_filedesc->fileptr);
345  if (nread != sizeof(lendianness)) {
346  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header: cannot read header(endianness) from file, aborting ... (%lu!=%lu)\n",(unsigned long) nread, (unsigned long) sizeof(lendianness)));
347  }
348  sion_filedesc->endianness = lendianness;
349  /* Check only first byte. Others are set for symmetry or user data */
350  sion_filedesc->swapbytes = ((sion_filedesc->endianness & 1) != sion_get_endianness());
351  DPRINTFP((32, DFUNCTION, -1, " endianness =0x%x swapbytes=%d\n", sion_filedesc->endianness, sion_filedesc->swapbytes));
352 
353 
354  /* VERSION Information */
355  nread = _sion_file_read(&Rsion_version, sizeof(Rsion_version), sion_filedesc->fileptr);
356  if (nread != sizeof(Rsion_version)) {
357  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(sion_version) from file, aborting ... (%lu!=%lu)\n", (unsigned long) nread, (unsigned long) sizeof(Rsion_version)));
358  }
359  sion_swap(&Rsion_version, &Rsion_version, sizeof(Rsion_version), 1, sion_filedesc->swapbytes);
360  sion_filedesc->filesionversion=Rsion_version;
361  DPRINTFP((32, DFUNCTION, -1, " sion_version=%d\n", Rsion_version));
362 
363  nread = _sion_file_read(&Rsion_version_patchlevel, sizeof(Rsion_version_patchlevel), sion_filedesc->fileptr);
364  if (nread != sizeof(Rsion_version_patchlevel)) {
365  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(sion_version_patchlevel) from file, aborting ... (%lu!=%lu)\n",
366  (unsigned long) nread, (unsigned long) sizeof(Rsion_version_patchlevel)));
367  }
368  sion_swap(&Rsion_version_patchlevel, &Rsion_version_patchlevel, sizeof(Rsion_version_patchlevel), 1, sion_filedesc->swapbytes);
369  sion_filedesc->filesionpatchlevel=Rsion_version_patchlevel;
370  DPRINTFP((32, DFUNCTION, -1, " sion_version_patchlevel=%d\n", (int) Rsion_version_patchlevel));
371 
372  nread = _sion_file_read(&Rsion_fileformat_version, sizeof(Rsion_fileformat_version), sion_filedesc->fileptr);
373  if (nread != sizeof(Rsion_fileformat_version)) {
374  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(sion_fileformat_version) from file, aborting ... (%lu!=%lu)\n",
375  (unsigned long) nread, (unsigned long) sizeof(Rsion_fileformat_version)));
376  }
377  sion_swap(&Rsion_fileformat_version, &Rsion_fileformat_version, sizeof(Rsion_fileformat_version), 1, sion_filedesc->swapbytes);
378  sion_filedesc->fileversion=Rsion_fileformat_version;
379  DPRINTFP((32, DFUNCTION, -1, " sion_fileformat_version=%d\n", (int) Rsion_fileformat_version));
380 
381  if (Rsion_fileformat_version != SION_FILEFORMAT_VERSION) {
382  if(Rsion_fileformat_version<2) {
383  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sionlib: FATAL ERROR: file format version of file differs, aborting ... (%lu!=%lu)\n",
384  (unsigned long) Rsion_fileformat_version, (unsigned long) SION_FILEFORMAT_VERSION));
385  } else {
386  _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_WARN,"sionlib: FATAL WARNING: old file format version of file differs, trying to read ... (%lu!=%lu)\n",
387  (unsigned long) Rsion_fileformat_version, (unsigned long) SION_FILEFORMAT_VERSION);
388  }
389  }
390 
391  /* file block size */
392  nread = _sion_file_read(&sion_filedesc->fsblksize, sizeof(lfsblksize), sion_filedesc->fileptr);
393 
394  if (nread != sizeof(sion_filedesc->fsblksize)) {
395  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(fsblksize) from file, aborting ... (%lu!=%lu)\n",
396  (unsigned long) nread, (unsigned long) sizeof(sion_filedesc->fsblksize)));
397  }
398  sion_swap(&sion_filedesc->fsblksize, &sion_filedesc->fsblksize, sizeof(sion_filedesc->fsblksize), 1, sion_filedesc->swapbytes);
399  DPRINTFP((32, DFUNCTION, -1, " fsblksize=%d\n", sion_filedesc->fsblksize));
400 
401  /* number of tasks */
402  nread = _sion_file_read(&sion_filedesc->ntasks, sizeof(sion_filedesc->ntasks), sion_filedesc->fileptr);
403  if (nread != sizeof(sion_filedesc->ntasks)) {
404  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(ntasks) from file, aborting ... (%lu!=%lu)\n",
405  (unsigned long) nread, (unsigned long) sizeof(sion_filedesc->ntasks)));
406  }
407  sion_swap(&sion_filedesc->ntasks, &sion_filedesc->ntasks, sizeof(sion_filedesc->ntasks), 1, sion_filedesc->swapbytes);
408  DPRINTFP((32, DFUNCTION, -1, " ntasks =%d\n", sion_filedesc->ntasks));
409 
410  /* number of files */
411  nread = _sion_file_read(&sion_filedesc->nfiles, sizeof(sion_filedesc->nfiles), sion_filedesc->fileptr);
412  if (nread != sizeof(sion_filedesc->nfiles)) {
413  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(nfiles) from file, aborting ... (%lu!=%lu)\n",
414  (unsigned long) nread, (unsigned long) sizeof(sion_filedesc->nfiles)));
415  }
416  sion_swap(&sion_filedesc->nfiles, &sion_filedesc->nfiles, sizeof(sion_filedesc->nfiles), 1, sion_filedesc->swapbytes);
417  DPRINTFP((32, DFUNCTION, -1, " nfiles =%d\n", sion_filedesc->nfiles));
418 
419  /* current file number */
420  if(sion_filedesc->fileversion>=3) {
421  nread = _sion_file_read(&sion_filedesc->filenumber, sizeof(sion_filedesc->filenumber), sion_filedesc->fileptr);
422  if (nread != sizeof(sion_filedesc->filenumber)) {
423  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(filenumber) from file, aborting ... (%lu!=%lu)\n",
424  (unsigned long) nread, (unsigned long) sizeof(sion_filedesc->filenumber)));
425  }
426  sion_swap(&sion_filedesc->filenumber, &sion_filedesc->filenumber, sizeof(sion_filedesc->filenumber), 1, sion_filedesc->swapbytes);
427  } else {
428  sion_filedesc->filenumber = 1;
429  }
430  DPRINTFP((32, DFUNCTION, -1, " filenumber =%d\n", sion_filedesc->filenumber));
431 
432 
433  /* flag1 */
434  if(Rsion_fileformat_version>=3) {
435  nread = _sion_file_read(&sion_filedesc->flag1, sizeof(sion_filedesc->flag1), sion_filedesc->fileptr);
436  if (nread != sizeof(sion_filedesc->flag1)) {
437  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(flag1) from file, aborting ... (%lu!=%lu)\n",
438  (unsigned long) nread, (unsigned long) sizeof(sion_filedesc->flag1)));
439  }
440  sion_swap(&sion_filedesc->flag1, &sion_filedesc->flag1, sizeof(sion_filedesc->flag1), 1, sion_filedesc->swapbytes);
441  } else {
442  sion_filedesc->flag1 = _SION_FLAG1_NONE;
443  }
444  DPRINTFP((32, DFUNCTION, -1, " flag1 =%lld\n", sion_filedesc->flag1));
445 
446  if(Rsion_fileformat_version>=5) {
447  /* flag1 --> keyval-mode since file format version 5 (upper 32bit) */
448  sion_filedesc->keyvalmode=sion_filedesc->flag1>>32;
449  DPRINTFP((32, DFUNCTION, -1, " keyvalmode=%d (%s)\n", (int) sion_filedesc->keyvalmode, sion_keyval_type_to_str(sion_filedesc->keyvalmode) ));
450  if(sion_filedesc->keyvalmode==0) {
451  sion_filedesc->keyvalmode=SION_KEYVAL_NONE;
452  DPRINTFP((32, DFUNCTION, -1, " keyvalmode is not set correctly in file, setting default=%d (%s)\n", (int) sion_filedesc->keyvalmode, sion_keyval_type_to_str(sion_filedesc->keyvalmode) ));
453  }
454  } else {
455  sion_filedesc->keyvalmode=SION_KEYVAL_NONE; /* not implemented before version 5 of file format */
456  DPRINTFP((32, DFUNCTION, -1, " file format version <5, setting default keyvalmode=%d (%s)\n", (int) sion_filedesc->keyvalmode, sion_keyval_type_to_str(sion_filedesc->keyvalmode) ));
457  }
458 
459 
460  /* flag2 */
461  if(Rsion_fileformat_version>=3) {
462  nread = _sion_file_read(&sion_filedesc->flag2, sizeof(sion_filedesc->flag2), sion_filedesc->fileptr);
463  if (nread != sizeof(sion_filedesc->flag2)) {
464  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(flag2) from file, aborting ... (%lu!=%lu)\n",
465  (unsigned long) nread, (unsigned long) sizeof(sion_filedesc->flag2)));
466  }
467  sion_swap(&sion_filedesc->flag2, &sion_filedesc->flag2, sizeof(sion_filedesc->flag2), 1, sion_filedesc->swapbytes);
468  } else {
469  sion_filedesc->flag2 = _SION_FLAG2_NONE;
470  }
471  DPRINTFP((32, DFUNCTION, -1, " flag2 =%lld\n", sion_filedesc->flag2));
472 
473  /* file name prefix */
474  lprefix = malloc(SION_FILENAME_LENGTH);
475  nread = _sion_file_read(lprefix, SION_FILENAME_LENGTH, sion_filedesc->fileptr);
476  if (nread != SION_FILENAME_LENGTH) {
477  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_fix_part: cannot read header(lprefix) from file, aborting ... (%lu!=%d)\n", (unsigned long) nread, SION_FILENAME_LENGTH));
478  }
479  sion_filedesc->prefix=strdup(lprefix);
480  free(lprefix);
481  DPRINTFP((32, DFUNCTION, -1, " prefix =%s\n", sion_filedesc->prefix));
482 
483 
484  /* */ DPRINTFTS(sion_filedesc->rank, "before purge");
485  _sion_file_purge(sion_filedesc->fileptr);
486  /* */ DPRINTFTS(sion_filedesc->rank, "after purge");
487 
488  sion_filedesc->end_of_header=_sion_file_get_position(sion_filedesc->fileptr);
489 
490  DPRINTFP((2, DFUNCTION, -1, "leave read fix_part\n"));
491 
492  return (rc);
493 }
494 #undef DFUNCTION
495 
496 #define DFUNCTION "_sion_read_header_var_part"
504 {
505  int rc = SION_SUCCESS;
506  size_t nread;
507  sion_int32 Rmaxchunks;
508 
509  DPRINTFP((32, DFUNCTION, -1, "enter read var_part\n"));
510  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
511 
512  /* globalranks */
513  nread = _sion_file_read(sion_filedesc->all_globalranks, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
514  if (nread != sizeof(sion_int64) * sion_filedesc->ntasks) {
515  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part: cannot read header(globalranks) from file, aborting ... (%d)\n", sion_filedesc->ntasks));
516  }
517  sion_swap(sion_filedesc->all_globalranks, sion_filedesc->all_globalranks, sizeof(sion_int64), sion_filedesc->ntasks, sion_filedesc->swapbytes);
518 
519  /* chunksizes */
520  nread = _sion_file_read(sion_filedesc->all_chunksizes, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
521  if (nread != sizeof(sion_int64) * sion_filedesc->ntasks) {
522  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part: cannot read header(chunksizes) from file, aborting ... (%d!=%lu)\n", sion_filedesc->ntasks, (unsigned long) nread));
523  }
524  sion_swap(sion_filedesc->all_chunksizes, sion_filedesc->all_chunksizes, sizeof(sion_int64), sion_filedesc->ntasks, sion_filedesc->swapbytes);
525 
526  /* maxchunks -> maxusedchunks */
527  nread = _sion_file_read(&Rmaxchunks, sizeof(Rmaxchunks), sion_filedesc->fileptr);
528  if (nread != sizeof(Rmaxchunks)) {
529  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part: cannot read header(maxchunks) from file, aborting ... (%lu!=%lu)\n",
530  (unsigned long) nread, (unsigned long) sizeof(Rmaxchunks)));
531  }
532  sion_swap(&Rmaxchunks, &Rmaxchunks, sizeof(Rmaxchunks), 1, sion_filedesc->swapbytes);
533  DPRINTFP((32, DFUNCTION, -1, " maxchunks=%d\n", Rmaxchunks));
534 
535  sion_filedesc->maxusedchunks=Rmaxchunks;
536  if(Rmaxchunks>sion_filedesc->maxchunks) _sion_realloc_filedesc_blocklist(sion_filedesc, Rmaxchunks);
537 
538  /* start_of_varheader */
539  nread = _sion_file_read(&sion_filedesc->start_of_varheader, sizeof(sion_filedesc->start_of_varheader), sion_filedesc->fileptr);
540  if (nread != sizeof(sion_filedesc->start_of_varheader)) {
541  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part: cannot read header(start_of_varheader) from file, aborting ... (%lu!=%lu)\n",
542  (unsigned long) nread, (unsigned long) sizeof(sion_filedesc->start_of_varheader)));
543  }
544  if (sion_filedesc->start_of_varheader == 0) {
545  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part: bad value for start_of_varheader (=%lu), aborting ...\n",
546  (unsigned long) sion_filedesc->start_of_varheader));
547  }
548  sion_swap(&sion_filedesc->start_of_varheader, &sion_filedesc->start_of_varheader, sizeof(sion_filedesc->start_of_varheader), 1, sion_filedesc->swapbytes);
549 
550  DPRINTFP((32, DFUNCTION, -1, "leave read var_part start_of_varheader=%lld\n", sion_filedesc->start_of_varheader));
551 
552  return (rc);
553 
554 }
555 #undef DFUNCTION
556 
557 #define DFUNCTION "_sion_rd_hdr_var_prt_blkcnt_to_field"
567  int field_size,
568  sion_int64 *field )
569 {
570  int rc = SION_SUCCESS;
571  size_t nread;
572 
573  DPRINTFP((32, DFUNCTION, -1, "enter\n"));
574  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
575 
576  if (field_size < sion_filedesc->ntasks) {
577  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_blockcount_to_field: cannot read header(blocksizes) field too small, aborting ... (%d<%d)\n", field_size, sion_filedesc->ntasks));
578  }
579  /* set file pointer to start of Meta Block 2 */
580  _sion_file_purge(sion_filedesc->fileptr);
581  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->start_of_varheader);
582 
583  nread = _sion_file_read(field, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
584  if (nread != sizeof(sion_int64) * sion_filedesc->ntasks) {
585  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_blockcount_to_field: cannot read blocksizes from meta block 2 of the file, aborting ... (%d,%d)\n", sion_filedesc->ntasks, nread));
586  }
587  sion_swap(field, field, sizeof(sion_int64), sion_filedesc->ntasks, sion_filedesc->swapbytes);
588 
589 
590  DPRINTFP((32, DFUNCTION, -1, "leave \n"));
591 
592  return (rc);
593 
594 }
595 #undef DFUNCTION
596 
597 #define DFUNCTION "_sion_rd_hdr_vr_prt_nxtblksizes_to_field"
608  int field_size,
609  sion_int64 *field )
610 {
611  size_t nread;
612  int rc = SION_SUCCESS;
613 
614  DPRINTFP((32, DFUNCTION, -1, "enter\n"));
615  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
616 
617  if (field_size < sion_filedesc->ntasks) {
618  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_nextblocksizes_to_field: cannot read header(blocksizes) field too small, aborting ... (%d<%d)\n", field_size, sion_filedesc->ntasks));
619  }
620  nread = _sion_file_read(field, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
621  if (nread != sizeof(sion_int64) * sion_filedesc->ntasks) {
622  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_nextblocksizes_to_field: cannot read blocksizes from meta block 2 of the file, aborting ... (%d,%d)\n", sion_filedesc->ntasks, nread));
623  }
624  sion_swap(field, field, sizeof(sion_int64), sion_filedesc->ntasks, sion_filedesc->swapbytes);
625 
626 
627  DPRINTFP((32, DFUNCTION, -1, "leave \n"));
628 
629  return (rc);
630 
631 }
632 #undef DFUNCTION
633 
634 #define DFUNCTION "_sion_read_header_var_part_blocksizes"
642 {
643  int rc = SION_SUCCESS;
644  size_t nread;
645  int i;
646 
647  DPRINTFP((32, DFUNCTION, -1, "enter read\n"));
648  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
649 
650  _sion_file_purge(sion_filedesc->fileptr);
651  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->start_of_varheader);
652 
653  /* all_blockcount */
654  nread = _sion_file_read(sion_filedesc->all_blockcount, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
655  if (nread != sizeof(sion_int64) * sion_filedesc->ntasks) {
656  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_blocksizes: cannot read header from file(sion_blockcount), aborting ... (%d)\n", sion_filedesc->ntasks));
657  }
658  sion_swap(sion_filedesc->all_blockcount, sion_filedesc->all_blockcount, sizeof(sion_int64), sion_filedesc->ntasks, sion_filedesc->swapbytes);
659  for (i = 0; i < sion_filedesc->ntasks; i++)
660  DPRINTFP((2048, DFUNCTION, -1, " read, numblocks on task %02d is %10lld\n", i, sion_filedesc->all_blockcount[i]));
661 
662  /* all_blocksizes */
663  nread = _sion_file_read(sion_filedesc->all_blocksizes, sizeof(sion_int64) * sion_filedesc->ntasks * sion_filedesc->maxusedchunks, sion_filedesc->fileptr);
664  if (nread != sizeof(sion_int64) * sion_filedesc->ntasks * sion_filedesc->maxusedchunks) {
665  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_blocksizes: cannot read header(sion_blocksizes) from file, aborting ... (%lu!=%lu)\n",
666  (unsigned long) sion_filedesc->ntasks * sion_filedesc->maxusedchunks, (unsigned long) nread));
667  }
668  sion_swap(sion_filedesc->all_blocksizes, sion_filedesc->all_blocksizes, sizeof(sion_int64), sion_filedesc->ntasks * sion_filedesc->maxusedchunks, sion_filedesc->swapbytes);
669 
670  for (i = 0; i < sion_filedesc->ntasks; i++)
671  DPRINTFP((2048, DFUNCTION, -1, " read, blocksize[0] on task %02d is %10lld\n", i, sion_filedesc->all_blocksizes[0*sion_filedesc->ntasks+i]));
672 
673  DPRINTFP((32, DFUNCTION, -1, "leave read\n"));
674  return (rc);
675 
676 }
677 
678 #undef DFUNCTION
679 
680 #define DFUNCTION "_sion_read_header_var_part_mapping"
690 {
691  int rc = SION_SUCCESS;
692  size_t nread;
693  sion_int64 position;
694 
695  DPRINTFP((32, DFUNCTION, -1, "enter read\n"));
696 
697  position=sion_filedesc->start_of_varheader
698  + sion_filedesc->ntasks * sizeof(sion_int64)
699  + sion_filedesc->ntasks * sion_filedesc->maxusedchunks *sizeof(sion_int64);
700  _sion_file_purge(sion_filedesc->fileptr);
701  _sion_file_set_position(sion_filedesc->fileptr, position);
702  DPRINTFP((32, DFUNCTION, -1, "calculate position %lld + %d * %d = %lld\n",sion_filedesc->start_of_varheader,sion_filedesc->ntasks,sion_filedesc->maxusedchunks,position ));
703  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
704 
705  /* read mapping_size */
706  nread = _sion_file_read(&sion_filedesc->mapping_size, sizeof(sion_filedesc->mapping_size), sion_filedesc->fileptr);
707  if (nread != sizeof(sion_filedesc->mapping_size)) {
708  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_mapping: cannot read header(mapping_size) from file, aborting ... (%d)\n", nread));
709  }
710  sion_swap(&sion_filedesc->mapping_size,&sion_filedesc->mapping_size, sizeof(sion_filedesc->mapping_size), 1, sion_filedesc->swapbytes);
711  DPRINTFP((32, DFUNCTION, -1, "mapping_size=%ld\n", (long) sion_filedesc->mapping_size));
712 
713  /* allocate mapping vector */
714  sion_filedesc->mapping = (sion_int32 *) malloc(sion_filedesc->mapping_size * 2 * sizeof(sion_int32));
715  if (sion_filedesc->mapping == NULL) {
716  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_mapping: cannot allocate temporary memory of size %lu (mapping), aborting ...\n", (unsigned long) 2 * sion_filedesc->mapping_size * sizeof(sion_int64)));
717  }
718  DPRINTFP((32, DFUNCTION, -1, "alloc mapping vector size=%d (%lu bytes)\n", sion_filedesc->mapping_size, (long) sion_filedesc->mapping_size * 2 * sizeof(sion_int32)));
719 
720  /* read mapping */
721  nread = _sion_file_read(sion_filedesc->mapping, sizeof(sion_int32) * sion_filedesc->mapping_size * 2, sion_filedesc->fileptr);
722  DPRINTFP((32, DFUNCTION, -1, "read mapping, %d \n", nread));
723  if (nread != (sizeof(sion_int32) * sion_filedesc->mapping_size * 2)) {
724  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_mapping: cannot read header(mapping) from file, aborting ... (%d!=%lu)\n", sion_filedesc->mapping_size*2, (unsigned long) nread));
725  }
726  sion_swap(sion_filedesc->mapping,sion_filedesc->mapping, sizeof(sion_int32), sion_filedesc->mapping_size * 2, sion_filedesc->swapbytes);
727 
728  DPRINTFP((32, DFUNCTION, -1, "leave read\n"));
729 
730  return (rc);
731 
732 }
733 #undef DFUNCTION
734 
735 #define DFUNCTION "_sion_read_header_var_part_locations_rank"
742 /* TODO: _sion_filedesc *sion_filedesc -> fileptr */
744 {
745  int rc = SION_SUCCESS;
746  int i, numblocks;
747  size_t nread;
748  sion_int64 position;
749  sion_int64 helpint64;
750 
751  DPRINTFP((32, DFUNCTION, -1, "enter read for rank %d of %d\n",sion_filedesc->rank,sion_filedesc->ntasks));
752 
753  _sion_file_purge(sion_filedesc->fileptr);
754  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->start_of_varheader);
755 
756  /* read number of blocks */
757  nread = _sion_file_read(&helpint64, sizeof(sion_int64), sion_filedesc->fileptr);
758  sion_swap(&helpint64,&helpint64, sizeof(sion_int64), 1, sion_filedesc->swapbytes);
759  numblocks = helpint64;
760  if (nread != sizeof(sion_int64)) {
761  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_locations_rank: cannot read header(numblocks) from file, aborting ... (%d)\n", sion_filedesc->ntasks));
762  }
763  sion_filedesc->maxusedchunks = numblocks;
764  sion_filedesc->lastchunknr = numblocks-1;
765 
766  /* read blocksizes */
767  for (i = 0; i < numblocks; i++) {
768 
769  position = sion_filedesc->start_of_varheader
770  + (i + 1) * sion_filedesc->ntasks * sizeof(sion_int64)
771  + sion_filedesc->rank * sizeof(sion_int64);
772  _sion_file_purge(sion_filedesc->fileptr);
773  _sion_file_set_position(sion_filedesc->fileptr, position);
774 
775  nread = _sion_file_read(&helpint64, sizeof(sion_int64), sion_filedesc->fileptr);
776  if (nread != sizeof(sion_int64)) {
777  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_locations_rank: cannot read header(blocksizes) from file, aborting ... (%d!=%lu)\n", 1, (unsigned long) nread));
778  }
779  sion_swap(&helpint64,&helpint64, sizeof(sion_int64), 1, sion_filedesc->swapbytes);
780  sion_filedesc->blocksizes[i] = helpint64;
781  DPRINTFP((32, "_sion_read_header_var_part_locations_rank", -1, "read blocksizes[%i], %lld start_of_varheader=%lld\n", i, helpint64, sion_filedesc->start_of_varheader));
782 
783  }
784 
785  DPRINTFP((32, DFUNCTION, -1, "leave read\n"));
786 
787  return (rc);
788 
789 }
790 #undef DFUNCTION
791 
792 #define DFUNCTION "_sion_read_header_var_part_mapping_rank"
802 {
803  int rc = SION_SUCCESS;
804  int msize;
805  size_t nread;
806  sion_int64 position;
807  sion_int32 helpint32;
808 
809  DPRINTFP((32, DFUNCTION, -1, "enter read for rank %d of %d\n",sion_filedesc->rank,sion_filedesc->ntasks));
810 
811  position=sion_filedesc->start_of_varheader
812  + sion_filedesc->ntasks * sizeof(sion_int64)
813  + sion_filedesc->ntasks * sion_filedesc->maxusedchunks *sizeof(sion_int64);
814  _sion_file_purge(sion_filedesc->fileptr);
815  _sion_file_set_position(sion_filedesc->fileptr, position);
816  DPRINTFP((32, DFUNCTION, -1, "calculate position %lld + %d * %d = %lld\n",sion_filedesc->start_of_varheader,sion_filedesc->ntasks,sion_filedesc->maxusedchunks,position ));
817  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
818 
819  /* read mapping_size */
820  nread = _sion_file_read(&helpint32, sizeof(sion_int32), sion_filedesc->fileptr);
821  if (nread != sizeof(sion_int32)) {
822  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_mapping_rank: cannot read header(mapping_size) from file, aborting ... (%d)\n", sion_filedesc->ntasks));
823  }
824  sion_swap(&helpint32,&helpint32, sizeof(sion_int32), 1, sion_filedesc->swapbytes);
825  msize = helpint32;
826  DPRINTFP((32, "_sion_read_header_var_part_mapping_rank", -1, "read mapping_size %d \n", msize));
827 
828  if((sion_filedesc->rank<0) || (sion_filedesc->rank>=msize)) {
829  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_mapping_rank: wrong rank %d not between 0 .. %d aborting ...\n", sion_filedesc->rank,msize));
830  }
831 
832  /* move to position in mapping table for rank */
833  position=sion_filedesc->start_of_varheader
834  + sion_filedesc->ntasks * sizeof(sion_int64)
835  + sion_filedesc->ntasks * sion_filedesc->maxusedchunks *sizeof(sion_int64)
836  + sizeof(sion_int32)
837  + 2*sion_filedesc->rank*sizeof(sion_int32);
838 
839  _sion_file_purge(sion_filedesc->fileptr);
840  _sion_file_set_position(sion_filedesc->fileptr, position);
841 
842  /* allocate mapping vector of length 1 */
843  sion_filedesc->mapping_size=1;
844  /* allocate mapping vector */
845  sion_filedesc->mapping = (sion_int32 *) malloc(sion_filedesc->mapping_size * 2 * sizeof(sion_int32));
846  if (sion_filedesc->mapping == NULL) {
847  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_mapping: cannot allocate temporary memory of size %lu (mapping), aborting ...\n", (unsigned long) 2 * sion_filedesc->mapping_size * sizeof(sion_int64)));
848  }
849  DPRINTFP((32, DFUNCTION, -1, "alloc mapping vector size=%d (%lu bytes)\n", sion_filedesc->mapping_size, (long) sion_filedesc->mapping_size * 2 * sizeof(sion_int32)));
850 
851  /* read mapping for rank */
852  nread = _sion_file_read(sion_filedesc->mapping, sizeof(sion_int32) * sion_filedesc->mapping_size * 2, sion_filedesc->fileptr);
853  DPRINTFP((32, DFUNCTION, -1, "read mapping, %d \n", nread));
854  if (nread != (sizeof(sion_int32) * sion_filedesc->mapping_size * 2)) {
855  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_mapping: cannot read header(mapping) from file, aborting ... (%d!=%lu)\n", sion_filedesc->mapping_size*2, (unsigned long) nread));
856  }
857  sion_swap(sion_filedesc->mapping,sion_filedesc->mapping, sizeof(sion_int32), sion_filedesc->mapping_size * 2, sion_filedesc->swapbytes);
858 
859  DPRINTFP((32, DFUNCTION, -1, "leave read filenumber=%d lrank=%d\n",sion_filedesc->mapping[0], sion_filedesc->mapping[1]));
860 
861  return (rc);
862 
863 }
864 #undef DFUNCTION
865 
866 
867 #define DFUNCTION "_sion_wr_hdr_var_prt_blkcnt_from_field"
877  int field_size,
878  sion_int64 *field )
879 {
880  size_t nwrite;
881  int rc=SION_SUCCESS;
882 
883  DPRINTFP((32, DFUNCTION, -1, "enter\n"));
884  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
885 
886  if (field_size < sion_filedesc->ntasks) {
887  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_read_header_var_part_blockcount_to_field: cannot read header(blocksizes) field too small, aborting ... (%d<%d)\n", field_size, sion_filedesc->ntasks));
888  }
889  /* set file pointer to start of Meta Block 2 */
890  _sion_file_purge(sion_filedesc->fileptr);
891  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->start_of_varheader);
892 
893  nwrite = _sion_file_write(field, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
894  if (nwrite != sizeof(sion_int64) * sion_filedesc->ntasks) {
895  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header_var_part_blockcount_from_field: cannot write header(all_blockcount) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
896  }
897  DPRINTFP((32, DFUNCTION, -1, " wrote all_blockcount field %d elements nwrite=%lu\n", sion_filedesc->ntasks, (unsigned long) nwrite));
898 
899  DPRINTFP((32, DFUNCTION, -1, "leave \n"));
900 
901  return (rc);
902 
903 }
904 #undef DFUNCTION
905 
906 #define DFUNCTION "_sion_wr_hdr_vr_prt_nxtblksizes_from_field"
917  int field_size,
918  sion_int64 *field )
919 {
920  int rc=SION_SUCCESS;
921  size_t nwrite;
922 
923  DPRINTFP((32, DFUNCTION, -1, "enter\n"));
924  DPRINTFP((16, DFUNCTION, sion_filedesc->rank, " fileptr is at position %14lld\n", _sion_file_get_position(sion_filedesc->fileptr)));
925 
926  if (field_size < sion_filedesc->ntasks) {
927  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header_var_part_nextblocksizes_from_field: cannot write header(blocksizes) field too small, aborting ... (%d<%d)\n", field_size, sion_filedesc->ntasks));
928  }
929  nwrite = _sion_file_write(field, sizeof(sion_int64) * sion_filedesc->ntasks, sion_filedesc->fileptr);
930  if (nwrite != sizeof(sion_int64) * sion_filedesc->ntasks) {
931  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_write_header_var_part_nextblocksizes_from_field: cannot write header(all_blocksizes) to file, aborting ... (%lu)\n", (unsigned long) nwrite));
932  }
933  DPRINTFP((32, DFUNCTION, -1, " wrote all_blocksizes field %d elements nwrite=%lu\n", sion_filedesc->ntasks, (unsigned long) nwrite));
934 
935  DPRINTFP((32, DFUNCTION, -1, "leave \n"));
936 
937  return (rc);
938 
939 }
940 #undef DFUNCTION
941 
char * sion_keyval_type_to_str(int type)
Returns key value mode as string.
int sion_get_endianness(void)
Return endianness.
Definition: sion_tools.c:32
void sion_swap(void *target, void *source, int size, int n, int do_swap)
Definition: sion_convert.c:44
#define SION_KEYVAL_NONE
Definition: sion_const.h:80
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
Definition: sion_file.c:434
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
Definition: sion_file.c:367
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
Definition: sion_file.c:467
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
Definition: sion_file.c:401
sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Write data to file.
Definition: sion_file.c:221
sion_int64 _sion_file_read(void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Read data from file.
Definition: sion_file.c:257
int _sion_realloc_filedesc_blocklist(_sion_filedesc *sion_filedesc, sion_int32 maxchunks)
Increase the memory used by the internal sion structure for the blocklist.
#define _SION_FLAG2_NONE
Definition: sion_filedesc.h:22
#define _SION_FLAG1_NONE
Definition: sion_filedesc.h:21
int _sion_read_header_var_part(_sion_filedesc *sion_filedesc)
Read the second part of SION Meta Block 1.
int _sion_write_header_var_part_blockcount_from_field(_sion_filedesc *sion_filedesc, int field_size, sion_int64 *field)
Write the block sizes from Meta Block 2.
int _sion_read_header_var_part_blocksizes_rank(_sion_filedesc *sion_filedesc)
Read the SION Meta Block 2.
int _sion_write_header_var_part_nextblocksizes_from_field(_sion_filedesc *sion_filedesc, int field_size, sion_int64 *field)
Write the next set of blocksizes from Meta Block 2 Assuming that filepointer is at the correct positi...
int _sion_read_header_var_part_mapping_rank(_sion_filedesc *sion_filedesc)
Read the mapping data at end of SION Meta Block 2.
int _sion_write_header_var_info(_sion_filedesc *sion_filedesc)
Write the SION Meta Block 1.
int _sion_write_header_var_part_blocksizes(_sion_filedesc *sion_filedesc)
Write the SION Meta Block 2.
int _sion_write_header(_sion_filedesc *sion_filedesc)
Write the SION Meta Block 1.
Definition: sion_metadata.c:38
int _sion_read_header_var_part_blockcount_to_field(_sion_filedesc *sion_filedesc, int field_size, sion_int64 *field)
Read the block sizes from Meta Block 2.
int _sion_read_header_var_part_blocksizes(_sion_filedesc *sion_filedesc)
Read the SION Meta Block 2.
int _sion_read_header_fix_part(_sion_filedesc *sion_filedesc)
Read part of the SION Meta Block 1.
int _sion_write_header_var_part_mapping(_sion_filedesc *sion_filedesc, sion_int32 mapping_size, sion_int32 *mapping)
Write mapping into the SION Meta Block 2.
int _sion_read_header_var_part_mapping(_sion_filedesc *sion_filedesc)
Read the mapping data at end of SION Meta Block 2.
int _sion_read_header_var_part_nextblocksizes_to_field(_sion_filedesc *sion_filedesc, int field_size, sion_int64 *field)
Read the next set of blocksizes from Meta Block 2 Assuming that filepointer is at the correct positio...
#define SION_ID
Definition: sion_metadata.h:14
Sion Time Stamp Header.
Sion File Descriptor Structure.
Definition: sion_filedesc.h:79
sion_int64 * all_blocksizes
sion_int32 filesionversion
sion_int64 start_of_varheader
sion_int32 filesionpatchlevel
sion_int64 * all_chunksizes
sion_int64 * blocksizes
sion_int64 * all_globalranks
_sion_fileptr * fileptr
Definition: sion_filedesc.h:82
sion_int64 * all_blockcount