libsc 2.8.7.187-a49fd
The SC library provides support for parallel scientific applications.
Loading...
Searching...
No Matches
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
50#ifndef SC_IO_H
51#define SC_IO_H
52
53#include <sc_containers.h>
54
58#define SC_CHECK_MPI_VERBOSE(errcode,user_msg) do { \
59 char sc_msg[sc_MPI_MAX_ERROR_STRING]; \
60 int sc_msglen; \
61 if ((errcode) != sc_MPI_SUCCESS) { \
62 sc_MPI_Error_string (errcode, sc_msg, &sc_msglen); \
63 SC_LERRORF ("%s at %s:%d: %s\n", \
64 (user_msg), __FILE__, __LINE__, sc_msg); \
65 }} while (0)
66
67SC_EXTERN_C_BEGIN;
68
79
88
96
106
123
143
155
168sc_io_sink_t *sc_io_sink_new (int iotype, int iomode,
169 int ioencode, ...);
170
179
192
201 const void *data, size_t bytes_avail);
202
222 size_t *bytes_in, size_t *bytes_out);
223
230 size_t bytes_align);
231
241sc_io_source_t *sc_io_source_new (int iotype, int ioencode, ...);
242
251
264
283 void *data, size_t bytes_avail,
284 size_t *bytes_out);
285
302 size_t *bytes_in,
303 size_t *bytes_out);
304
311 size_t bytes_align);
312
318
330 void *data,
331 size_t bytes_avail,
332 size_t *bytes_out);
333
341int sc_io_file_save (const char *filename,
342 sc_array_t * buffer);
343
353int sc_io_file_load (const char *filename,
354 sc_array_t * buffer);
355
383
427 int zlib_compression_level,
428 int line_break_character);
429
453 size_t *original_size,
454 char *format_char, void *re);
455
515 size_t max_original_size, void *re);
516
523int sc_vtk_write_binary (FILE * vtkfile, char *numeric_data,
524 size_t byte_length);
525
532int sc_vtk_write_compressed (FILE * vtkfile,
533 char *numeric_data,
534 size_t byte_length);
535
539FILE *sc_fopen (const char *filename, const char *mode,
540 const char *errmsg);
541
550void sc_fwrite (const void *ptr, size_t size,
551 size_t nmemb, FILE * file, const char *errmsg);
552
561void sc_fread (void *ptr, size_t size,
562 size_t nmemb, FILE * file, const char *errmsg);
563
567void sc_fflush_fsync_fclose (FILE * file);
568
590 const char *filename, sc_io_open_mode_t amode,
591 sc_MPI_Info mpiinfo, sc_MPI_File * mpifile);
592
593#define sc_mpi_read sc_io_read
607void sc_io_read (sc_MPI_File mpifile, void *ptr,
608 size_t zcount, sc_MPI_Datatype t,
609 const char *errmsg);
610
626 sc_MPI_Offset offset, void *ptr,
627 int count, sc_MPI_Datatype t,
628 int *ocount);
629
644 sc_MPI_Offset offset, void *ptr,
645 int count, sc_MPI_Datatype t,
646 int *ocount);
647
648#define sc_mpi_write sc_io_write
662void sc_io_write (sc_MPI_File mpifile, const void *ptr,
663 size_t zcount, sc_MPI_Datatype t,
664 const char *errmsg);
665
682 sc_MPI_Offset offset,
683 const void *ptr, int count,
684 sc_MPI_Datatype t, int *ocount);
685
701 sc_MPI_Offset offset,
702 const void *ptr, int count,
703 sc_MPI_Datatype t, int *ocount);
704
714
715SC_EXTERN_C_END;
716
717#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.
int sc_io_file_load(const char *filename, sc_array_t *buffer)
Read a file into a buffer in one call.
int sc_io_read_at_all(sc_MPI_File mpifile, sc_MPI_Offset offset, void *ptr, int count, sc_MPI_Datatype t, int *ocount)
Read MPI file content collectively into memory for an explicit offset.
int sc_io_write_at(sc_MPI_File mpifile, sc_MPI_Offset offset, const void *ptr, int count, sc_MPI_Datatype t, int *ocount)
Write MPI file content into memory for an explicit offset.
int sc_io_read_at(sc_MPI_File mpifile, sc_MPI_Offset offset, void *ptr, int count, sc_MPI_Datatype t, int *ocount)
Read MPI file content into memory for an explicit offset.
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:146
@ 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:148
@ SC_IO_WRITE_APPEND
append to an already existing file
Definition sc_io.h:152
@ SC_IO_READ
open a file in read-only mode
Definition sc_io.h:147
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.
sc_io_type_t
The type of I/O operation sc_io_sink and sc_io_source.
Definition sc_io.h:99
@ SC_IO_TYPE_FILEFILE
Write to an already opened file.
Definition sc_io.h:102
@ SC_IO_TYPE_LAST
Invalid entry to close list.
Definition sc_io.h:103
@ SC_IO_TYPE_FILENAME
Write to a file to be opened.
Definition sc_io.h:101
@ SC_IO_TYPE_BUFFER
Write to a buffer.
Definition sc_io.h:100
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_source_destroy_null(sc_io_source_t **source)
Free data source and NULL the pointer to it.
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_sink_destroy_null(sc_io_sink_t **sink)
Free data sink and NULL the pointer to it.
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.
int sc_io_write_at_all(sc_MPI_File mpifile, sc_MPI_Offset offset, const void *ptr, int count, sc_MPI_Datatype t, int *ocount)
Write MPI file content collectively into memory for an explicit offset.
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_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 a file context.
int sc_io_file_save(const char *filename, sc_array_t *buffer)
Save a buffer to a file in one call.
sc_io_mode_t
The I/O mode for writing using sc_io_sink.
Definition sc_io.h:82
@ SC_IO_MODE_LAST
Invalid entry to close list.
Definition sc_io.h:85
@ SC_IO_MODE_WRITE
Semantics as "w" in fopen.
Definition sc_io.h:83
@ SC_IO_MODE_APPEND
Semantics as "a" in fopen.
Definition sc_io.h:84
sc_io_encode_t
Enum to specify encoding for sc_io_sink and sc_io_source.
Definition sc_io.h:91
@ SC_IO_ENCODE_NONE
No encoding.
Definition sc_io.h:92
@ SC_IO_ENCODE_LAST
Invalid entry to close list.
Definition sc_io.h:93
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_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:72
@ SC_IO_ERROR_NONE
The value of zero means no error.
Definition sc_io.h:73
@ SC_IO_ERROR_FATAL
The io object is now dysfunctional.
Definition sc_io.h:74
@ SC_IO_ERROR_AGAIN
Another io operation may resolve it.
Definition sc_io.h:75
int sc_vtk_write_binary(FILE *vtkfile, char *numeric_data, size_t byte_length)
This function writes numeric binary data in VTK base64 encoding.
sc3_MPI_Datatype_t sc_MPI_Datatype
Emulate MPI datatypes.
Definition sc_mpi.h:462
sc3_MPI_Comm_t sc_MPI_Comm
Emulate an MPI communicator.
Definition sc_mpi.h:460
sc3_MPI_Info_t sc_MPI_Info
Emulate an MPI Info object.
Definition sc_mpi.h:461
long sc_MPI_Offset
Emulate the MPI offset type.
Definition sc_mpi.h:793
The sc_array object provides a dynamic array of equal-size elements.
Definition sc_containers.h:118
A generic data sink.
Definition sc_io.h:109
int is_eof
Have we reached the end of file?
Definition sc_io.h:120
sc_io_encode_t encode
encoding of data
Definition sc_io.h:112
size_t bytes_in
input bytes count
Definition sc_io.h:118
size_t buffer_bytes
distinguish from array elements
Definition sc_io.h:115
sc_io_type_t iotype
type of the I/O operation
Definition sc_io.h:110
sc_io_mode_t mode
write semantics
Definition sc_io.h:111
size_t bytes_out
written bytes count
Definition sc_io.h:119
FILE * file
file pointer for iotype unequal to SC_IO_TYPE_BUFFER
Definition sc_io.h:116
sc_array_t * buffer
buffer for the iotype SC_IO_TYPE_BUFFER
Definition sc_io.h:113
A generic data source.
Definition sc_io.h:126
sc_io_encode_t encode
encoding of data
Definition sc_io.h:128
size_t bytes_out
read bytes count
Definition sc_io.h:135
sc_io_sink_t * mirror
if activated, a sink to store the data
Definition sc_io.h:137
FILE * file
file pointer for iotype unequal to SC_IO_TYPE_BUFFER
Definition sc_io.h:132
int is_eof
Have we reached the end of file?
Definition sc_io.h:136
size_t bytes_in
input bytes count
Definition sc_io.h:134
sc_array_t * mirror_buffer
if activated, the buffer for the mirror
Definition sc_io.h:139
sc_io_type_t iotype
type of the I/O operation
Definition sc_io.h:127
size_t buffer_bytes
distinguish from array elements
Definition sc_io.h:131
sc_array_t * buffer
buffer for the iotype SC_IO_TYPE_BUFFER
Definition sc_io.h:129
Replacement structure for MPI_File.
Definition sc_mpi.h:799