SIONlib  2.0.0-rc.2
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-2019 **
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 /* I/O */
61 size_t sion_write(const void *data, size_t size, size_t nitems, int sid);
62 
66 size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid);
67 
88 size_t sion_read(void *data, size_t size, size_t nitems, int sid);
89 
93 size_t sion_fread(void *data, size_t size, size_t nitems, int sid);
94 
95 /* helper functions */
110 int sion_eof(int sid);
111 
115 int sion_feof(int sid);
116 
139 int sion_ensure_free_space(int sid, int64_t bytes);
140 
148 int sion_flush(int sid);
149 
150 /* get size of internal data structure */
160 int sion_get_sizeof(int sid, int *numbytes, int *numfds);
161 
162 /* duplicate fd (only parallel read-mode) */
178 int sion_dup(int sid, int mode, int rank, uint64_t key);
179 
188 int sion_dedup(int sid);
189 
190 /* special helper functions, for used with szlib */
191 int sion_optimize_fp_buffer(int sid);
192 
193 /* get information (with sion datatypes) */
201 int sion_get_file_endianness(int sid);
202 
210 int sion_endianness_swap_needed(int sid);
211 int64_t sion_get_bytes_written(int sid);
212 int64_t sion_get_bytes_read(int sid);
213 
226 int64_t sion_bytes_avail_in_block(int sid);
227 
239 int64_t sion_bytes_avail_in_chunk(int sid);
240 
254 int64_t sion_get_position(int sid);
255 
273 int sion_get_mapping(int sid, int *mapping_size, int32_t **mapping, int *numfiles);
274 
308 int sion_get_locations(int sid, int *ntasks, int *maxchunks, int64_t *globalskip, int64_t *start_of_varheader,
309  int64_t **sion_chunksizes, int64_t **sion_globalranks, int64_t **sion_blockcount, int64_t **sion_blocksizes);
310 
311 /* parallel mode */
332 int sion_get_current_location(int sid, int *currentchunknr, int64_t *currentpos, int *maxchunks, int64_t **chunksizes);
333 
334 /* serial mode */
354 int sion_get_current_locations(int sid, int *ntasks, int64_t **sion_currentpos, int64_t **sion_currentblocknr);
355 int sion_get_number_of_files(int sid);
356 int sion_get_filenumber(int sid);
357 
358 int sion_get_number_of_logical_files(int sid);
359 
360 int64_t *sion_get_chunksizes(int sid);
361 
362 int32_t sion_get_fsblksize(int sid);
363 
364 /* 1 is opened with sion_open or sion_open_rank */
365 int sion_is_serial_opened(int sid);
366 
367 /* 1 if using GPFS or Linux hints */
368 int sion_using_hints(int sid);
369 
370 /* return current endianness (1-> big endian, 0 ->little endian) */
377 int sion_get_endianness(void);
378 
379 /* return if SIONlib supports PTHREADS (Thread-safe) 1 -> yes, 0 -> no */
380 int sion_is_thread_safe(void);
381 
382 /* return version numbers */
388 int sion_get_version(int *main_version, int *sub_version, int *patch_level, int *fileformat_version);
389 
390 typedef struct _sion_io_stat_struct sion_io_stat_t;
392  int nfiles;
393  const char **names;
394  size_t *sizes;
395  int *roles;
396 };
397 
398 /* return info about accessed (local) files on this task */
399 sion_io_stat_t *sion_get_io_info(int sid);
400 
401 /* return info about accessed (local) files on this task */
402 sion_io_stat_t *sion_get_io_info_by_spec(int sid, int roles, int flag);
403 int sion_free_io_info(sion_io_stat_t *info);
404 
405 /* Seeking */
428 int sion_seek(int sid, int64_t offset, sion_seek_mode whence);
429 
436 //
447 int sion_seek_chunk(int sid, int32_t offset, sion_seek_mode whence);
448 
463 int sion_switch_logical_file(int sid, int file_number);
464 
470 int64_t sion_tell(int sid);
471 
472 /* register user defined lock and unlock routines, which are needed to access shared data structures internally */
483 int sion_lock_register_lock_callbacks(int lock(void *), int unlock(void *), void *lock_data);
484 
491 
492 /* Utilities */
506 void sion_swap(void *target, void *source, int size, int n, int do_swap);
507 
508 char *sion_get_fname(int sid);
509 int64_t sion_get_chunksize(int sid);
510 int32_t sion_get_globalrank(int sid);
511 
682 
683 struct _sion_key_stat_struct;
684 
699 size_t sion_write_key(const void *data, uint64_t key, size_t size, size_t nitems, int sid);
700 
704 size_t sion_fwrite_key(const void *data, uint64_t key, size_t size, size_t nitems, int sid);
705 
722 size_t sion_read_key(void *data, uint64_t key, size_t size, size_t nitems, int sid);
723 
727 size_t sion_fread_key(void *data, uint64_t key, size_t size, size_t nitems, int sid);
728 
729 /* iterator for key-value pairs */
737 int sion_read_key_iterator_reset(int sid);
738 
742 int sion_fread_key_iterator_reset(int sid);
743 
757 int sion_read_key_iterator_next(int sid, uint64_t *key, size_t *size);
758 
762 int sion_fread_key_iterator_next(int sid, uint64_t *key, size_t *size);
763 
780 int sion_seek_key(int sid, uint64_t key, int entrynum, int64_t posinentry);
781 
789 int sion_key_full_scan(int sid);
790 
798 int sion_key_list_iterator_reset(int sid);
799 
808 int sion_key_list_iterator_next(int sid, uint64_t *keyptr);
809 
812  uint64_t key;
813  int64_t num_blocks;
814  int64_t total_size;
815 };
816 
826 int sion_key_get_stat(int sid, uint64_t key, sion_key_stat_t *stat);
827 
835 int sion_get_keyval_mode(int sid);
836 
844 char *sion_keyval_type_to_str(int type);
845 
847 
848 #ifdef __cplusplus
849 }
850 #endif
851 
852 /* Debugging */
853 #ifndef DPRINTF
854 #define DPRINTF(A)
855 #define DPRINTFP(A)
856 #define DPRINTTS(A, B)
857 #define DPRINTFTS2(A, B)
858 #endif
859 
861 
862 #endif
size_t sion_read_key(void *data, uint64_t key, size_t size, size_t nitems, int sid)
Read data for key.
int sion_dedup(int sid)
Function which destroy a duplicated sion file descriptor.
Definition: sion_common.c:729
sion_seek_mode
determines how offsets are interpreted for seek operations
Definition: sion_enums.h:49
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:109
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:35
int sion_dup(int sid, int mode, int rank, uint64_t key)
Function which duplicates a sion file descriptor.
Definition: sion_common.c:704
int sion_read_key_iterator_next(int sid, uint64_t *key, size_t *size)
Forward to next key.
int64_t sion_bytes_avail_in_block(int sid)
Return the number of bytes available in the current chunk.
Definition: sion_common.c:560
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:682
int64_t sion_tell(int sid)
Inspect position of file pointer in logical file.
Definition: sion_common.c:524
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:389
int sion_fread_key_iterator_next(int sid, uint64_t *key, size_t *size)
Forward to next key.
size_t sion_read(void *data, size_t size, size_t nitems, int sid)
Read data from SIONlib file.
Definition: sion_common.c:353
int sion_feof(int sid)
Function that indicates whether the end of this logical file has been reached.
Definition: sion_common.c:555
size_t sion_write(const void *data, size_t size, size_t nitems, int sid)
Write data to a SIONlib file.
Definition: sion_common.c:292
int sion_endianness_swap_needed(int sid)
Returns whether or not byte swapping is needed for sid.
Definition: sion_common.c:147
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:743
size_t sion_fread(void *data, size_t size, size_t nitems, int sid)
Read data from a SIONlib file.
Definition: sion_common.c:384
int sion_get_file_endianness(int sid)
Returns edianness of data in file sid.
Definition: sion_common.c:132
int sion_eof(int sid)
Function that indicates whether the end of this logical file has been reached.
Definition: sion_common.c:534
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:824
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:565
int sion_switch_logical_file(int sid, int file_number)
moves the file pointer to a different logical file
Definition: sion_common.c:479
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:432
int sion_flush(int sid)
Flushed sion file.
Definition: sion_common.c:624
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:90
int sion_seek_key(int sid, uint64_t key, int entrynum, int64_t posinentry)
Seek to position in key.
int sion_read_key_iterator_reset(int sid)
Resets key iterator.
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)
Function to ensure that enough space is available for writing.
Definition: sion_common.c:634
size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid)
Write data to a SIONlib file.
Definition: sion_common.c:348
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:160
int sion_lock_user_callbacks_defined(void)
Function which return flag, if user callback for locking are registered.
Definition: sion_common.c:757
int64_t sion_get_position(int sid)
Function that returns the current file position.
Definition: sion_common.c:590
size_t sion_write_key(const void *data, uint64_t key, size_t size, size_t nitems, int sid)
Writes data for key.
int sion_get_endianness(void)
Return endianness.
Definition: sion_common.c:812
int sion_get_keyval_mode(int sid)
Return selected mode for key value.