libsc 2.8.5.210-64a7
The SC library provides support for parallel scientific applications.
sc_io.h
Go to the documentation of this file.
1/*
2 This file is part of the SC Library.
3 The SC Library provides support for parallel scientific applications.
4
5 Copyright (C) 2010 The University of Texas System
6 Additional copyright (C) 2011 individual authors
7
8 The SC Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 The SC Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with the SC Library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
22*/
23
66#ifndef SC_IO_H
67#define SC_IO_H
68
69#include <sc_containers.h>
70
74#define SC_CHECK_MPI_VERBOSE(errcode,user_msg) do { \
75 char sc_msg[sc_MPI_MAX_ERROR_STRING]; \
76 int sc_msglen; \
77 if ((errcode) != sc_MPI_SUCCESS) { \
78 sc_MPI_Error_string (errcode, sc_msg, &sc_msglen); \
79 SC_LERRORF ("%s at %s:%d: %s\n", \
80 (user_msg), __FILE__, __LINE__, sc_msg); \
81 }} while (0)
82
83SC_EXTERN_C_BEGIN;
84
87typedef enum
88{
95
97typedef enum
98{
104
106typedef enum
107{
112
114typedef enum
115{
122
124typedef struct sc_io_sink
125{
132 FILE *file;
134 size_t bytes_in;
135 size_t bytes_out;
136}
138
140typedef struct sc_io_source
141{
147 FILE *file;
149 size_t bytes_in;
150 size_t bytes_out;
155}
157
159typedef enum
160{
169
182sc_io_sink_t *sc_io_sink_new (int iotype, int iomode,
183 int ioencode, ...);
184
193
202 const void *data, size_t bytes_avail);
203
223 size_t *bytes_in, size_t *bytes_out);
224
231 size_t bytes_align);
232
242sc_io_source_t *sc_io_source_new (int iotype, int ioencode, ...);
243
252
269 void *data, size_t bytes_avail,
270 size_t *bytes_out);
271
288 size_t *bytes_in,
289 size_t *bytes_out);
290
297 size_t bytes_align);
298
304
316 void *data,
317 size_t bytes_avail,
318 size_t *bytes_out);
319
347
391 int zlib_compression_level,
392 int line_break_character);
393
417 size_t *original_size,
418 char *format_char, void *re);
419
479 size_t max_original_size, void *re);
480
487int sc_vtk_write_binary (FILE * vtkfile, char *numeric_data,
488 size_t byte_length);
489
496int sc_vtk_write_compressed (FILE * vtkfile,
497 char *numeric_data,
498 size_t byte_length);
499
503FILE *sc_fopen (const char *filename, const char *mode,
504 const char *errmsg);
505
514void sc_fwrite (const void *ptr, size_t size,
515 size_t nmemb, FILE * file, const char *errmsg);
516
525void sc_fread (void *ptr, size_t size,
526 size_t nmemb, FILE * file, const char *errmsg);
527
531void sc_fflush_fsync_fclose (FILE * file);
532
553 const char *filename, sc_io_open_mode_t amode,
554 sc_MPI_Info mpiinfo, sc_MPI_File * mpifile);
555
556#define sc_mpi_read sc_io_read
570void sc_io_read (sc_MPI_File mpifile, void *ptr,
571 size_t zcount, sc_MPI_Datatype t,
572 const char *errmsg);
573
587
607 sc_MPI_Offset offset, void *ptr,
608 int zcount, sc_MPI_Datatype t,
609 int *ocount);
610
624 sc_MPI_Offset offset, void *ptr,
625 int zcount, sc_MPI_Datatype t,
626 int *ocount);
627
642int sc_io_read_all (sc_MPI_File mpifile, void *ptr,
643 int zcount, sc_MPI_Datatype t,
644 int *ocount);
645
646#define sc_mpi_write sc_io_write
660void sc_io_write (sc_MPI_File mpifile, const void *ptr,
661 size_t zcount, sc_MPI_Datatype t,
662 const char *errmsg);
663
677
698 sc_MPI_Offset offset,
699 const void *ptr, int zcount,
700 sc_MPI_Datatype t, int *ocount);
701
723 sc_MPI_Offset offset,
724 const void *ptr, size_t zcount,
725 sc_MPI_Datatype t, int *ocount);
726
742 const void *ptr, size_t zcount,
743 sc_MPI_Datatype t, int *ocount);
744
753
754SC_EXTERN_C_END;
755
756#endif /* SC_IO_H */
Dynamic containers such as lists, arrays, and hash tables.
void sc_io_write(sc_MPI_File mpifile, const void *ptr, size_t zcount, sc_MPI_Datatype t, const char *errmsg)
Write memory content to an MPI file.
struct sc_io_sink sc_io_sink_t
A generic data sink.
void sc_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file, const char *errmsg)
Write memory content to a file.
sc_io_open_mode_t
Open modes for sc_io_open.
Definition: sc_io.h:160
@ SC_IO_WRITE_CREATE
open a file in write-only mode; if the file exists, the file will be truncated to length zero and the...
Definition: sc_io.h:162
@ SC_IO_WRITE_APPEND
append to an already existing file
Definition: sc_io.h:166
@ SC_IO_READ
open a file in read-only mode
Definition: sc_io.h:161
int sc_io_source_read_mirror(sc_io_source_t *source, void *data, size_t bytes_avail, size_t *bytes_out)
Read data from the source's mirror.
int sc_io_read_at(sc_MPI_File mpifile, sc_MPI_Offset offset, void *ptr, int zcount, sc_MPI_Datatype t, int *ocount)
Read MPI file content into memory for an explicit offset.
int sc_io_write_at_all(sc_MPI_File mpifile, sc_MPI_Offset offset, const void *ptr, size_t zcount, sc_MPI_Datatype t, int *ocount)
Write MPI file content collectively into memory for an explicit offset.
sc_io_type_t
The type of I/O operation sc_io_sink and sc_io_source.
Definition: sc_io.h:115
@ SC_IO_TYPE_FILEFILE
Write to an already opened file.
Definition: sc_io.h:118
@ SC_IO_TYPE_LAST
Invalid entry to close list.
Definition: sc_io.h:119
@ SC_IO_TYPE_FILENAME
Write to a file to be opened.
Definition: sc_io.h:117
@ SC_IO_TYPE_BUFFER
Write to a buffer.
Definition: sc_io.h:116
int sc_io_source_read(sc_io_source_t *source, void *data, size_t bytes_avail, size_t *bytes_out)
Read data from a source.
int sc_io_read_all(sc_MPI_File mpifile, void *ptr, int zcount, sc_MPI_Datatype t, int *ocount)
Read memory content collectively from an MPI file.
int sc_io_sink_write(sc_io_sink_t *sink, const void *data, size_t bytes_avail)
Write data to a sink.
int sc_io_read_at_legal(void)
Check for restricted usage of sc_io_read_at.
int sc_io_write_at_legal(void)
Check for restricted usage of sc_io_write_at.
void sc_io_encode_zlib(sc_array_t *data, sc_array_t *out, int zlib_compression_level, int line_break_character)
Encode a block of arbitrary data, compressed, into an ASCII string.
int sc_io_source_align(sc_io_source_t *source, size_t bytes_align)
Align source to a byte boundary by skipping.
sc_io_sink_t * sc_io_sink_new(int iotype, int iomode, int ioencode,...)
Create a generic data sink.
FILE * sc_fopen(const char *filename, const char *mode, const char *errmsg)
Wrapper for fopen(3).
sc_io_source_t * sc_io_source_new(int iotype, int ioencode,...)
Create a generic data source.
void sc_io_encode(sc_array_t *data, sc_array_t *out)
Encode a block of arbitrary data with the default sc_io format.
int sc_io_decode(sc_array_t *data, sc_array_t *out, size_t max_original_size, void *re)
Decode a block of base 64 encoded compressed data.
int sc_io_close(sc_MPI_File *file)
Close collectively a sc_MPI_File.
int sc_io_write_at(sc_MPI_File mpifile, sc_MPI_Offset offset, const void *ptr, int zcount, sc_MPI_Datatype t, int *ocount)
Write MPI file content into memory for an explicit offset.
int sc_io_source_destroy(sc_io_source_t *source)
Free data source.
int sc_io_decode_info(sc_array_t *data, size_t *original_size, char *format_char, void *re)
Decode length and format of original input from encoded data.
int sc_io_sink_destroy(sc_io_sink_t *sink)
Free data sink.
int sc_io_open(sc_MPI_Comm mpicomm, const char *filename, sc_io_open_mode_t amode, sc_MPI_Info mpiinfo, sc_MPI_File *mpifile)
Opens a MPI file or without MPI I/O or even without MPI a file context.
sc_io_mode_t
The I/O mode for writing using sc_io_sink.
Definition: sc_io.h:98
@ SC_IO_MODE_LAST
Invalid entry to close list.
Definition: sc_io.h:101
@ SC_IO_MODE_WRITE
Semantics as "w" in fopen.
Definition: sc_io.h:99
@ SC_IO_MODE_APPEND
Semantics as "a" in fopen.
Definition: sc_io.h:100
sc_io_encode_t
Enum to specify encoding for sc_io_sink and sc_io_source.
Definition: sc_io.h:107
@ SC_IO_ENCODE_NONE
No encoding.
Definition: sc_io.h:108
@ SC_IO_ENCODE_LAST
Invalid entry to close list.
Definition: sc_io.h:109
void sc_fread(void *ptr, size_t size, size_t nmemb, FILE *file, const char *errmsg)
Read file content into memory.
struct sc_io_source sc_io_source_t
A generic data source.
int sc_io_read_at_all(sc_MPI_File mpifile, sc_MPI_Offset offset, void *ptr, int zcount, sc_MPI_Datatype t, int *ocount)
Read MPI file content collectively into memory for an explicit offset.
int sc_io_source_activate_mirror(sc_io_source_t *source)
Activate a buffer that mirrors (i.e., stores) the data that was read.
void sc_io_read(sc_MPI_File mpifile, void *ptr, size_t zcount, sc_MPI_Datatype t, const char *errmsg)
Read MPI file content into memory.
int sc_io_sink_align(sc_io_sink_t *sink, size_t bytes_align)
Align sink to a byte boundary by writing zeros.
void sc_fflush_fsync_fclose(FILE *file)
Best effort to flush a file's data to disc and close it.
int sc_vtk_write_compressed(FILE *vtkfile, char *numeric_data, size_t byte_length)
This function writes numeric binary data in VTK compressed format.
int sc_io_sink_complete(sc_io_sink_t *sink, size_t *bytes_in, size_t *bytes_out)
Flush all buffered output data to sink.
int sc_io_source_complete(sc_io_source_t *source, size_t *bytes_in, size_t *bytes_out)
Determine whether all data buffered from source has been returned by read.
sc_io_error_t
Error values for io.
Definition: sc_io.h:88
@ SC_IO_ERROR_NONE
The value of zero means no error.
Definition: sc_io.h:89
@ SC_IO_ERROR_FATAL
The io object is now dysfunctional.
Definition: sc_io.h:90
@ SC_IO_ERROR_AGAIN
Another io operation may resolve it.
Definition: sc_io.h:91
int sc_vtk_write_binary(FILE *vtkfile, char *numeric_data, size_t byte_length)
This function writes numeric binary data in VTK base64 encoding.
int sc_io_write_all(sc_MPI_File mpifile, const void *ptr, size_t zcount, sc_MPI_Datatype t, int *ocount)
Write memory content collectively to an MPI file.
sc3_MPI_Datatype_t sc_MPI_Datatype
Emulate MPI datatypes.
Definition: sc_mpi.h:393
sc3_MPI_Comm_t sc_MPI_Comm
Emulate an MPI communicator.
Definition: sc_mpi.h:391
sc3_MPI_Info_t sc_MPI_Info
Emulate an MPI Info object.
Definition: sc_mpi.h:392
long sc_MPI_Offset
Emulate the MPI offset type.
Definition: sc_mpi.h:652
The sc_array object provides a dynamic array of equal-size elements.
Definition: sc_containers.h:91
A generic data sink.
Definition: sc_io.h:125
sc_io_encode_t encode
encoding of data
Definition: sc_io.h:128
size_t bytes_in
input bytes count
Definition: sc_io.h:134
size_t buffer_bytes
distinguish from array elems
Definition: sc_io.h:131
sc_io_type_t iotype
type of the I/O operation
Definition: sc_io.h:126
sc_io_mode_t mode
write semantics
Definition: sc_io.h:127
size_t bytes_out
written bytes count
Definition: sc_io.h:135
FILE * file
file pointer for iotype unequal to SC_IO_TYPE_BUFFER
Definition: sc_io.h:132
sc_array_t * buffer
buffer for the iotype SC_IO_TYPE_BUFFER
Definition: sc_io.h:129
A generic data source.
Definition: sc_io.h:141
sc_io_encode_t encode
encoding of data
Definition: sc_io.h:143
size_t bytes_out
read bytes count
Definition: sc_io.h:150
sc_io_sink_t * mirror
if activated, a sink to store the data
Definition: sc_io.h:151
FILE * file
file pointer for iotype unequal to SC_IO_TYPE_BUFFER
Definition: sc_io.h:147
size_t bytes_in
input bytes count
Definition: sc_io.h:149
sc_array_t * mirror_buffer
if activated, the buffer for the mirror
Definition: sc_io.h:153
sc_io_type_t iotype
type of the I/O operation
Definition: sc_io.h:142
size_t buffer_bytes
distinguish from array elems
Definition: sc_io.h:146
sc_array_t * buffer
buffer for the iotype SC_IO_TYPE_BUFFER
Definition: sc_io.h:144
Replacement structure for MPI_File.
Definition: sc_mpi.h:658