My Project
programmer's documentation
Loading...
Searching...
No Matches
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-2019 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
54typedef struct _cs_file_t cs_file_t;
55
56/* Helper structure for IO serialization */
57
58#if defined(HAVE_MPI)
59typedef struct _cs_file_serializer_t cs_file_serializer_t;
60#endif
61
62/* File modes */
63
64typedef 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
74typedef 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
94
95/* MPI-IO file positionning methods */
96
103
104/* Offset for file position indicator (int64_t in C99) */
105
106#if defined(SIZEOF_LONG_LONG)
107typedef long long cs_file_off_t;
108#else
109typedef long cs_file_off_t;
110#endif
111
112/*=============================================================================
113 * Global variables
114 *============================================================================*/
115
116/* names associated with file access methods */
117
118extern const char *cs_file_access_name[];
119
120/* names associated with MPI-IO positionning */
121
122extern const char *cs_file_mpi_positionning_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 acces 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
151cs_file_t *
152cs_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
161cs_file_t *
162cs_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 acces 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
184cs_file_t *
185cs_file_open_default(const char *name,
186 cs_file_mode_t mode);
187
188/*----------------------------------------------------------------------------*/
202/*----------------------------------------------------------------------------*/
203
204cs_file_t *
205cs_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
218cs_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
231const char *
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
242void
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
255int
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
269void
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
288size_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
312size_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
342size_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
380size_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
418size_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
440int
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
468void
469cs_file_dump(const cs_file_t *f);
470
471/*----------------------------------------------------------------------------
472 * Free the default options for file access.
473 *----------------------------------------------------------------------------*/
474
475void
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
490void
492 cs_file_access_t *method,
493 MPI_Info *hints);
494
495#else
496
497void
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
519void
521 cs_file_access_t method,
522 MPI_Info hints);
523
524#else
525
526void
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 * A minimum block size target may also be used, so as to limit the number
544 * of active blocks to a value proportional to the data size (limiting
545 * latency issues for small data sets, while not requiring too much local
546 * memory).
547 *
548 * parameters:
549 * block_rank_step --> MPI rank stepping between non-empty distributed blocks,
550 * or NULL
551 * block_min_size --> minimum block size target for non-empty distributed
552 * blocks, or NULL
553 * block_comm --> Handle to MPI communicator used for distributed
554 * file block access, or NULL
555 * comm --> Handle to main MPI communicator, or NULL
556 *----------------------------------------------------------------------------*/
557
558void
559cs_file_get_default_comm(int *block_rank_step,
560 int *block_min_size,
561 MPI_Comm *block_comm,
562 MPI_Comm *comm);
563
564/*----------------------------------------------------------------------------
565 * Set default MPI communicator values for file access.
566 *
567 * A block rank stepping value may be used, allowing the use of a reduced
568 * communicator for distributed block reads and writes.
569 * If this value is greater than 1, ranks not a multiple of this step must be
570 * guaranteed to be empty for block reads and writes with files opened using
571 * this default.
572 *
573 * A minimum block size target may also be used, so as to limit the number
574 * of active blocks to a value proportional to the data size (limiting
575 * latency issues for small data sets, while not requiring too much local
576 * memory).
577 *
578 * For each argument, an "out of range" value may be used to avoid modifying
579 * the previous default for that argument.
580 *
581 * parameters:
582 * block_rank_step <-- MPI rank stepping between non-empty blocks for
583 * file block reads and writes (not set if <= 0)
584 * block_min_size <-- minimum block size target for non-empty distributed
585 * blocks (not set if < 1)
586 * comm <-- handle to main MPI communicator
587 * (not set if MPI_COMM_SELF)
588 *----------------------------------------------------------------------------*/
589
590void
591cs_file_set_default_comm(int block_rank_step,
592 int block_min_size,
593 MPI_Comm comm);
594
595/*----------------------------------------------------------------------------
596 * Create an MPI communicator for distributed block parallel IO.
597 *
598 * parameters:
599 * block_rank_step <-- MPI rank stepping between non-empty blocks
600 * comm <-- Handle to main MPI communicator
601 *
602 * returns:
603 * communicator associated with IO, MPI_COMM_NULL for ranks not
604 * participating in parallel IO (including ranks participating in IO
605 * where communicator size would be 1)
606 *----------------------------------------------------------------------------*/
607
608MPI_Comm
609cs_file_block_comm(int block_rank_step,
610 MPI_Comm comm);
611
612#endif /* defined(HAVE_MPI) */
613
614/*----------------------------------------------------------------------------
615 * Get the positionning method for MPI-IO
616 *
617 * For details, see cs_file_set_mpi_io_positionning().
618 *
619 * returns:
620 * positionning method for MPI-IO
621 *----------------------------------------------------------------------------*/
622
625
626/*----------------------------------------------------------------------------
627 * Set the positionning method for MPI-IO
628 *
629 * It is not always known whether a performance or robustness difference is
630 * to be expected using explicit file offsets or individual file pointers.
631 * Perusal of a sampling of ROMIO code would seem to indicate that no
632 * difference is to be expected, but this might change with MPI IO variants
633 * or file systems, so this advanced setting is made possible.
634 *
635 * This setting is not available on a per-file basis, though this could be
636 * done in the future in the unexpected case of performance results
637 * showing this would be useful.
638 *
639 * parameters:
640 * positionning <-- chosen positionning method for MPI-IO
641 *----------------------------------------------------------------------------*/
642
643void
645
646/*----------------------------------------------------------------------------
647 * Print information on default options for file access.
648 *----------------------------------------------------------------------------*/
649
650void
652
653#if defined(HAVE_MPI)
654
655/*----------------------------------------------------------------------------
656 * Create a cs_file_serializer_t structure.
657 *
658 * The buf_block_size argument is optional, and may be used when the buffer
659 * on rank 0 is larger than (global_num_end - global_num_start)*size*stride
660 * bytes. If zero, a block size of (global_num_end - global_num_start) on
661 * rank 0 is assumed; a buffer may not be smaller than this, as it must
662 * initially contain all data on rank 0's block.
663 *
664 * parameters:
665 * size <-- size of each item of data in bytes
666 * stride <-- number of (interlaced) values per block item
667 * global_num_start <-- global number of first block item (1 to n numbering)
668 * global_num_end <-- global number of past-the end block item
669 * (1 to n numbering)
670 * buf_block_size <-- Local data buffer block size, or 0 for default
671 * global_num_end - global_num_start
672 * (only useful on rank 0)
673 * buf <-- pointer to local block data buffer
674 * comm <-- associated MPI communicator
675 *
676 * returns:
677 * pointer to new serializer structure
678 *----------------------------------------------------------------------------*/
679
681cs_file_serializer_create(size_t size,
682 size_t stride,
683 cs_gnum_t global_num_start,
684 cs_gnum_t global_num_end,
685 size_t buf_block_size,
686 void *buf,
687 MPI_Comm comm);
688
689/*----------------------------------------------------------------------------
690 * Destroy a cs_file_serializer_t structure.
691 *
692 * parameters:
693 * s <-> pointer to pointer structure that should be destroyed
694 *----------------------------------------------------------------------------*/
695
696void
698
699/*----------------------------------------------------------------------------
700 * Advance a cs_file_serializer_t structure.
701 *
702 * Data from the buffer of the next communicating rank is copied
703 * to rank 0 (this is a no-op the first time this function is called,
704 * as rank 0 already has its data).
705 *
706 * On rank 0, the return value may point to the buffer defined when
707 * initializing the serializer, or to an aditional buffer if the former is
708 * too small to receive data from all ranks.
709 *
710 * Note also that for ranks > 0, this function always returns NULL,
711 * as only one call is needed for those ranks.
712 *
713 * parameters:
714 * s <-- pointer to serializer structure
715 * cur_range --> optional start and past-the end global numbers for the
716 * current block (size: 2), or NULL; only on rank 0
717 *
718 * returns:
719 * a pointer to the buffer containing new data (first call counts as new),
720 * or NULL if we are finished; always NULL on ranks > 0
721 *----------------------------------------------------------------------------*/
722
723void *
725 cs_gnum_t cur_range[2]);
726
727#endif /* defined(HAVE_MPI) */
728
729/*----------------------------------------------------------------------------
730 * Create a new directory using default permissions.
731 *
732 * This function is similar to the POSIX function mkdir(), except that
733 * it has no "mode" argument: by default, on a POSIX type system,
734 * permissions include read, write, and execute access for the user,
735 * group and others, modified by the users umask value (so with a
736 * typical configuration, the user will have read, write, and execute
737 * pemission, the group and others will only have read and execute
738 * permission, but this behavior may be modified).
739 *
740 * Also, contrary to the usual mkdir(), if the directory already
741 * exists (and is truly a directory), this is considered a success
742 * and not a failure, and 0 is returned: the aim of this function
743 * is to make a directory available, so if it already exists,
744 * this is considered acceptable.
745 *
746 * parameters:
747 * path: <-- name of new directory.
748 *
749 * returns:
750 * 0 on success, -1 if an error occured (in which case errno
751 * contains the appropriate error code). If the underlying
752 * system has no mkdir() function or it was not detected
753 * upon BFT configuration, 1 is returned.
754 *----------------------------------------------------------------------------*/
755
756int
757cs_file_mkdir_default(const char *path);
758
759/*----------------------------------------------------------------------------
760 * Check if a file exists and is a regular file.
761 *
762 * parameters:
763 * path <-- file name.
764 *
765 * returns:
766 * 1 if file exists and is a regular file, 0 otherwise.
767 *----------------------------------------------------------------------------*/
768
769int
770cs_file_isreg(const char *path);
771
772/*----------------------------------------------------------------------------
773 * Check if a directory exists.
774 *
775 * parameters:
776 * path <-- directory name.
777 *
778 * returns:
779 * 1 if directory exists, 0 otherwise.
780 *----------------------------------------------------------------------------*/
781
782int
783cs_file_isdir(const char *path);
784
785/*----------------------------------------------------------------------------
786 * List files inside a directory.
787 *
788 * The array returned must be freed by the caller using BFT_FREE,
789 * as well as the individual entries in the array.
790 *
791 * parameters:
792 * path <-- name of directory.
793 *
794 * returns:
795 * an array of file names in a directory. The last entry is set to NULL.
796 * If no means to list the directory or an error occured, the return
797 * value is simply NULL.
798 *----------------------------------------------------------------------------*/
799
800char **
801cs_file_listdir(const char *path);
802
803/*----------------------------------------------------------------------------
804 * Return the size of a file.
805 *
806 * If the file does not exist, 0 is returned.
807 *
808 * Note that for some special files, such as files in the Linux /proc
809 * directory, this may return 0.
810 *
811 * parameters
812 * path <-- file path.
813 *
814 * returns:
815 * size of file.
816 *----------------------------------------------------------------------------*/
817
819cs_file_size(const char *path);
820
821/*----------------------------------------------------------------------------
822 * Remove a file if it exists and is a regular file.
823 *
824 * parameters
825 * path <-- file path.
826 *
827 * returns:
828 * 0 in case of success or if file does not exist, 0 otherwise.
829 *----------------------------------------------------------------------------*/
830
831int
832cs_file_remove(const char *path);
833
834/*----------------------------------------------------------------------------*/
835
837
838#endif /* __CS_FILE_H__ */
#define BEGIN_C_DECLS
Definition cs_defs.h:467
#define END_C_DECLS
Definition cs_defs.h:468
cs_file_mpi_positionning_t cs_file_get_mpi_io_positionning(void)
Get the positionning method for MPI-IO.
Definition cs_file.c:3236
void cs_file_dump(const cs_file_t *f)
Dump the metadata of a file structure in human readable form.
Definition cs_file.c:2789
cs_file_off_t cs_file_tell(cs_file_t *f)
Return the position of the file pointer.
Definition cs_file.c:2748
void cs_file_set_mpi_io_positionning(cs_file_mpi_positionning_t positionning)
Set the positionning method for MPI-IO.
Definition cs_file.c:3260
int cs_file_get_swap_endian(const cs_file_t *f)
Return a file's byte-swapping behavior.
Definition cs_file.c:2071
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:2887
void cs_file_serializer_destroy(cs_file_serializer_t **s)
Destroy a cs_file_serializer_t structure.
Definition cs_file.c:3410
const char * cs_file_get_name(const cs_file_t *f)
Return a file's name.
Definition cs_file.c:2020
struct _cs_file_serializer_t cs_file_serializer_t
Definition cs_file.h:59
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:1789
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:3378
int cs_file_isdir(const char *path)
Check if a directory exists.
Definition cs_file.c:3696
void cs_file_set_default_comm(int block_rank_step, int block_min_size, MPI_Comm comm)
Set default MPI communicator values for file access.
Definition cs_file.c:3112
long long cs_file_off_t
Definition cs_file.h:107
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:2210
cs_file_t * cs_file_free(cs_file_t *f)
Destroy a file descriptor and close the associated file.
Definition cs_file.c:1991
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:1907
cs_file_access_t
Definition cs_file.h:84
@ CS_FILE_MPI_INDEPENDENT
Definition cs_file.h:89
@ CS_FILE_MPI_COLLECTIVE
Definition cs_file.h:91
@ CS_FILE_MPI_NON_COLLECTIVE
Definition cs_file.h:90
@ CS_FILE_STDIO_SERIAL
Definition cs_file.h:87
@ CS_FILE_STDIO_PARALLEL
Definition cs_file.h:88
@ CS_FILE_DEFAULT
Definition cs_file.h:86
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:2340
void cs_file_free_defaults(void)
Free the default options for file access.
Definition cs_file.c:2841
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:2037
struct _cs_file_t cs_file_t
Definition cs_file.h:54
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:2556
cs_file_off_t cs_file_size(const char *path)
Return the size of a file.
Definition cs_file.c:3802
int cs_file_remove(const char *path)
Remove a file if it exists and is a regular file.
Definition cs_file.c:3854
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:2659
int cs_file_isreg(const char *path)
Check if a file exists and is a regular file.
Definition cs_file.c:3650
void cs_file_defaults_info(void)
Print information on default options for file access.
Definition cs_file.c:3272
cs_file_mode_t
Definition cs_file.h:64
@ CS_FILE_MODE_APPEND
Definition cs_file.h:68
@ CS_FILE_MODE_WRITE
Definition cs_file.h:67
@ CS_FILE_MODE_READ
Definition cs_file.h:66
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:2112
void cs_file_get_default_comm(int *block_rank_step, int *block_min_size, MPI_Comm *block_comm, MPI_Comm *comm)
Get default MPI communicator values for file access.
Definition cs_file.c:3049
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:3170
char ** cs_file_listdir(const char *path)
List files inside a directory.
Definition cs_file.c:3743
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:2953
int cs_file_mkdir_default(const char *path)
Create a new directory using default permissions.
Definition cs_file.c:3575
cs_file_seek_t
Definition cs_file.h:74
@ CS_FILE_SEEK_SET
Definition cs_file.h:76
@ CS_FILE_SEEK_END
Definition cs_file.h:78
@ CS_FILE_SEEK_CUR
Definition cs_file.h:77
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:1961
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:2456
const char * cs_file_access_name[]
Definition cs_file.c:280
const char * cs_file_mpi_positionning_name[]
Definition cs_file.c:290
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:3443
void cs_file_set_swap_endian(cs_file_t *f, int swap)
Set a file's byte-swapping behavior.
Definition cs_file.c:2088
cs_file_mpi_positionning_t
Definition cs_file.h:97
@ CS_FILE_MPI_INDIVIDUAL_POINTERS
Definition cs_file.h:100
@ CS_FILE_MPI_EXPLICIT_OFFSETS
Definition cs_file.h:99