7.0
general documentation
cs_file.h
Go to the documentation of this file.
1 #ifndef __CS_FILE_H__
2 #define __CS_FILE_H__
3 
4 /*============================================================================
5  * File and directory operations, with parallel file I/O
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2021 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 #if defined(HAVE_MPI)
31 #include <mpi.h>
32 #endif
33 
34 /*----------------------------------------------------------------------------
35  * Local headers
36  *----------------------------------------------------------------------------*/
37 
38 #include "cs_defs.h"
39 
40 /*----------------------------------------------------------------------------*/
41 
43 
44 /*=============================================================================
45  * Macro definitions
46  *============================================================================*/
47 
48 /*============================================================================
49  * Type definitions
50  *============================================================================*/
51 
52 /* File descriptor */
53 
54 typedef struct _cs_file_t cs_file_t;
55 
56 /* Helper structure for IO serialization */
57 
58 #if defined(HAVE_MPI)
59 typedef struct _cs_file_serializer_t cs_file_serializer_t;
60 #endif
61 
62 /* File modes */
63 
64 typedef enum {
65 
66  CS_FILE_MODE_READ, /* Read mode */
67  CS_FILE_MODE_WRITE, /* Write mode */
68  CS_FILE_MODE_APPEND /* Append mode */
69 
71 
72 /* Possibilities for the third argument of cs_file_seek() */
73 
74 typedef enum {
75 
76  CS_FILE_SEEK_SET, /* Seek from beginning of file */
77  CS_FILE_SEEK_CUR, /* Seek from current position */
78  CS_FILE_SEEK_END /* Seek from end of file */
79 
81 
82 /* File access methods */
83 
84 typedef enum {
85 
92 
94 
95 /* MPI-IO file positioning methods */
96 
97 typedef enum {
98 
101 
103 
104 /* Offset for file position indicator (int64_t in C99) */
105 
106 #if defined(SIZEOF_LONG_LONG)
107 typedef long long cs_file_off_t;
108 #else
109 typedef long cs_file_off_t;
110 #endif
111 
112 /*=============================================================================
113  * Global variables
114  *============================================================================*/
115 
116 /* names associated with file access methods */
117 
118 extern const char *cs_file_access_name[];
119 
120 /* names associated with MPI-IO positioning */
121 
122 extern const char *cs_file_mpi_positioning_name[];
123 
124 /*=============================================================================
125  * Public function prototypes
126  *============================================================================*/
127 
128 /*----------------------------------------------------------------------------
129  * Create a file descriptor and open the associated file.
130  *
131  * By default, data is written or read as native data. This behavior may be
132  * modified by cs_file_set_swap_endian().
133  *
134  * parameters:
135  * name <-- file name
136  * mode <-- file access mode: read, write, or append
137  * method <-- file access method
138  * hints <-- associated hints for MPI-IO, or MPI_INFO_NULL
139  * block_comm <-- handle to MPI communicator used for distributed file
140  * block access (may be a subset of comm if some ranks do
141  * not directly access distributed data blocks)
142  * comm <-- handle to main MPI communicator
143  *
144  * returns:
145  * pointer to cs_file_t file descriptor (NULL in case of failure);
146  * currently, errors are fatal.
147  *----------------------------------------------------------------------------*/
148 
149 #if defined(HAVE_MPI)
150 
151 cs_file_t *
152 cs_file_open(const char *name,
153  cs_file_mode_t mode,
154  cs_file_access_t method,
155  MPI_Info hints,
156  MPI_Comm block_comm,
157  MPI_Comm comm);
158 
159 #else
160 
161 cs_file_t *
162 cs_file_open(const char *name,
163  cs_file_mode_t mode,
164  cs_file_access_t method);
165 
166 #endif
167 
168 /*----------------------------------------------------------------------------
169  * Create a file descriptor and open the associated file, using the default
170  * file communicator and access method.
171  *
172  * By default, data is written or read as native data. This behavior may be
173  * modified by cs_file_set_swap_endian().
174  *
175  * parameters:
176  * name <-- file name
177  * mode <-- file access mode: read, write, or append
178  *
179  * returns:
180  * pointer to cs_file_t file descriptor (NULL in case of failure);
181  * currently, errors are fatal.
182  *----------------------------------------------------------------------------*/
183 
184 cs_file_t *
185 cs_file_open_default(const char *name,
186  cs_file_mode_t mode);
187 
188 /*----------------------------------------------------------------------------*/
202 /*----------------------------------------------------------------------------*/
203 
204 cs_file_t *
205 cs_file_open_serial(const char *name,
206  cs_file_mode_t mode);
207 
208 /*----------------------------------------------------------------------------
209  * Destroy a file descriptor and close the associated file.
210  *
211  * parameters:
212  * f <-> file descriptor to destroy
213  *
214  * returns:
215  * NULL pointer
216  *----------------------------------------------------------------------------*/
217 
218 cs_file_t *
220 
221 /*----------------------------------------------------------------------------
222  * Return a file's name.
223  *
224  * parameters:
225  * f <-- cs_file_t descriptor
226  *
227  * returns:
228  * pointer to the file's name.
229  *----------------------------------------------------------------------------*/
230 
231 const char *
232 cs_file_get_name(const cs_file_t *f);
233 
234 /*----------------------------------------------------------------------------
235  * Ensure that data is read or written in big-endian
236  * (network standard) format.
237  *
238  * parameters:
239  * f <-> cs_file_t descriptor
240  *----------------------------------------------------------------------------*/
241 
242 void
244 
245 /*----------------------------------------------------------------------------
246  * Return a file's byte-swapping behavior.
247  *
248  * parameters:
249  * f <-- cs_file_t descriptor
250  *
251  * returns:
252  * 0 if file's endianness is the same as the system's, 1 otherwise.
253  *----------------------------------------------------------------------------*/
254 
255 int
257 
258 /*----------------------------------------------------------------------------
259  * Set a file's byte-swapping behavior.
260  *
261  * Using this function assumes one is familiar with a file's coding
262  * or structure; use with caution.
263  *
264  * parameters:
265  * f <-> cs_file_t descriptor
266  * swap <-- 1 if bytes must be swapped, 0 otherwise
267  *----------------------------------------------------------------------------*/
268 
269 void
271  int swap);
272 
273 /*----------------------------------------------------------------------------
274  * Read global data from a file, distributing it to all processes
275  * associated with that file.
276  *
277  * parameters:
278  * f <-- cs_file_t descriptor
279  * buf --> pointer to location receiving data
280  * size <-- size of each item of data in bytes
281  * ni <-- number of items to read
282  *
283  * returns:
284  * the number of items (not bytes) sucessfully read; currently,
285  * errors are fatal.
286  *----------------------------------------------------------------------------*/
287 
288 size_t
290  void *buf,
291  size_t size,
292  size_t ni);
293 
294 /*----------------------------------------------------------------------------
295  * Write global data to a file.
296  *
297  * Under MPI, data is only written by the associated communicator's root
298  * rank. The buffers on other ranks are ignored, though the file offset
299  * is updated (i.e. the call to this function is collective).
300  *
301  * parameters:
302  * f <-- cs_file_t descriptor
303  * buf <-- pointer to location containing data
304  * size <-- size of each item of data in bytes
305  * ni <-- number of items to read
306  *
307  * returns:
308  * the number of items (not bytes) sucessfully written; currently,
309  * errors are fatal.
310  *----------------------------------------------------------------------------*/
311 
312 size_t
314  const void *buf,
315  size_t size,
316  size_t ni);
317 
318 /*----------------------------------------------------------------------------
319  * Read data to a buffer, distributing a contiguous part of it to each
320  * process associated with a file.
321  *
322  * Each process should receive a (possibly empty) block of the data,
323  * and we should have:
324  * global_num_start at rank 0 = 1
325  * global_num_start at rank i+1 = global_num_end at rank i.
326  * Otherwise, behavior (especially positioning for future reads) is undefined.
327  *
328  * parameters:
329  * f <-- cs_file_t descriptor
330  * buf --> pointer to location receiving data
331  * size <-- size of each item of data in bytes
332  * stride <-- number of (interlaced) values per block item
333  * global_num_start <-- global number of first block item (1 to n numbering)
334  * global_num_end <-- global number of past-the end block item
335  * (1 to n numbering)
336  *
337  * returns:
338  * the (local) number of items (not bytes) sucessfully read; currently,
339  * errors are fatal.
340  *----------------------------------------------------------------------------*/
341 
342 size_t
344  void *buf,
345  size_t size,
346  size_t stride,
347  cs_gnum_t global_num_start,
348  cs_gnum_t global_num_end);
349 
350 /*----------------------------------------------------------------------------
351  * Write data to a file, each associated process providing a contiguous part
352  * of this data.
353  *
354  * Each process should provide a (possibly empty) block of the data,
355  * and we should have:
356  * global_num_start at rank 0 = 1
357  * global_num_start at rank i+1 = global_num_end at rank i.
358  * Otherwise, behavior (especially positioning for future reads) is undefined.
359  *
360  * This function may require an internal copy of the data to ensure that
361  * the buffer contents are not modified, so if the buffer contents are
362  * temporary values, to be deleted after writing, using
363  * cs_file_write_block_buffer() instead may be used to avoid an unneeded
364  * memory allocation and copy.
365  *
366  * parameters:
367  * f <-- cs_file_t descriptor
368  * buf <-- pointer to location containing data
369  * size <-- size of each item of data in bytes
370  * stride <-- number of (interlaced) values per block item
371  * global_num_start <-- global number of first block item (1 to n numbering)
372  * global_num_end <-- global number of past-the end block item
373  * (1 to n numbering)
374  *
375  * returns:
376  * the (local) number of items (not bytes) sucessfully written; currently,
377  * errors are fatal.
378  *----------------------------------------------------------------------------*/
379 
380 size_t
382  const void *buf,
383  size_t size,
384  size_t stride,
385  cs_gnum_t global_num_start,
386  cs_gnum_t global_num_end);
387 
388 /*----------------------------------------------------------------------------
389  * Write data to a file, each associated process providing a contiguous part
390  * of this data.
391  *
392  * Each process should provide a (possibly empty) block of the data,
393  * and we should have:
394  * global_num_start at rank 0 = 1
395  * global_num_start at rank i+1 = global_num_end at rank i.
396  * Otherwise, behavior (especially positioning for future reads) is undefined.
397  *
398  * This function is intended to be used mainly data that is already a
399  * copy of original data (such as data that has been redistributed across
400  * processors just for the sake of output), or that is to be deleted after
401  * writing, so it may modify the values in its input buffer (notably to
402  * convert from little-endian to big-endian of vice-versa if necessary).
403  *
404  * parameters:
405  * f <-- cs_file_t descriptor
406  * buf <-> pointer to location containing data
407  * size <-- size of each item of data in bytes
408  * stride <-- number of (interlaced) values per block item
409  * global_num_start <-- global number of first block item (1 to n numbering)
410  * global_num_end <-- global number of past-the end block item
411  * (1 to n numbering)
412  *
413  * returns:
414  * the (local) number of items (not bytes) sucessfully written; currently,
415  * errors are fatal.
416  *----------------------------------------------------------------------------*/
417 
418 size_t
420  void *buf,
421  size_t size,
422  size_t stride,
423  cs_gnum_t global_num_start,
424  cs_gnum_t global_num_end);
425 
426 /*----------------------------------------------------------------------------
427  * Update the file pointer according to whence.
428  *
429  * parameters:
430  * f <-> cs_file_t descriptor.
431  * offset <-- add to position specified to whence to obtain new position,
432  * measured in characters from the beginning of the file.
433  * whence <-- beginning if CS_FILE_SEEK_SET, current if CS_FILE_SEEK_CUR,
434  * or end-of-file if CS_FILE_SEEK_END.
435  *
436  * returns:
437  * 0 upon success, nonzero otherwise; currently, errors are fatal.
438  *----------------------------------------------------------------------------*/
439 
440 int
442  cs_file_off_t offset,
443  cs_file_seek_t whence);
444 
445 /*----------------------------------------------------------------------------
446  * Return the position of the file pointer.
447  *
448  * In parallel, we consider the file pointer to be equal to the highest
449  * value of the individual file pointers.
450  *
451  * parameters:
452  * f <-- cs_file_t descriptor
453  *
454  * returns:
455  * current position of the file pointer
456  *----------------------------------------------------------------------------*/
457 
460 
461 /*----------------------------------------------------------------------------
462  * Dump the metadata of a file structure in human readable form
463  *
464  * parameters:
465  * f <-- pointer to file
466  *----------------------------------------------------------------------------*/
467 
468 void
469 cs_file_dump(const cs_file_t *f);
470 
471 /*----------------------------------------------------------------------------
472  * Free the default options for file access.
473  *----------------------------------------------------------------------------*/
474 
475 void
477 
478 /*----------------------------------------------------------------------------
479  * Get the default options for file access.
480  *
481  * parameters:
482  * mode <-- file mode for which the default is queried (write and
483  * append use the same method, and are interchangeable here)
484  * access --> default file access method, or NULL
485  * hints --> MPI-IO hints, or NULL
486  *----------------------------------------------------------------------------*/
487 
488 #if defined(HAVE_MPI)
489 
490 void
492  cs_file_access_t *method,
493  MPI_Info *hints);
494 
495 #else
496 
497 void
499  cs_file_access_t *method);
500 
501 #endif
502 
503 /*----------------------------------------------------------------------------
504  * Set the default options for file access.
505  *
506  * If the method given contains incompatible values, such as when setting
507  * MPI-IO methods when MPI-IO is not available, a "reasonable" default
508  * is used instead.
509  *
510  * parameters:
511  * mode <-- file mode for which the default is to be set (write and
512  * append use the same method, and are interchangeable here)
513  * method <-- default access method to set
514  * hints <-- MPI-IO hints, or MPI_INFO_NULL
515  *----------------------------------------------------------------------------*/
516 
517 #if defined(HAVE_MPI)
518 
519 void
521  cs_file_access_t method,
522  MPI_Info hints);
523 
524 #else
525 
526 void
528  cs_file_access_t method);
529 
530 #endif
531 
532 #if defined(HAVE_MPI)
533 
534 /*----------------------------------------------------------------------------
535  * Get default MPI communicator values for file access.
536  *
537  * A block rank stepping value may be used, allowing the use of a reduced
538  * communicator for distributed block reads and writes.
539  * If this value is greater than 1, ranks not a multiple of this step must be
540  * guaranteed to be empty for block reads and writes with files opened using
541  * this default.
542  *
543  * parameters:
544  * block_rank_step --> MPI rank stepping between non-empty distributed blocks,
545  * or NULL
546  * block_comm --> Handle to MPI communicator used for distributed
547  * file block access, or NULL
548  * comm --> Handle to main MPI communicator, or NULL
549  *----------------------------------------------------------------------------*/
550 
551 void
552 cs_file_get_default_comm(int *block_rank_step,
553  MPI_Comm *block_comm,
554  MPI_Comm *comm);
555 
556 /*----------------------------------------------------------------------------
557  * Set default MPI communicator values for file access.
558  *
559  * A block rank stepping value may be used, allowing the use of a reduced
560  * communicator for distributed block reads and writes.
561  * If this value is greater than 1, ranks not a multiple of this step must be
562  * guaranteed to be empty for block reads and writes with files opened using
563  * this default.
564  *
565  * For each argument, an "out of range" value may be used to avoid modifying
566  * the previous default for that argument.
567  *
568  * parameters:
569  * block_rank_step <-- MPI rank stepping between non-empty blocks for
570  * file block reads and writes (not set if <= 0)
571  * comm <-- handle to main MPI communicator
572  * (not set if MPI_COMM_SELF)
573  *----------------------------------------------------------------------------*/
574 
575 void
576 cs_file_set_default_comm(int block_rank_step,
577  MPI_Comm comm);
578 
579 /*----------------------------------------------------------------------------
580  * Create an MPI communicator for distributed block parallel IO.
581  *
582  * parameters:
583  * block_rank_step <-- MPI rank stepping between non-empty blocks
584  * comm <-- Handle to main MPI communicator
585  *
586  * returns:
587  * communicator associated with IO, MPI_COMM_NULL for ranks not
588  * participating in parallel IO (including ranks participating in IO
589  * where communicator size would be 1)
590  *----------------------------------------------------------------------------*/
591 
592 MPI_Comm
593 cs_file_block_comm(int block_rank_step,
594  MPI_Comm comm);
595 
596 #endif /* defined(HAVE_MPI) */
597 
598 /*----------------------------------------------------------------------------
599  * Get the positioning method for MPI-IO
600  *
601  * For details, see cs_file_set_mpi_io_positioning().
602  *
603  * returns:
604  * positioning method for MPI-IO
605  *----------------------------------------------------------------------------*/
606 
609 
610 /*----------------------------------------------------------------------------
611  * Set the positioning method for MPI-IO
612  *
613  * It is not always known whether a performance or robustness difference is
614  * to be expected using explicit file offsets or individual file pointers.
615  * Perusal of a sampling of ROMIO code would seem to indicate that no
616  * difference is to be expected, but this might change with MPI IO variants
617  * or file systems, so this advanced setting is made possible.
618  *
619  * This setting is not available on a per-file basis, though this could be
620  * done in the future in the unexpected case of performance results
621  * showing this would be useful.
622  *
623  * parameters:
624  * positioning <-- chosen positioning method for MPI-IO
625  *----------------------------------------------------------------------------*/
626 
627 void
629 
630 /*----------------------------------------------------------------------------
631  * Print information on default options for file access.
632  *----------------------------------------------------------------------------*/
633 
634 void
636 
637 #if defined(HAVE_MPI)
638 
639 /*----------------------------------------------------------------------------
640  * Create a cs_file_serializer_t structure.
641  *
642  * The buf_block_size argument is optional, and may be used when the buffer
643  * on rank 0 is larger than (global_num_end - global_num_start)*size*stride
644  * bytes. If zero, a block size of (global_num_end - global_num_start) on
645  * rank 0 is assumed; a buffer may not be smaller than this, as it must
646  * initially contain all data on rank 0's block.
647  *
648  * parameters:
649  * size <-- size of each item of data in bytes
650  * stride <-- number of (interlaced) values per block item
651  * global_num_start <-- global number of first block item (1 to n numbering)
652  * global_num_end <-- global number of past-the end block item
653  * (1 to n numbering)
654  * buf_block_size <-- Local data buffer block size, or 0 for default
655  * global_num_end - global_num_start
656  * (only useful on rank 0)
657  * buf <-- pointer to local block data buffer
658  * comm <-- associated MPI communicator
659  *
660  * returns:
661  * pointer to new serializer structure
662  *----------------------------------------------------------------------------*/
663 
665 cs_file_serializer_create(size_t size,
666  size_t stride,
667  cs_gnum_t global_num_start,
668  cs_gnum_t global_num_end,
669  size_t buf_block_size,
670  void *buf,
671  MPI_Comm comm);
672 
673 /*----------------------------------------------------------------------------
674  * Destroy a cs_file_serializer_t structure.
675  *
676  * parameters:
677  * s <-> pointer to pointer structure that should be destroyed
678  *----------------------------------------------------------------------------*/
679 
680 void
682 
683 /*----------------------------------------------------------------------------
684  * Advance a cs_file_serializer_t structure.
685  *
686  * Data from the buffer of the next communicating rank is copied
687  * to rank 0 (this is a no-op the first time this function is called,
688  * as rank 0 already has its data).
689  *
690  * On rank 0, the return value may point to the buffer defined when
691  * initializing the serializer, or to an aditional buffer if the former is
692  * too small to receive data from all ranks.
693  *
694  * Note also that for ranks > 0, this function always returns NULL,
695  * as only one call is needed for those ranks.
696  *
697  * parameters:
698  * s <-- pointer to serializer structure
699  * cur_range --> optional start and past-the end global numbers for the
700  * current block (size: 2), or NULL; only on rank 0
701  *
702  * returns:
703  * a pointer to the buffer containing new data (first call counts as new),
704  * or NULL if we are finished; always NULL on ranks > 0
705  *----------------------------------------------------------------------------*/
706 
707 void *
709  cs_gnum_t cur_range[2]);
710 
711 #endif /* defined(HAVE_MPI) */
712 
713 /*----------------------------------------------------------------------------
714  * Create a new directory using default permissions.
715  *
716  * This function is similar to the POSIX function mkdir(), except that
717  * it has no "mode" argument: by default, on a POSIX type system,
718  * permissions include read, write, and execute access for the user,
719  * group and others, modified by the users umask value (so with a
720  * typical configuration, the user will have read, write, and execute
721  * pemission, the group and others will only have read and execute
722  * permission, but this behavior may be modified).
723  *
724  * Also, contrary to the usual mkdir(), if the directory already
725  * exists (and is truly a directory), this is considered a success
726  * and not a failure, and 0 is returned: the aim of this function
727  * is to make a directory available, so if it already exists,
728  * this is considered acceptable.
729  *
730  * parameters:
731  * path: <-- name of new directory.
732  *
733  * returns:
734  * 0 on success, -1 if an error occured (in which case errno
735  * contains the appropriate error code). If the underlying
736  * system has no mkdir() function or it was not detected
737  * upon BFT configuration, 1 is returned.
738  *----------------------------------------------------------------------------*/
739 
740 int
741 cs_file_mkdir_default(const char *path);
742 
743 /*----------------------------------------------------------------------------
744  * Check if a file exists and is a regular file.
745  *
746  * parameters:
747  * path <-- file name.
748  *
749  * returns:
750  * 1 if file exists and is a regular file, 0 otherwise.
751  *----------------------------------------------------------------------------*/
752 
753 int
754 cs_file_isreg(const char *path);
755 
756 /*----------------------------------------------------------------------------
757  * Check if a directory exists.
758  *
759  * parameters:
760  * path <-- directory name.
761  *
762  * returns:
763  * 1 if directory exists, 0 otherwise.
764  *----------------------------------------------------------------------------*/
765 
766 int
767 cs_file_isdir(const char *path);
768 
769 /*----------------------------------------------------------------------------
770  * List files inside a directory.
771  *
772  * The array returned must be freed by the caller using BFT_FREE,
773  * as well as the individual entries in the array.
774  *
775  * parameters:
776  * path <-- name of directory.
777  *
778  * returns:
779  * an array of file names in a directory. The last entry is set to NULL.
780  * If no means to list the directory or an error occured, the return
781  * value is simply NULL.
782  *----------------------------------------------------------------------------*/
783 
784 char **
785 cs_file_listdir(const char *path);
786 
787 /*----------------------------------------------------------------------------
788  * Return the size of a file.
789  *
790  * If the file does not exist, 0 is returned.
791  *
792  * Note that for some special files, such as files in the Linux /proc
793  * directory, this may return 0.
794  *
795  * parameters
796  * path <-- file path.
797  *
798  * returns:
799  * size of file.
800  *----------------------------------------------------------------------------*/
801 
803 cs_file_size(const char *path);
804 
805 /*----------------------------------------------------------------------------
806  * Remove a file if it exists and is a regular file or an empty directory.
807  *
808  * parameters
809  * path <-- file path.
810  *
811  * returns:
812  * 0 in case of success or if file does not exist, not 0 otherwise.
813  *----------------------------------------------------------------------------*/
814 
815 int
816 cs_file_remove(const char *path);
817 
818 /*----------------------------------------------------------------------------
819  * Check if a file name ends with a specific string (extension)
820  *
821  * parameters
822  * path <-- file path.
823  * end <-- string to compare
824  *
825  * returns:
826  * 1 if the path ends with the given string, 0 otherwise.
827  *----------------------------------------------------------------------------*/
828 
829 int
830 cs_file_endswith(const char *path,
831  const char *end);
832 
833 /*----------------------------------------------------------------------------*/
834 
836 
837 #endif /* __CS_FILE_H__ */
void cs_file_get_default_access(cs_file_mode_t mode, cs_file_access_t *method, MPI_Info *hints)
Get the default options for file access.
Definition: cs_file.c:3323
size_t cs_file_write_block_buffer(cs_file_t *f, void *buf, size_t size, size_t stride, cs_gnum_t global_num_start, cs_gnum_t global_num_end)
Write data to a file, each associated process providing a contiguous part of this data...
Definition: cs_file.c:2950
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
Definition: cs_file.h:90
void cs_file_set_swap_endian(cs_file_t *f, int swap)
Set a file&#39;s byte-swapping behavior.
Definition: cs_file.c:2450
char ** cs_file_listdir(const char *path)
List files inside a directory.
Definition: cs_file.c:4160
struct _cs_file_serializer_t cs_file_serializer_t
Definition: cs_file.h:59
void cs_file_defaults_info(void)
Print information on default options for file access.
Definition: cs_file.c:3686
void cs_file_set_default_comm(int block_rank_step, MPI_Comm comm)
Set default MPI communicator values for file access.
Definition: cs_file.c:3530
cs_file_serializer_t * cs_file_serializer_create(size_t size, size_t stride, cs_gnum_t global_num_start, cs_gnum_t global_num_end, size_t buf_block_size, void *buf, MPI_Comm comm)
Create a cs_file_serializer_t structure.
Definition: cs_file.c:3795
void cs_file_serializer_destroy(cs_file_serializer_t **s)
Destroy a cs_file_serializer_t structure.
Definition: cs_file.c:3827
Definition: cs_file.h:86
void * cs_file_serializer_advance(cs_file_serializer_t *s, cs_gnum_t cur_range[2])
Advance a cs_file_serializer_t structure.
Definition: cs_file.c:3860
cs_file_seek_t
seek semantics (third argument of cs_file_seek)
Definition: cs_file.h:74
int cs_file_get_swap_endian(const cs_file_t *f)
Return a file&#39;s byte-swapping behavior.
Definition: cs_file.c:2433
void cs_file_free_defaults(void)
Free the default options for file access.
Definition: cs_file.c:3278
size_t cs_file_write_block(cs_file_t *f, const void *buf, size_t size, size_t stride, cs_gnum_t global_num_start, cs_gnum_t global_num_end)
Write data to a file, each associated process providing a contiguous part of this data...
Definition: cs_file.c:2839
size_t cs_file_read_block(cs_file_t *f, void *buf, size_t size, size_t stride, cs_gnum_t global_num_start, cs_gnum_t global_num_end)
Read data to a buffer, distributing a contiguous part of it to each process associated with a file...
Definition: cs_file.c:2702
cs_file_t * cs_file_open(const char *name, cs_file_mode_t mode, cs_file_access_t method, MPI_Info hints, MPI_Comm block_comm, MPI_Comm comm)
Create a file descriptor and open the associated file.
Definition: cs_file.c:2126
#define BEGIN_C_DECLS
Definition: cs_defs.h:495
int cs_file_isdir(const char *path)
Check if a directory exists.
Definition: cs_file.c:4113
Definition: cs_file.h:76
Definition: cs_file.h:88
cs_file_t * cs_file_free(cs_file_t *f)
Destroy a file descriptor and close the associated file.
Definition: cs_file.c:2352
void cs_file_dump(const cs_file_t *f)
Dump the metadata of a file structure in human readable form.
Definition: cs_file.c:3212
cs_file_mode_t
File acces modes.
Definition: cs_file.h:64
#define MPI_Info
Definition: cs_defs.h:93
MPI_Comm cs_file_block_comm(int block_rank_step, MPI_Comm comm)
Create an MPI communicator for distributed block parallel IO.
Definition: cs_file.c:3584
const char * cs_file_get_name(const cs_file_t *f)
Return a file&#39;s name.
Definition: cs_file.c:2382
const char * cs_file_access_name[]
Definition: cs_file.c:282
Definition: cs_file.h:91
long long cs_file_off_t
Definition: cs_file.h:107
int cs_file_mkdir_default(const char *path)
Create a new directory using default permissions.
Definition: cs_file.c:3992
cs_file_mpi_positioning_t
MPI-IO positioning methods.
Definition: cs_file.h:97
void cs_file_set_mpi_io_positioning(cs_file_mpi_positioning_t positioning)
Set the positioning method for MPI-IO.
Definition: cs_file.c:3674
Definition: cs_file.h:78
int cs_file_remove(const char *path)
Remove a file if it exists and is a regular file or an empty directory.
Definition: cs_file.c:4272
Definition: cs_file.h:68
Definition: cs_file.h:66
int cs_file_seek(cs_file_t *f, cs_file_off_t offset, cs_file_seek_t whence)
Update the file pointer according to whence.
Definition: cs_file.c:3082
int cs_file_endswith(const char *path, const char *end)
Check if file name/path ends with a specific string.
Definition: cs_file.c:4340
size_t cs_file_write_global(cs_file_t *f, const void *buf, size_t size, size_t ni)
Write global data to a file.
Definition: cs_file.c:2572
cs_file_off_t cs_file_size(const char *path)
Return the size of a file.
Definition: cs_file.c:4219
int cs_file_isreg(const char *path)
Check if a file exists and is a regular file.
Definition: cs_file.c:4067
cs_file_t * cs_file_open_serial(const char *name, cs_file_mode_t mode)
Create a file descriptor and open the associated file, using the serial IO on the root rank...
Definition: cs_file.c:2322
cs_file_access_t
Shared file access methods.
Definition: cs_file.h:84
size_t cs_file_read_global(cs_file_t *f, void *buf, size_t size, size_t ni)
Read global data from a file, distributing it to all processes associated with that file...
Definition: cs_file.c:2474
cs_file_off_t cs_file_tell(cs_file_t *f)
Return the position of the file pointer.
Definition: cs_file.c:3171
Definition: cs_file.h:100
#define END_C_DECLS
Definition: cs_defs.h:496
Definition: cs_file.h:87
struct _cs_file_t cs_file_t
Definition: cs_file.h:54
Definition: cs_file.h:67
void cs_file_get_default_comm(int *block_rank_step, MPI_Comm *block_comm, MPI_Comm *comm)
Get default MPI communicator values for file access.
Definition: cs_file.c:3478
Definition: cs_file.h:99
const char * cs_file_mpi_positioning_name[]
Definition: cs_file.c:292
Definition: cs_file.h:89
cs_file_mpi_positioning_t cs_file_get_mpi_io_positioning(void)
Get the positioning method for MPI-IO.
Definition: cs_file.c:3650
Definition: cs_file.h:77
cs_file_t * cs_file_open_default(const char *name, cs_file_mode_t mode)
Create a file descriptor and open the associated file, using the default file communicator and access...
Definition: cs_file.c:2268
void cs_file_set_default_access(cs_file_mode_t mode, cs_file_access_t method, MPI_Info hints)
Set the default options for file access.
Definition: cs_file.c:3389
void cs_file_set_big_endian(cs_file_t *f)
Ensure that data is read or written in big-endian (network standard) format.
Definition: cs_file.c:2399