SIONlib  1.6.1
Scalable I/O library for parallel access to task-local files
sion_common.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2015 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
16 #ifndef SION_SION_COMMON_H
17 #define SION_SION_COMMON_H
18 
19 /* SIONlib PUBLIC Interface: common */
20 
21 #include <stdio.h>
22 #include <stdint.h>
23 
24 #include "sion_platform.h"
25 #include "sion_datatypes.h"
26 
27 /* default mode */
28 #define SION_SERIAL_MASTER
29 
30 #define SION_MAX_FSBLOCKSIZE 32*1024*1024
31 #define SION_DEFAULT_FSBLOCKSIZE 2*1024*1024
32 
33 #define SION_FILENAME_LENGTH 1024
34 
35 #define SION_DIFFSIZE 1
36 #define SION_DUMMY 2
37 #define MAXCHUNKS 100
39 #define WFLARGEMETABLOCK_none /* for BENCHMARKING only */
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 
46  int _sion_close_sid(int sid);
47 
48  /* I/O */
49  size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid);
50  size_t sion_fread( void *data, size_t size, size_t nitems, int sid);
51 
52  /* I/O: key-value */
53  size_t sion_fwrite_key(const void *data, uint64_t key, size_t size, size_t nitems, int sid);
54  size_t sion_fread_key(void *data, uint64_t key, size_t size, size_t nitems, int sid);
55 
56  /* iterator for key-value pairs */
57  int sion_fread_key_iterator_reset(int sid);
58  int sion_fread_key_iterator_next(int sid, uint64_t *key, size_t *size);
59 
60  /* seek for key-value */
61  int sion_seek_key(int sid, uint64_t key, int entrynum, sion_int64 posinentry );
62 
63  /* scans input file for all information about all keys of this rank */
64  int sion_key_full_scan(int sid);
65 
66  /* iterator for list of keys */
67  int sion_key_list_iterator_reset(int sid);
68  int sion_key_list_iterator_next(int sid, uint64_t *keyptr);
69 
70  typedef struct _sion_key_stat_struct sion_key_stat_t;
72  uint64_t key;
73  sion_int64 num_blocks;
74  sion_int64 total_size;
75  };
76 
77  /* fills a stat-data structure containing information about the key */
78  int sion_key_get_stat(int sid, uint64_t key, sion_key_stat_t *stat);
79 
80  /* helper functions */
81  int sion_feof(int sid);
82  int sion_ensure_free_space(int sid, sion_int64 bytes);
83 
84  int sion_flush(int sid);
85 
86  /* get size of internal data structure */
87  int sion_get_sizeof(int sid, int *numbytes, int *numfds);
88 
89  /* duplicate fd (only parallel read-mode) */
90  int sion_dup(int sid, int mode, int rank, uint64_t key);
91  int sion_dedup(int sid);
92 
93  /* special helper functions, for used with szlib */
94  int sion_set_fp_closed(int sid);
95  int sion_set_second_fp(int sid, FILE *fp);
96  int sion_unset_second_fp(int sid);
97  FILE * sion_get_fp(int sid);
98  int sion_get_fd(int sid);
99  int sion_optimize_fp_buffer(int sid);
100 
101 
102  /* get information (with sion datatypes) */
103  int sion_get_file_endianness(int sid);
104  int sion_endianness_swap_needed(int sid);
105  sion_int64 sion_get_bytes_written(int sid);
106  sion_int64 sion_get_bytes_read(int sid);
107  sion_int64 sion_bytes_avail_in_block( int sid );
108  sion_int64 sion_bytes_avail_in_chunk( int sid );
109  sion_int64 sion_get_position( int sid );
110 
111  int sion_get_mapping( int sid,
112  int *mapping_size,
113  sion_int32 **mapping,
114  int *numfiles );
115 
116  int sion_get_locations( int sid,
117  int *ntasks,
118  int *maxblocks,
119  sion_int64 *globalskip,
120  sion_int64 *start_of_varheader,
121  sion_int64 **sion_localsizes,
122  sion_int64 **sion_globalranks,
123  sion_int64 **sion_blockcount,
124  sion_int64 **sion_blocksizes);
125  /* parallel mode */
126  int sion_get_current_location( int sid,
127  int *currentblock,
128  sion_int64 *currentpos,
129  int *maxchunks,
130  sion_int64 **chunksizes );
131  /* serial mode */
132  int sion_get_current_locations( int sid,
133  int *ntasks,
134  sion_int64 **sion_currentpos,
135  sion_int64 **sion_currentblocknr );
136  int sion_get_number_of_files( int sid );
137  int sion_get_filenumber( int sid );
138 
139  /* 1 is opened with sion_open or sion_open_rank */
140  int sion_is_serial_opened( int sid );
141 
142  /* 1 if using GPFS or Linux hints */
143  int sion_using_hints(int sid);
144 
145  /* return current endianness (1-> big endian, 0 ->little endian) */
146  int sion_get_endianness(void);
147 
148  /* return if SIONlib supports PTHREADS (Thread-safe) 1 -> yes, 0 -> no */
149  int sion_is_thread_safe(void);
150 
151  /* return keyvalue mode (constants described in sion_const.h) */
152  int sion_get_keyval_mode(int sid);
153  char* sion_keyval_type_to_str(int type); /* converts keyval mode to character string */
154 
155 
156  /* return version numbers */
157  int sion_get_version(int *main_version, int *sub_version, int *patch_level, int *fileformat_version);
158 
159  /* Seeking */
160  int sion_seek( int sid,
161  int rank,
162  int currentblocknr,
163  sion_int64 posinblk );
164 
165  int sion_seek_fp( int sid,
166  int rank,
167  int currentblocknr,
168  sion_int64 posinblk,
169  FILE **fileptr
170  );
171 
172  /* register user defined lock and unlock routines, which are needed to access shared data structures internally */
173  int sion_lock_register_lock_callbacks(int lock(void *), int unlock(void *), void *lock_data);
175 
176 
177  /* Utilities */
178 
179  /* perform byte-order swapping for arrays n units of size byte are
180  swapped if and only if aflag==0 in-place swapping (target==source)
181  is allowed if target != source, the buffers must not overlap */
182  void sion_swap(void *target, void *source, int size, int n, int aflag);
183 
184  /* for backward compatibility */
185 #define _sion_stat_file _sion_file_stat_file
186  int _sion_file_stat_file(const char *fname);
187 
188 #ifdef __cplusplus
189 }
190 #endif
191 
192  /* Debugging */
193 #ifndef DPRINTF
194 #define DPRINTF(A)
195 #define DPRINTFP(A)
196 #define DPRINTTS(A,B)
197 #define DPRINTFTS2(A,B)
198 #endif
199 
200 
201 #endif
int sion_seek_key(int sid, uint64_t key, int entrynum, sion_int64 posinentry)
Seek to position in key.
int sion_key_list_iterator_next(int sid, uint64_t *keyptr)
Forward to next key.
int sion_get_endianness(void)
Return endianness.
Definition: sion_tools.c:26
int sion_get_file_endianness(int sid)
Returns edianness of data in file sid.
Definition: sion_common.c:246
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:731
int sion_dedup(int sid)
Function which destroy a duplicated sion file descriptor.
Definition: sion_common.c:1115
int sion_seek(int sid, int rank, int currentblocknr, sion_int64 posinblk)
Function to set the file pointer to a new position.
Definition: sion_common.c:620
sion_int64 sion_bytes_avail_in_block(int sid)
Return the number of bytes available in the current chunk.
Definition: sion_common.c:801
int sion_get_current_locations(int sid, int *ntasks, sion_int64 **sion_currentpos, sion_int64 **sion_currentblocknr)
Returns current position in file and pointer fiels containing chunk sizes.
Definition: sion_common.c:300
int sion_lock_user_callbacks_defined(void)
Function which return flag, if user callback for locking are registered.
Definition: sion_common.c:1159
int sion_get_locations(int sid, int *ntasks, int *maxblocks, sion_int64 *globalskip, sion_int64 *start_of_varheader, sion_int64 **sion_localsizes, sion_int64 **sion_globalranks, sion_int64 **sion_blockcount, sion_int64 **sion_blocksizes)
Returns pointers to internal fields.
Definition: sion_common.c:80
int sion_get_mapping(int sid, int *mapping_size, sion_int32 **mapping, int *numfiles)
Returns pointers to the internal field mapping.
Definition: sion_common.c:212
size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid)
Write data to sion file.
Definition: sion_common.c:432
int sion_endianness_swap_needed(int sid)
Returns whether or not byte swapping is needed for sid.
Definition: sion_common.c:270
char * sion_keyval_type_to_str(int type)
Returns key value mode as string.
int sion_flush(int sid)
Flushed sion file.
Definition: sion_common.c:952
int sion_dup(int sid, int mode, int rank, uint64_t key)
Function which duplicates a sion file descriptor.
Definition: sion_common.c:1081
int sion_get_version(int *main_version, int *sub_version, int *patch_level, int *fileformat_version)
Return version numbers.
Definition: sion_tools.c:45
int sion_fread_key_iterator_reset(int sid)
Resets key iterator.
int sion_key_list_iterator_reset(int sid)
Resets key iterator.
sion_int64 sion_bytes_avail_in_chunk(int sid)
Function that returns the number of bytes available in the current chunk.
Definition: sion_common.c:816
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:1140
int sion_get_keyval_mode(int sid)
Return selected mode for key value.
int sion_ensure_free_space(int sid, sion_int64 bytes)
Funtion to ensure that enough space is available for writing.
Definition: sion_common.c:975
size_t sion_fread(void *data, size_t size, size_t nitems, int sid)
Read data from sion file.
Definition: sion_common.c:552
int sion_seek_fp(int sid, int rank, int currentblocknr, sion_int64 posinblk, FILE **fileptr)
Deprecated. Use sion_seek() instead.
Definition: sion_common.c:643
int sion_key_full_scan(int sid)
Performs a full scan of all meta data in current file.
int _sion_file_stat_file(const char *fname)
Check if file exists (LARGE_FILE support on BlueGene)
Definition: sion_file.c:204
size_t sion_fread_key(void *data, uint64_t key, size_t size, size_t nitems, int sid)
Read data for key.
size_t sion_fwrite_key(const void *data, uint64_t key, size_t size, size_t nitems, int sid)
Writes data for key.
int sion_key_get_stat(int sid, uint64_t key, sion_key_stat_t *stat)
get statistics about key
sion_int64 sion_get_position(int sid)
Function that returns the current file position.
Definition: sion_common.c:852
void sion_swap(void *target, void *source, int size, int n, int aflag)
Definition: sion_convert.c:36
int sion_get_current_location(int sid, int *currentblock, sion_int64 *currentpos, int *maxchunks, sion_int64 **chunksizes)
Returns current position in file and pointer fiels containing chunk sizes.
Definition: sion_common.c:178
int sion_get_sizeof(int sid, int *numbytes, int *numfds)
Function returns size of internal data structure for sid.
Definition: sion_common.c:1043