libsc  2.8.3.341-30a7-dirty
The SC library provides support for parallel scientific applications.
sc_io.h
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 
24 #ifndef SC_IO_H
25 #define SC_IO_H
26 
27 #include <sc_containers.h>
28 
32 #define SC_CHECK_MPI_VERBOSE(errcode,user_msg) do { \
33  char sc_msg[sc_MPI_MAX_ERROR_STRING]; \
34  int sc_msglen; \
35  if ((errcode) != sc_MPI_SUCCESS) { \
36  sc_MPI_Error_string (errcode, sc_msg, &sc_msglen); \
37  SC_LERRORF ("%s at %s:%d: %s\n", \
38  (user_msg), __FILE__, __LINE__, sc_msg); \
39  }} while (0)
40 
41 SC_EXTERN_C_BEGIN;
42 
45 typedef enum
46 {
47  SC_IO_ERROR_NONE,
48  SC_IO_ERROR_FATAL = -1,
49  SC_IO_ERROR_AGAIN = -2
51 }
52 sc_io_error_t;
53 
54 typedef enum
55 {
56  SC_IO_MODE_WRITE,
57  SC_IO_MODE_APPEND,
58  SC_IO_MODE_LAST
59 }
60 sc_io_mode_t;
61 
62 typedef enum
63 {
64  SC_IO_ENCODE_NONE,
65  SC_IO_ENCODE_LAST
66 }
67 sc_io_encode_t;
68 
69 typedef enum
70 {
71  SC_IO_TYPE_BUFFER,
72  SC_IO_TYPE_FILENAME,
73  SC_IO_TYPE_FILEFILE,
74  SC_IO_TYPE_LAST
75 }
76 sc_io_type_t;
77 
78 typedef struct sc_io_sink
79 {
80  sc_io_type_t iotype;
81  sc_io_mode_t mode;
82  sc_io_encode_t encode;
83  sc_array_t *buffer;
84  size_t buffer_bytes;
85  FILE *file;
86  size_t bytes_in;
87  size_t bytes_out;
88 }
90 
91 typedef struct sc_io_source
92 {
93  sc_io_type_t iotype;
94  sc_io_encode_t encode;
95  sc_array_t *buffer;
96  size_t buffer_bytes;
97  FILE *file;
98  size_t bytes_in;
99  size_t bytes_out;
100  sc_io_sink_t *mirror;
101  sc_array_t *mirror_buffer;
102 }
104 
105 typedef enum
106 {
107  SC_IO_READ,
108  SC_IO_WRITE_CREATE,
109  SC_IO_WRITE_APPEND
110 }
111 sc_io_open_mode_t;
112 
125 sc_io_sink_t *sc_io_sink_new (int iotype, int iomode,
126  int ioencode, ...);
127 
135 int sc_io_sink_destroy (sc_io_sink_t * sink);
136 
144 int sc_io_sink_write (sc_io_sink_t * sink,
145  const void *data, size_t bytes_avail);
146 
165 int sc_io_sink_complete (sc_io_sink_t * sink,
166  size_t *bytes_in, size_t *bytes_out);
167 
173 int sc_io_sink_align (sc_io_sink_t * sink,
174  size_t bytes_align);
175 
185 sc_io_source_t *sc_io_source_new (int iotype, int ioencode, ...);
186 
194 int sc_io_source_destroy (sc_io_source_t * source);
195 
211 int sc_io_source_read (sc_io_source_t * source,
212  void *data, size_t bytes_avail,
213  size_t *bytes_out);
214 
230 int sc_io_source_complete (sc_io_source_t * source,
231  size_t *bytes_in,
232  size_t *bytes_out);
233 
239 int sc_io_source_align (sc_io_source_t * source,
240  size_t bytes_align);
241 
246 int sc_io_source_activate_mirror (sc_io_source_t * source);
247 
253 int sc_io_source_read_mirror (sc_io_source_t * source,
254  void *data,
255  size_t bytes_avail,
256  size_t *bytes_out);
257 
262 int sc_io_have_zlib (void);
263 
290 void sc_io_encode (sc_array_t *data, sc_array_t *out);
291 
330 void sc_io_encode_zlib (sc_array_t *data, sc_array_t *out,
331  int zlib_compression_level);
332 
355 int sc_io_decode_info (sc_array_t *data,
356  size_t *original_size,
357  char *format_char, void *re);
358 
416 int sc_io_decode (sc_array_t *data, sc_array_t *out,
417  size_t max_original_size, void *re);
418 
425 int sc_vtk_write_binary (FILE * vtkfile, char *numeric_data,
426  size_t byte_length);
427 
434 int sc_vtk_write_compressed (FILE * vtkfile,
435  char *numeric_data,
436  size_t byte_length);
437 
441 FILE *sc_fopen (const char *filename, const char *mode,
442  const char *errmsg);
443 
452 void sc_fwrite (const void *ptr, size_t size,
453  size_t nmemb, FILE * file, const char *errmsg);
454 
463 void sc_fread (void *ptr, size_t size,
464  size_t nmemb, FILE * file, const char *errmsg);
465 
469 void sc_fflush_fsync_fclose (FILE * file);
470 
485 int sc_io_open (sc_MPI_Comm mpicomm,
486  const char *filename, sc_io_open_mode_t amode,
487  sc_MPI_Info mpiinfo, sc_MPI_File * mpifile);
488 
489 #ifdef SC_ENABLE_MPIIO
490 
491 #define sc_mpi_read sc_io_read
504 void sc_io_read (sc_MPI_File mpifile, void *ptr,
505  size_t zcount, sc_MPI_Datatype t,
506  const char *errmsg);
507 
508 #endif
509 
524 int sc_io_read_at (sc_MPI_File mpifile,
525  sc_MPI_Offset offset, void *ptr,
526  int zcount, sc_MPI_Datatype t,
527  int *ocount);
528 
542 int sc_io_read_at_all (sc_MPI_File mpifile,
543  sc_MPI_Offset offset, void *ptr,
544  int zcount, sc_MPI_Datatype t,
545  int *ocount);
546 
557 int sc_io_read_all (sc_MPI_File mpifile, void *ptr,
558  int zcount, sc_MPI_Datatype t,
559  int *ocount);
560 
561 #ifdef SC_ENABLE_MPIIO
562 
563 #define sc_mpi_write sc_io_write
576 void sc_io_write (sc_MPI_File mpifile, const void *ptr,
577  size_t zcount, sc_MPI_Datatype t,
578  const char *errmsg);
579 
580 #endif
581 
596 int sc_io_write_at (sc_MPI_File mpifile,
597  sc_MPI_Offset offset,
598  const void *ptr, size_t zcount,
599  sc_MPI_Datatype t, int *ocount);
600 
618 int sc_io_write_at_all (sc_MPI_File mpifile,
619  sc_MPI_Offset offset,
620  const void *ptr, size_t zcount,
621  sc_MPI_Datatype t, int *ocount);
622 
634 int sc_io_write_all (sc_MPI_File mpifile,
635  const void *ptr, size_t zcount,
636  sc_MPI_Datatype t, int *ocount);
637 
645 int sc_io_close (sc_MPI_File * file);
646 
647 SC_EXTERN_C_END;
648 
649 #endif /* SC_IO_H */
Dynamic containers such as lists, arrays, and hash tables.
sc3_MPI_Datatype_t sc_MPI_Datatype
Emulate MPI datatypes.
Definition: sc_mpi.h:394
sc3_MPI_Comm_t sc_MPI_Comm
Emulate an MPI communicator.
Definition: sc_mpi.h:392
sc3_MPI_Info_t sc_MPI_Info
Emulate an MPI Info object.
Definition: sc_mpi.h:393
long sc_MPI_Offset
Emulate the MPI offset type.
Definition: sc_mpi.h:637
The sc_array object provides a dynamic array of equal-size elements.
Definition: sc_containers.h:91
Definition: sc_io.h:79
size_t buffer_bytes
distinguish from array elems
Definition: sc_io.h:84
Definition: sc_io.h:92
size_t buffer_bytes
distinguish from array elems
Definition: sc_io.h:96
Replacement structure for MPI_File.
Definition: sc_mpi.h:643