9.2
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-2026 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 "base/cs_defs.h"
39
40/*=============================================================================
41 * Macro definitions
42 *============================================================================*/
43
44/*============================================================================
45 * Type definitions
46 *============================================================================*/
47
48/* File descriptor */
49
50typedef struct _cs_file_t cs_file_t;
51
52/* Helper structure for IO serialization */
53
54#if defined(HAVE_MPI)
55typedef struct _cs_file_serializer_t cs_file_serializer_t;
56#endif
57
58/* File modes */
59
61typedef enum {
62
68
69/* Possibilities for the third argument of cs_file_seek() */
70
72typedef enum {
73
79
80/* File access methods */
81
83typedef enum {
84
98
99/* MPI-IO file positioning methods */
100
109typedef enum {
110
117
118/* Offset for file position indicator (int64_t in C99) */
119
120#if defined(SIZEOF_LONG_LONG)
121typedef long long cs_file_off_t;
122#else
123typedef long cs_file_off_t;
124#endif
125
126/*=============================================================================
127 * Global variables
128 *============================================================================*/
129
130/* names associated with file access methods */
131
132extern const char *cs_file_access_name[];
133
134/* names associated with MPI-IO positioning */
135
136extern const char *cs_file_mpi_positioning_name[];
137
138/*=============================================================================
139 * Public function prototypes
140 *============================================================================*/
141
142/*----------------------------------------------------------------------------
143 * Create a file descriptor and open the associated file.
144 *
145 * By default, data is written or read as native data. This behavior may be
146 * modified by cs_file_set_swap_endian().
147 *
148 * parameters:
149 * name <-- file name
150 * mode <-- file access mode: read, write, or append
151 * method <-- file access method
152 * hints <-- associated hints for MPI-IO, or MPI_INFO_NULL
153 * block_comm <-- handle to MPI communicator used for distributed file
154 * block access (may be a subset of comm if some ranks do
155 * not directly access distributed data blocks)
156 * comm <-- handle to main MPI communicator
157 *
158 * returns:
159 * pointer to cs_file_t file descriptor (NULL in case of failure);
160 * currently, errors are fatal.
161 *----------------------------------------------------------------------------*/
162
163#if defined(HAVE_MPI)
164
165cs_file_t *
166cs_file_open(const char *name,
167 cs_file_mode_t mode,
168 cs_file_access_t method,
169 MPI_Info hints,
170 MPI_Comm block_comm,
171 MPI_Comm comm);
172
173#else
174
175cs_file_t *
176cs_file_open(const char *name,
177 cs_file_mode_t mode,
178 cs_file_access_t method);
179
180#endif
181
182/*----------------------------------------------------------------------------
183 * Create a file descriptor and open the associated file, using the default
184 * file communicator and access method.
185 *
186 * By default, data is written or read as native data. This behavior may be
187 * modified by cs_file_set_swap_endian().
188 *
189 * parameters:
190 * name <-- file name
191 * mode <-- file access mode: read, write, or append
192 *
193 * returns:
194 * pointer to cs_file_t file descriptor (NULL in case of failure);
195 * currently, errors are fatal.
196 *----------------------------------------------------------------------------*/
197
198cs_file_t *
199cs_file_open_default(const char *name,
200 cs_file_mode_t mode);
201
202/*----------------------------------------------------------------------------*/
216/*----------------------------------------------------------------------------*/
217
218cs_file_t *
219cs_file_open_serial(const char *name,
220 cs_file_mode_t mode);
221
222/*----------------------------------------------------------------------------
223 * Destroy a file descriptor and close the associated file.
224 *
225 * parameters:
226 * f <-> file descriptor to destroy
227 *
228 * returns:
229 * null pointer
230 *----------------------------------------------------------------------------*/
231
232cs_file_t *
234
235/*----------------------------------------------------------------------------*/
236/*
237 * \brief Transfer a block of data to file in memory.
238 *
239 * Only for files opened using CS_FILE_IN_MEMORY_SERIAL.
240 *
241 * \param[in] f cs_file_t descriptor
242 * \param[in] nb number of matching bytes for data
243 * \param[in] data data buffer (ownership is relinquished by caller)
244 */
245/*----------------------------------------------------------------------------*/
246
247void
249 size_t nb,
250 void *data);
251
252/*----------------------------------------------------------------------------
253 * Return a file's name.
254 *
255 * parameters:
256 * f <-- cs_file_t descriptor
257 *
258 * returns:
259 * pointer to the file's name.
260 *----------------------------------------------------------------------------*/
261
262const char *
264
265/*----------------------------------------------------------------------------
266 * Get pointer to data for file in memory.
267 *
268 * parameters:
269 * f <-- cs_file_t descriptor
270 *
271 * return:
272 * pointer to file data.
273 *----------------------------------------------------------------------------*/
274
275void *
277
278/*----------------------------------------------------------------------------
279 * Allow global read attemps past end of file without throwing an error.
280 *
281 * Currently only for files with serial access.
282 *
283 * parameters:
284 * f <-> cs_file_t descriptor
285 * allow_eof <-- allow read attempt pas EOF
286 *----------------------------------------------------------------------------*/
287
288void
290 bool allow_eof);
291
292/*----------------------------------------------------------------------------
293 * Ensure that data is read or written in big-endian
294 * (network standard) format.
295 *
296 * parameters:
297 * f <-> cs_file_t descriptor
298 *----------------------------------------------------------------------------*/
299
300void
302
303/*----------------------------------------------------------------------------
304 * Return a file's byte-swapping behavior.
305 *
306 * parameters:
307 * f <-- cs_file_t descriptor
308 *
309 * returns:
310 * 0 if file's endianness is the same as the system's, 1 otherwise.
311 *----------------------------------------------------------------------------*/
312
313int
315
316/*----------------------------------------------------------------------------
317 * Set a file's byte-swapping behavior.
318 *
319 * Using this function assumes one is familiar with a file's coding
320 * or structure; use with caution.
321 *
322 * parameters:
323 * f <-> cs_file_t descriptor
324 * swap <-- 1 if bytes must be swapped, 0 otherwise
325 *----------------------------------------------------------------------------*/
326
327void
329 int swap);
330
331/*----------------------------------------------------------------------------
332 * Read global data from a file, distributing it to all processes
333 * associated with that file.
334 *
335 * parameters:
336 * f <-- cs_file_t descriptor
337 * buf --> pointer to location receiving data
338 * size <-- size of each item of data in bytes
339 * ni <-- number of items to read
340 *
341 * returns:
342 * the number of items (not bytes) sucessfully read; currently,
343 * errors are fatal.
344 *----------------------------------------------------------------------------*/
345
346size_t
348 void *buf,
349 size_t size,
350 size_t ni);
351
352/*----------------------------------------------------------------------------
353 * Write global data to a file.
354 *
355 * Under MPI, data is only written by the associated communicator's root
356 * rank. The buffers on other ranks are ignored, though the file offset
357 * is updated (i.e. the call to this function is collective).
358 *
359 * parameters:
360 * f <-- cs_file_t descriptor
361 * buf <-- pointer to location containing data
362 * size <-- size of each item of data in bytes
363 * ni <-- number of items to read
364 *
365 * returns:
366 * the number of items (not bytes) sucessfully written; currently,
367 * errors are fatal.
368 *----------------------------------------------------------------------------*/
369
370size_t
372 const void *buf,
373 size_t size,
374 size_t ni);
375
376/*----------------------------------------------------------------------------
377 * Read data to a buffer, distributing a contiguous part of it to each
378 * process associated with a file.
379 *
380 * Each process should receive a (possibly empty) block of the data,
381 * and we should have:
382 * global_num_start at rank 0 = 1
383 * global_num_start at rank i+1 = global_num_end at rank i.
384 * Otherwise, behavior (especially positioning for future reads) is undefined.
385 *
386 * parameters:
387 * f <-- cs_file_t descriptor
388 * buf --> pointer to location receiving data
389 * size <-- size of each item of data in bytes
390 * stride <-- number of (interlaced) values per block item
391 * global_num_start <-- global number of first block item (1 to n numbering)
392 * global_num_end <-- global number of past-the end block item
393 * (1 to n numbering)
394 *
395 * returns:
396 * the (local) number of items (not bytes) sucessfully read; currently,
397 * errors are fatal.
398 *----------------------------------------------------------------------------*/
399
400size_t
402 void *buf,
403 size_t size,
404 size_t stride,
405 cs_gnum_t global_num_start,
406 cs_gnum_t global_num_end);
407
408/*----------------------------------------------------------------------------
409 * Write data to a file, each associated process providing a contiguous part
410 * of this data.
411 *
412 * Each process should provide a (possibly empty) block of the data,
413 * and we should have:
414 * global_num_start at rank 0 = 1
415 * global_num_start at rank i+1 = global_num_end at rank i.
416 * Otherwise, behavior (especially positioning for future reads) is undefined.
417 *
418 * This function may require an internal copy of the data to ensure that
419 * the buffer contents are not modified, so if the buffer contents are
420 * temporary values, to be deleted after writing, using
421 * cs_file_write_block_buffer() instead may be used to avoid an unneeded
422 * memory allocation and copy.
423 *
424 * parameters:
425 * f <-- cs_file_t descriptor
426 * buf <-- pointer to location containing data
427 * size <-- size of each item of data in bytes
428 * stride <-- number of (interlaced) values per block item
429 * global_num_start <-- global number of first block item (1 to n numbering)
430 * global_num_end <-- global number of past-the end block item
431 * (1 to n numbering)
432 *
433 * returns:
434 * the (local) number of items (not bytes) sucessfully written; currently,
435 * errors are fatal.
436 *----------------------------------------------------------------------------*/
437
438size_t
440 const void *buf,
441 size_t size,
442 size_t stride,
443 cs_gnum_t global_num_start,
444 cs_gnum_t global_num_end);
445
446/*----------------------------------------------------------------------------
447 * Write data to a file, each associated process providing a contiguous part
448 * of this data.
449 *
450 * Each process should provide a (possibly empty) block of the data,
451 * and we should have:
452 * global_num_start at rank 0 = 1
453 * global_num_start at rank i+1 = global_num_end at rank i.
454 * Otherwise, behavior (especially positioning for future reads) is undefined.
455 *
456 * This function is intended to be used mainly data that is already a
457 * copy of original data (such as data that has been redistributed across
458 * processors just for the sake of output), or that is to be deleted after
459 * writing, so it may modify the values in its input buffer (notably to
460 * convert from little-endian to big-endian of vice-versa if necessary).
461 *
462 * parameters:
463 * f <-- cs_file_t descriptor
464 * buf <-> pointer to location containing data
465 * size <-- size of each item of data in bytes
466 * stride <-- number of (interlaced) values per block item
467 * global_num_start <-- global number of first block item (1 to n numbering)
468 * global_num_end <-- global number of past-the end block item
469 * (1 to n numbering)
470 *
471 * returns:
472 * the (local) number of items (not bytes) sucessfully written; currently,
473 * errors are fatal.
474 *----------------------------------------------------------------------------*/
475
476size_t
478 void *buf,
479 size_t size,
480 size_t stride,
481 cs_gnum_t global_num_start,
482 cs_gnum_t global_num_end);
483
484/*----------------------------------------------------------------------------
485 * Update the file pointer according to whence.
486 *
487 * parameters:
488 * f <-> cs_file_t descriptor.
489 * offset <-- add to position specified to whence to obtain new position,
490 * measured in characters from the beginning of the file.
491 * whence <-- beginning if CS_FILE_SEEK_SET, current if CS_FILE_SEEK_CUR,
492 * or end-of-file if CS_FILE_SEEK_END.
493 *
494 * returns:
495 * 0 upon success, nonzero otherwise; currently, errors are fatal.
496 *----------------------------------------------------------------------------*/
497
498int
500 cs_file_off_t offset,
501 cs_file_seek_t whence);
502
503/*----------------------------------------------------------------------------
504 * Return the position of the file pointer.
505 *
506 * In parallel, we consider the file pointer to be equal to the highest
507 * value of the individual file pointers.
508 *
509 * parameters:
510 * f <-- cs_file_t descriptor
511 *
512 * returns:
513 * current position of the file pointer
514 *----------------------------------------------------------------------------*/
515
518
519/*----------------------------------------------------------------------------*/
531/*----------------------------------------------------------------------------*/
532
533char *
534cs_file_gets(char *s,
535 const int size,
536 const cs_file_t *f,
537 int *line);
538
539/*----------------------------------------------------------------------------*/
556/*----------------------------------------------------------------------------*/
557
558char *
559cs_file_gets_try(char *s,
560 const int size,
561 const cs_file_t *f,
562 int *line);
563
564/*----------------------------------------------------------------------------
565 * Dump the metadata of a file structure in human readable form
566 *
567 * parameters:
568 * f <-- pointer to file
569 *----------------------------------------------------------------------------*/
570
571void
572cs_file_dump(const cs_file_t *f);
573
574/*----------------------------------------------------------------------------
575 * Free the default options for file access.
576 *----------------------------------------------------------------------------*/
577
578void
580
581/*----------------------------------------------------------------------------
582 * Get the default options for file access.
583 *
584 * parameters:
585 * mode <-- file mode for which the default is queried (write and
586 * append use the same method, and are interchangeable here)
587 * access --> default file access method, or null
588 * hints --> MPI-IO hints, or null
589 *----------------------------------------------------------------------------*/
590
591#if defined(HAVE_MPI)
592
593void
595 cs_file_access_t *method,
596 MPI_Info *hints);
597
598#else
599
600void
602 cs_file_access_t *method);
603
604#endif
605
606/*----------------------------------------------------------------------------
607 * Set the default options for file access.
608 *
609 * If the method given contains incompatible values, such as when setting
610 * MPI-IO methods when MPI-IO is not available, a "reasonable" default
611 * is used instead.
612 *
613 * parameters:
614 * mode <-- file mode for which the default is to be set (write and
615 * append use the same method, and are interchangeable here)
616 * method <-- default access method to set
617 * hints <-- MPI-IO hints, or MPI_INFO_NULL
618 *----------------------------------------------------------------------------*/
619
620#if defined(HAVE_MPI)
621
622void
624 cs_file_access_t method,
625 MPI_Info hints);
626
627#else
628
629void
631 cs_file_access_t method);
632
633#endif
634
635#if defined(HAVE_MPI)
636
637/*----------------------------------------------------------------------------
638 * Get default MPI communicator values for file access.
639 *
640 * A block rank stepping value may be used, allowing the use of a reduced
641 * communicator for distributed block reads and writes.
642 * If this value is greater than 1, ranks not a multiple of this step must be
643 * guaranteed to be empty for block reads and writes with files opened using
644 * this default.
645 *
646 * parameters:
647 * block_rank_step --> MPI rank stepping between non-empty distributed blocks,
648 * or null
649 * block_comm --> Handle to MPI communicator used for distributed
650 * file block access, or null
651 * comm --> Handle to main MPI communicator, or null
652 *----------------------------------------------------------------------------*/
653
654void
655cs_file_get_default_comm(int *block_rank_step,
656 MPI_Comm *block_comm,
657 MPI_Comm *comm);
658
659/*----------------------------------------------------------------------------
660 * Set default MPI communicator values for file access.
661 *
662 * A block rank stepping value may be used, allowing the use of a reduced
663 * communicator for distributed block reads and writes.
664 * If this value is greater than 1, ranks not a multiple of this step must be
665 * guaranteed to be empty for block reads and writes with files opened using
666 * this default.
667 *
668 * For each argument, an "out of range" value may be used to avoid modifying
669 * the previous default for that argument.
670 *
671 * parameters:
672 * block_rank_step <-- MPI rank stepping between non-empty blocks for
673 * file block reads and writes (not set if <= 0)
674 * comm <-- handle to main MPI communicator
675 * (not set if MPI_COMM_SELF)
676 *----------------------------------------------------------------------------*/
677
678void
679cs_file_set_default_comm(int block_rank_step,
680 MPI_Comm comm);
681
682/*----------------------------------------------------------------------------
683 * Create an MPI communicator for distributed block parallel IO.
684 *
685 * parameters:
686 * block_rank_step <-- MPI rank stepping between non-empty blocks
687 * comm <-- Handle to main MPI communicator
688 *
689 * returns:
690 * communicator associated with IO, MPI_COMM_NULL for ranks not
691 * participating in parallel IO (including ranks participating in IO
692 * where communicator size would be 1)
693 *----------------------------------------------------------------------------*/
694
695MPI_Comm
696cs_file_block_comm(int block_rank_step,
697 MPI_Comm comm);
698
699#endif /* defined(HAVE_MPI) */
700
701/*----------------------------------------------------------------------------
702 * Get the positioning method for MPI-IO
703 *
704 * For details, see cs_file_set_mpi_io_positioning().
705 *
706 * returns:
707 * positioning method for MPI-IO
708 *----------------------------------------------------------------------------*/
709
712
713/*----------------------------------------------------------------------------
714 * Set the positioning method for MPI-IO
715 *
716 * It is not always known whether a performance or robustness difference is
717 * to be expected using explicit file offsets or individual file pointers.
718 * Perusal of a sampling of ROMIO code would seem to indicate that no
719 * difference is to be expected, but this might change with MPI IO variants
720 * or file systems, so this advanced setting is made possible.
721 *
722 * This setting is not available on a per-file basis, though this could be
723 * done in the future in the unexpected case of performance results
724 * showing this would be useful.
725 *
726 * parameters:
727 * positioning <-- chosen positioning method for MPI-IO
728 *----------------------------------------------------------------------------*/
729
730void
732
733/*----------------------------------------------------------------------------
734 * Print information on default options for file access.
735 *----------------------------------------------------------------------------*/
736
737void
739
740#if defined(HAVE_MPI)
741
742/*----------------------------------------------------------------------------
743 * Create a cs_file_serializer_t structure.
744 *
745 * The buf_block_size argument is optional, and may be used when the buffer
746 * on rank 0 is larger than (global_num_end - global_num_start)*size*stride
747 * bytes. If zero, a block size of (global_num_end - global_num_start) on
748 * rank 0 is assumed; a buffer may not be smaller than this, as it must
749 * initially contain all data on rank 0's block.
750 *
751 * parameters:
752 * size <-- size of each item of data in bytes
753 * stride <-- number of (interlaced) values per block item
754 * global_num_start <-- global number of first block item (1 to n numbering)
755 * global_num_end <-- global number of past-the end block item
756 * (1 to n numbering)
757 * buf_block_size <-- Local data buffer block size, or 0 for default
758 * global_num_end - global_num_start
759 * (only useful on rank 0)
760 * buf <-- pointer to local block data buffer
761 * comm <-- associated MPI communicator
762 *
763 * returns:
764 * pointer to new serializer structure
765 *----------------------------------------------------------------------------*/
766
768cs_file_serializer_create(size_t size,
769 size_t stride,
770 cs_gnum_t global_num_start,
771 cs_gnum_t global_num_end,
772 size_t buf_block_size,
773 void *buf,
774 MPI_Comm comm);
775
776/*----------------------------------------------------------------------------
777 * Destroy a cs_file_serializer_t structure.
778 *
779 * parameters:
780 * s <-> pointer to pointer structure that should be destroyed
781 *----------------------------------------------------------------------------*/
782
783void
785
786/*----------------------------------------------------------------------------
787 * Advance a cs_file_serializer_t structure.
788 *
789 * Data from the buffer of the next communicating rank is copied
790 * to rank 0 (this is a no-op the first time this function is called,
791 * as rank 0 already has its data).
792 *
793 * On rank 0, the return value may point to the buffer defined when
794 * initializing the serializer, or to an aditional buffer if the former is
795 * too small to receive data from all ranks.
796 *
797 * Note also that for ranks > 0, this function always returns null,
798 * as only one call is needed for those ranks.
799 *
800 * parameters:
801 * s <-- pointer to serializer structure
802 * cur_range --> optional start and past-the end global numbers for the
803 * current block (size: 2), or null; only on rank 0
804 *
805 * returns:
806 * a pointer to the buffer containing new data (first call counts as new),
807 * or null if we are finished; always null on ranks > 0
808 *----------------------------------------------------------------------------*/
809
810void *
812 cs_gnum_t cur_range[2]);
813
814#endif /* defined(HAVE_MPI) */
815
816/*----------------------------------------------------------------------------
817 * Create a new directory using default permissions.
818 *
819 * This function is similar to the POSIX function mkdir(), except that
820 * it has no "mode" argument: by default, on a POSIX type system,
821 * permissions include read, write, and execute access for the user,
822 * group and others, modified by the users umask value (so with a
823 * typical configuration, the user will have read, write, and execute
824 * pemission, the group and others will only have read and execute
825 * permission, but this behavior may be modified).
826 *
827 * Also, contrary to the usual mkdir(), if the directory already
828 * exists (and is truly a directory), this is considered a success
829 * and not a failure, and 0 is returned: the aim of this function
830 * is to make a directory available, so if it already exists,
831 * this is considered acceptable.
832 *
833 * parameters:
834 * path: <-- name of new directory.
835 *
836 * returns:
837 * 0 on success, -1 if an error occured (in which case errno
838 * contains the appropriate error code). If the underlying
839 * system has no mkdir() function or it was not detected
840 * upon BFT configuration, 1 is returned.
841 *----------------------------------------------------------------------------*/
842
843int
844cs_file_mkdir_default(const char *path);
845
846/*----------------------------------------------------------------------------
847 * Check if a file exists and is a regular file.
848 *
849 * parameters:
850 * path <-- file name.
851 *
852 * returns:
853 * 1 if file exists and is a regular file, 0 otherwise.
854 *----------------------------------------------------------------------------*/
855
856int
857cs_file_isreg(const char *path);
858
859/*----------------------------------------------------------------------------
860 * Check if a directory exists.
861 *
862 * parameters:
863 * path <-- directory name.
864 *
865 * returns:
866 * 1 if directory exists, 0 otherwise.
867 *----------------------------------------------------------------------------*/
868
869int
870cs_file_isdir(const char *path);
871
872/*----------------------------------------------------------------------------
873 * List files inside a directory.
874 *
875 * The array returned must be freed by the caller using CS_FREE,
876 * as well as the individual entries in the array.
877 *
878 * parameters:
879 * path <-- name of directory.
880 *
881 * returns:
882 * an array of file names in a directory. The last entry is set to null.
883 * If no means to list the directory or an error occured, the return
884 * value is simply null.
885 *----------------------------------------------------------------------------*/
886
887char **
888cs_file_listdir(const char *path);
889
890/*----------------------------------------------------------------------------
891 * Return the size of a file.
892 *
893 * If the file does not exist, 0 is returned.
894 *
895 * Note that for some special files, such as files in the Linux /proc
896 * directory, this may return 0.
897 *
898 * parameters
899 * path <-- file path.
900 *
901 * returns:
902 * size of file.
903 *----------------------------------------------------------------------------*/
904
906cs_file_size(const char *path);
907
908/*----------------------------------------------------------------------------
909 * Remove a file if it exists and is a regular file or an empty directory.
910 *
911 * parameters
912 * path <-- file path.
913 *
914 * returns:
915 * 0 in case of success or if file does not exist, not 0 otherwise.
916 *----------------------------------------------------------------------------*/
917
918int
919cs_file_remove(const char *path);
920
921/*----------------------------------------------------------------------------
922 * Check if a file name ends with a specific string (extension)
923 *
924 * parameters
925 * path <-- file path.
926 * end <-- string to compare
927 *
928 * returns:
929 * 1 if the path ends with the given string, 0 otherwise.
930 *----------------------------------------------------------------------------*/
931
932int
933cs_file_endswith(const char *path,
934 const char *end);
935
936/*----------------------------------------------------------------------------*/
937
938#endif /* CS_FILE_H */
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:317
#define MPI_Info
Definition: cs_defs.h:86
void cs_file_dump(const cs_file_t *f)
Dump the metadata of a file structure in human readable form.
Definition: cs_file.cpp:3715
cs_file_off_t cs_file_tell(cs_file_t *f)
Return the position of the file pointer.
Definition: cs_file.cpp:3621
int cs_file_get_swap_endian(const cs_file_t *f)
Return a file's byte-swapping behavior.
Definition: cs_file.cpp:2873
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.cpp:3827
const char * cs_file_mpi_positioning_name[]
void cs_file_serializer_destroy(cs_file_serializer_t **s)
Destroy a cs_file_serializer_t structure.
Definition: cs_file.cpp:4329
void cs_file_set_default_comm(int block_rank_step, MPI_Comm comm)
Set default MPI communicator values for file access.
Definition: cs_file.cpp:4034
const char * cs_file_get_name(const cs_file_t *f)
Return a file's name.
Definition: cs_file.cpp:2822
struct _cs_file_serializer_t cs_file_serializer_t
Definition: cs_file.h:55
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.cpp:2490
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.cpp:4297
int cs_file_isdir(const char *path)
Check if a directory exists.
Definition: cs_file.cpp:4615
void * cs_file_in_memory_get_data(cs_file_t *f)
Get pointer to data for file in memory.
Definition: cs_file.cpp:2761
long cs_file_off_t
Definition: cs_file.h:123
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.cpp:3982
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.cpp:3015
cs_file_t * cs_file_free(cs_file_t *f)
Destroy a file descriptor and close the associated file.
Definition: cs_file.cpp:2728
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.cpp:2644
char * cs_file_gets_try(char *s, const int size, const cs_file_t *f, int *line)
Formatted input from a text file if possible (as fgets()).
Definition: cs_file.cpp:3698
cs_file_access_t
Definition: cs_file.h:83
@ CS_FILE_MPI_INDEPENDENT
Definition: cs_file.h:89
@ CS_FILE_STDIO_SERIAL
Definition: cs_file.h:86
@ CS_FILE_IN_MEMORY_SERIAL
Definition: cs_file.h:94
@ CS_FILE_MPI_COLLECTIVE
Definition: cs_file.h:93
@ CS_FILE_MPI_NON_COLLECTIVE
Definition: cs_file.h:91
@ CS_FILE_STDIO_PARALLEL
Definition: cs_file.h:88
@ CS_FILE_DEFAULT
Definition: cs_file.h:85
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.cpp:3150
void cs_file_free_defaults(void)
Free the default options for file access.
Definition: cs_file.cpp:3782
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.cpp:2839
struct _cs_file_t cs_file_t
Definition: cs_file.h:50
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.cpp:3399
cs_file_off_t cs_file_size(const char *path)
Return the size of a file.
Definition: cs_file.cpp:4721
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.cpp:4774
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.cpp:3532
int cs_file_endswith(const char *path, const char *end)
Check if file name/path ends with a specific string.
Definition: cs_file.cpp:4842
int cs_file_isreg(const char *path)
Check if a file exists and is a regular file.
Definition: cs_file.cpp:4569
void cs_file_in_memory_transfer_data(cs_file_t *f, size_t nb, void *data)
Transfer a block of data to file in memory.
Definition: cs_file.cpp:2798
void cs_file_set_mpi_io_positioning(cs_file_mpi_positioning_t positioning)
Set the positioning method for MPI-IO.
Definition: cs_file.cpp:4178
void cs_file_defaults_info(void)
Print information on default options for file access.
Definition: cs_file.cpp:4190
cs_file_mode_t
Definition: cs_file.h:61
@ CS_FILE_MODE_APPEND
Definition: cs_file.h:65
@ CS_FILE_MODE_WRITE
Definition: cs_file.h:64
@ CS_FILE_MODE_READ
Definition: cs_file.h:63
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.cpp:2914
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.cpp:4088
char ** cs_file_listdir(const char *path)
List files inside a directory.
Definition: cs_file.cpp:4662
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.cpp:3893
char * cs_file_gets(char *s, const int size, const cs_file_t *f, int *line)
Formatted input from a text file (as fgets()).
Definition: cs_file.cpp:3670
int cs_file_mkdir_default(const char *path)
Create a new directory using default permissions.
Definition: cs_file.cpp:4494
cs_file_seek_t
Definition: cs_file.h:72
@ CS_FILE_SEEK_CUR
Definition: cs_file.h:75
@ CS_FILE_SEEK_END
Definition: cs_file.h:76
@ CS_FILE_SEEK_SET
Definition: cs_file.h:74
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.cpp:2698
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.cpp:3288
const char * cs_file_access_name[]
Definition: cs_file.cpp:277
cs_file_mpi_positioning_t cs_file_get_mpi_io_positioning(void)
Get the positioning method for MPI-IO.
Definition: cs_file.cpp:4154
void cs_file_set_allow_read_global_eof(cs_file_t *f, bool allow_eof)
Definition: cs_file.cpp:2779
cs_file_mpi_positioning_t
Definition: cs_file.h:109
@ CS_FILE_MPI_INDIVIDUAL_POINTERS
Definition: cs_file.h:113
@ CS_FILE_MPI_EXPLICIT_OFFSETS
Definition: cs_file.h:111
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.cpp:4362
void cs_file_set_swap_endian(cs_file_t *f, int swap)
Set a file's byte-swapping behavior.
Definition: cs_file.cpp:2890