SIONlib  2.0.0-rc.1
Scalable I/O library for parallel access to task-local files
sion_common.h
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2018 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
10 #ifndef SION_SION_COMMON_H
11 #define SION_SION_COMMON_H
12 
19 #include <stdint.h>
20 #include <stdio.h>
21 
22 #include "sion_enums.h"
23 
25 
26 /* default mode */
27 #define SION_SERIAL_MASTER
28 
29 #define SION_MAX_FSBLOCKSIZE 32 * 1024 * 1024
30 #define SION_DEFAULT_FSBLOCKSIZE 2 * 1024 * 1024
31 
32 #define SION_FILENAME_LENGTH 1024
33 
34 #define MAXCHUNKS 100
36 #define WFLARGEMETABLOCK_none /* for BENCHMARKING only */
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 int _sion_close_sid(int sid);
43 
44 /* I/O */
57 size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid);
58 
72 size_t sion_fread(void *data, size_t size, size_t nitems, int sid);
73 
74 /* helper functions */
85 int sion_feof(int sid);
86 
97 int sion_ensure_free_space(int sid, int64_t bytes);
98 
106 int sion_flush(int sid);
107 
108 /* get size of internal data structure */
118 int sion_get_sizeof(int sid, int *numbytes, int *numfds);
119 
120 /* duplicate fd (only parallel read-mode) */
136 int sion_dup(int sid, int mode, int rank, uint64_t key);
137 
146 int sion_dedup(int sid);
147 
148 /* special helper functions, for used with szlib */
149 int sion_optimize_fp_buffer(int sid);
150 
151 /* get information (with sion datatypes) */
159 int sion_get_file_endianness(int sid);
160 
168 int sion_endianness_swap_needed(int sid);
169 int64_t sion_get_bytes_written(int sid);
170 int64_t sion_get_bytes_read(int sid);
171 
182 int64_t sion_bytes_avail_in_block(int sid);
183 
195 int64_t sion_bytes_avail_in_chunk(int sid);
196 
207 int64_t sion_get_position(int sid);
208 
222 int sion_get_mapping(int sid, int *mapping_size, int32_t **mapping, int *numfiles);
223 
250 int sion_get_locations(int sid, int *ntasks, int *maxchunks, int64_t *globalskip, int64_t *start_of_varheader,
251  int64_t **sion_chunksizes, int64_t **sion_globalranks, int64_t **sion_blockcount, int64_t **sion_blocksizes);
252 
253 /* parallel mode */
270 int sion_get_current_location(int sid, int *currentchunknr, int64_t *currentpos, int *maxchunks, int64_t **chunksizes);
271 
272 /* serial mode */
288 int sion_get_current_locations(int sid, int *ntasks, int64_t **sion_currentpos, int64_t **sion_currentblocknr);
289 int sion_get_number_of_files(int sid);
290 int sion_get_filenumber(int sid);
291 
292 /* 1 is opened with sion_open or sion_open_rank */
293 int sion_is_serial_opened(int sid);
294 
295 /* 1 if using GPFS or Linux hints */
296 int sion_using_hints(int sid);
297 
298 /* return current endianness (1-> big endian, 0 ->little endian) */
305 int sion_get_endianness(void);
306 
307 /* return if SIONlib supports PTHREADS (Thread-safe) 1 -> yes, 0 -> no */
308 int sion_is_thread_safe(void);
309 
310 /* return version numbers */
316 int sion_get_version(int *main_version, int *sub_version, int *patch_level, int *fileformat_version);
317 
318 typedef struct _sion_io_stat_struct sion_io_stat_t;
320  int nfiles;
321  const char **names;
322  size_t *sizes;
323  int *roles;
324 };
325 
326 /* return info about accessed (local) files on this task */
327 sion_io_stat_t *sion_get_io_info(int sid);
328 
329 /* return info about accessed (local) files on this task */
330 sion_io_stat_t *sion_get_io_info_by_spec(int sid, int roles, int flag);
331 int sion_free_io_info(sion_io_stat_t *info);
332 
333 /* Seeking */
356 int sion_seek(int sid, int64_t offset, sion_seek_mode whence);
357 
364 //
375 int sion_seek_chunk(int sid, int32_t offset, sion_seek_mode whence);
376 
391 int sion_switch_logical_file(int sid, int file_number);
392 
393 /* register user defined lock and unlock routines, which are needed to access shared data structures internally */
404 int sion_lock_register_lock_callbacks(int lock(void *), int unlock(void *), void *lock_data);
405 
412 
413 /* Utilities */
427 void sion_swap(void *target, void *source, int size, int n, int do_swap);
428 
429 char *sion_get_fname(int sid);
430 int64_t sion_get_chunksize(int sid);
431 int32_t sion_get_globalrank(int sid);
432 
603 
604 struct _sion_key_stat_struct;
605 
620 size_t sion_fwrite_key(const void *data, uint64_t key, size_t size, size_t nitems, int sid);
621 
638 size_t sion_fread_key(void *data, uint64_t key, size_t size, size_t nitems, int sid);
639 
640 /* iterator for key-value pairs */
648 int sion_fread_key_iterator_reset(int sid);
649 
663 int sion_fread_key_iterator_next(int sid, uint64_t *key, size_t *size);
664 
681 int sion_seek_key(int sid, uint64_t key, int entrynum, int64_t posinentry);
682 
690 int sion_key_full_scan(int sid);
691 
699 int sion_key_list_iterator_reset(int sid);
700 
709 int sion_key_list_iterator_next(int sid, uint64_t *keyptr);
710 
713  uint64_t key;
714  int64_t num_blocks;
715  int64_t total_size;
716 };
717 
727 int sion_key_get_stat(int sid, uint64_t key, sion_key_stat_t *stat);
728 
736 int sion_get_keyval_mode(int sid);
737 
745 char *sion_keyval_type_to_str(int type);
746 
748 
749 #ifdef __cplusplus
750 }
751 #endif
752 
753 /* Debugging */
754 #ifndef DPRINTF
755 #define DPRINTF(A)
756 #define DPRINTFP(A)
757 #define DPRINTTS(A, B)
758 #define DPRINTFTS2(A, B)
759 #endif
760 
762 
763 #endif
int sion_dedup(int sid)
Function which destroy a duplicated sion file descriptor.
Definition: sion_common.c:760
sion_seek_mode
determines how offsets are interpreted for seek operations
Definition: sion_enums.h:32
int sion_get_mapping(int sid, int *mapping_size, int32_t **mapping, int *numfiles)
Returns pointers to the internal field mapping.
Definition: sion_common.c:126
int sion_get_locations(int sid, int *ntasks, int *maxchunks, int64_t *globalskip, int64_t *start_of_varheader, int64_t **sion_chunksizes, int64_t **sion_globalranks, int64_t **sion_blockcount, int64_t **sion_blocksizes)
Returns pointers to internal fields.
Definition: sion_common.c:34
int sion_dup(int sid, int mode, int rank, uint64_t key)
Function which duplicates a sion file descriptor.
Definition: sion_common.c:735
int64_t sion_bytes_avail_in_block(int sid)
Return the number of bytes available in the current chunk.
Definition: sion_common.c:582
int sion_key_full_scan(int sid)
Performs a full scan of all meta data in current file.
int sion_get_sizeof(int sid, int *numbytes, int *numfds)
Function returns size of internal data structure for sid.
Definition: sion_common.c:713
int sion_key_list_iterator_next(int sid, uint64_t *keyptr)
Forward to next key.
int sion_key_get_stat(int sid, uint64_t key, sion_key_stat_t *stat)
get statistics about key
int sion_seek(int sid, int64_t offset, sion_seek_mode whence)
moves the file pointer inside a logical file
Definition: sion_common.c:396
int sion_fread_key_iterator_next(int sid, uint64_t *key, size_t *size)
Forward to next key.
int sion_feof(int sid)
Function that indicates whether the end of file is reached for this task.
Definition: sion_common.c:531
int sion_endianness_swap_needed(int sid)
Returns whether or not byte swapping is needed for sid.
Definition: sion_common.c:164
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...
Definition: sion_common.c:774
size_t sion_fread(void *data, size_t size, size_t nitems, int sid)
Read data from sion file.
Definition: sion_common.c:365
int sion_get_file_endianness(int sid)
Returns edianness of data in file sid.
Definition: sion_common.c:149
char * sion_keyval_type_to_str(int type)
Returns key value mode as string.
int sion_key_list_iterator_reset(int sid)
Resets key iterator.
int sion_get_version(int *main_version, int *sub_version, int *patch_level, int *fileformat_version)
Return version numbers.
Definition: sion_common.c:834
int64_t sion_bytes_avail_in_chunk(int sid)
Function that returns the number of bytes available in the current chunk.
Definition: sion_common.c:587
int sion_switch_logical_file(int sid, int file_number)
moves the file pointer to a different logical file
Definition: sion_common.c:486
int sion_seek_chunk(int sid, int32_t offset, sion_seek_mode whence)
moves the file pointer by increments of entire chunks inside the logical file
Definition: sion_common.c:439
int sion_flush(int sid)
Flushed sion file.
Definition: sion_common.c:646
int sion_get_current_location(int sid, int *currentchunknr, int64_t *currentpos, int *maxchunks, int64_t **chunksizes)
Returns current position in file and pointer fiels containing chunk sizes.
Definition: sion_common.c:107
int sion_seek_key(int sid, uint64_t key, int entrynum, int64_t posinentry)
Seek to position in key.
void sion_swap(void *target, void *source, int size, int n, int do_swap)
Perform byte-order swapping for arrays.
Definition: sion_convert.c:17
int sion_ensure_free_space(int sid, int64_t bytes)
Funtion to ensure that enough space is available for writing.
Definition: sion_common.c:656
size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid)
Write data to sion file.
Definition: sion_common.c:309
int sion_fread_key_iterator_reset(int sid)
Resets key iterator.
size_t sion_fwrite_key(const void *data, uint64_t key, size_t size, size_t nitems, int sid)
Writes data for key.
size_t sion_fread_key(void *data, uint64_t key, size_t size, size_t nitems, int sid)
Read data for key.
int sion_get_current_locations(int sid, int *ntasks, int64_t **sion_currentpos, int64_t **sion_currentblocknr)
Returns current position in file and pointer fiels containing chunk sizes.
Definition: sion_common.c:177
int sion_lock_user_callbacks_defined(void)
Function which return flag, if user callback for locking are registered.
Definition: sion_common.c:788
int64_t sion_get_position(int sid)
Function that returns the current file position.
Definition: sion_common.c:612
int sion_get_endianness(void)
Return endianness.
Definition: sion_common.c:822
int sion_get_keyval_mode(int sid)
Return selected mode for key value.