SDDSlib
|
MPI-based Parallel I/O Functions for SDDS Datasets. More...
Go to the source code of this file.
Functions | |
char * | BlankToNull (char *string) |
Converts a blank string to NULL . | |
void | SDDS_MPI_GOTO_ERROR (FILE *fp, char *str, int32_t mpierr, int32_t exit_code) |
Handles MPI errors by printing an error message and optionally exiting. | |
int32_t | SDDS_MPI_File_Open (MPI_DATASET *MPI_dataset, char *filename, unsigned long flags) |
Opens an MPI file with the specified flags. | |
char * | SDDS_CreateNamelistField (char *name, char *value) |
Creates a namelist field string from a name and value. | |
char * | SDDS_CreateDescription (char *text, char *contents) |
Creates a description block for the SDDS layout. | |
char * | SDDS_CreateParameterDefinition (PARAMETER_DEFINITION *parameter_definition) |
Creates a parameter definition block for the SDDS layout. | |
char * | SDDS_CreateColumnDefinition (COLUMN_DEFINITION *column_definition) |
Creates a column definition block for the SDDS layout. | |
char * | SDDS_CreateArrayDefinition (ARRAY_DEFINITION *array_definition) |
Creates an array definition block for the SDDS layout. | |
char * | SDDS_CreateAssociateDefinition (ASSOCIATE_DEFINITION *associate_definition) |
Creates an associate definition block for the SDDS layout. | |
char * | SDDS_CreateDataMode (DATA_MODE *data_mode) |
Creates a data mode block for the SDDS layout. | |
int32_t | SDDS_MPI_WriteAsciiString (SDDS_DATASET *SDDS_dataset, char *string) |
Writes an ASCII string to the SDDS dataset using MPI. | |
int32_t | SDDS_MPI_WriteLayout (SDDS_DATASET *SDDS_dataset) |
Writes the layout of the SDDS dataset to the MPI file. | |
void | SDDS_MPI_BOMB (char *text, MPI_File *mpi_file) |
Terminates the program after handling errors and cleaning up MPI resources. | |
int32_t | SDDS_MPI_WritePage (SDDS_DATASET *SDDS_dataset) |
Writes a page of data to the MPI file associated with the SDDS dataset. | |
MPI_Datatype | Convert_SDDStype_To_MPItype (int32_t SDDS_type) |
Converts an SDDS data type to the corresponding MPI data type. | |
int32_t | SDDS_MPI_Terminate (SDDS_DATASET *SDDS_dataset) |
Terminates the SDDS dataset by freeing all allocated resources and closing MPI files. | |
int32_t | SDDS_MPI_InitializeOutput (SDDS_DATASET *SDDS_dataset, char *description, char *contents, char *filename, unsigned long flags, short column_major) |
Initializes the SDDS dataset for MPI output. | |
int32_t | SDDS_MPI_InitializeCopy (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, short column_major) |
Initializes a copy of an SDDS dataset for MPI output. | |
void | SDDS_MPI_Setup (SDDS_DATASET *SDDS_dataset, int32_t parallel_io, int32_t n_processors, int32_t myid, MPI_Comm comm, short master_read) |
Sets up the SDDS dataset for MPI operations. | |
int32_t | SDDS_MPI_DisconnectFile (SDDS_DATASET *SDDS_dataset) |
Disconnects the MPI file associated with the SDDS dataset. | |
int32_t | SDDS_MPI_ReconnectFile (SDDS_DATASET *SDDS_dataset) |
Reconnects the MPI file associated with the SDDS dataset. | |
Variables | |
int32_t | SDDS_mpi_error_str_len |
char | SDDS_mpi_error_str [MPI_MAX_ERROR_STRING] |
char * | SDDS_MPI_FILE_TYPE [2] = {"external32", "native"} |
static int32_t | terminateMode = 0 |
MPI-based Parallel I/O Functions for SDDS Datasets.
This file implements a suite of functions to facilitate parallel input/output operations for SDDS (Self Describing Data Set) datasets using MPI (Message Passing Interface). It includes functionalities for initializing MPI output, writing dataset layouts and data pages, handling errors, terminating datasets, and managing MPI file connections.
Definition in file SDDSmpi_output.c.
char * BlankToNull | ( | char * | string | ) |
Converts a blank string to NULL
.
This function checks if the input string is NULL
or consists only of whitespace characters. If so, it returns NULL
; otherwise, it returns the original string.
string | The input string to check. |
NULL
if the string is NULL
or blank, otherwise returns the original string. Definition at line 77 of file SDDSmpi_output.c.
MPI_Datatype Convert_SDDStype_To_MPItype | ( | int32_t | SDDS_type | ) |
Converts an SDDS data type to the corresponding MPI data type.
This function maps custom SDDS data types to their equivalent MPI data types using a switch statement. If an unknown SDDS data type is provided, the function calls SDDS_Bomb
to handle the error.
SDDS_type | The SDDS data type to convert. |
MPI_Datatype
. Definition at line 731 of file SDDSmpi_output.c.
char * SDDS_CreateArrayDefinition | ( | ARRAY_DEFINITION * | array_definition | ) |
Creates an array definition block for the SDDS layout.
This function allocates and constructs an array definition block based on the provided ARRAY_DEFINITION
structure. It includes fields such as name
, symbol
, units
, description
, format_string
, group_name
, type
, dimensions
, and ends the block.
array_definition | Pointer to the ARRAY_DEFINITION structure. |
Definition at line 289 of file SDDSmpi_output.c.
char * SDDS_CreateAssociateDefinition | ( | ASSOCIATE_DEFINITION * | associate_definition | ) |
Creates an associate definition block for the SDDS layout.
This function allocates and constructs an associate definition block based on the provided ASSOCIATE_DEFINITION
structure. It includes fields such as name
, filename
, contents
, path
, description
, and the associated SDDS index.
associate_definition | Pointer to the ASSOCIATE_DEFINITION structure. |
Definition at line 325 of file SDDSmpi_output.c.
char * SDDS_CreateColumnDefinition | ( | COLUMN_DEFINITION * | column_definition | ) |
Creates a column definition block for the SDDS layout.
This function allocates and constructs a column definition block based on the provided COLUMN_DEFINITION
structure. It includes fields such as name
, symbol
, units
, description
, format_string
, type
, and ends the block.
column_definition | Pointer to the COLUMN_DEFINITION structure. |
Definition at line 262 of file SDDSmpi_output.c.
char * SDDS_CreateDataMode | ( | DATA_MODE * | data_mode | ) |
Creates a data mode block for the SDDS layout.
This function allocates and constructs a data mode block based on the provided DATA_MODE
structure. It includes fields such as mode
, lines_per_row
, no_row_counts
, column_major_order
, and ends the block.
data_mode | Pointer to the DATA_MODE structure. |
NULL
if the mode is invalid. Definition at line 356 of file SDDSmpi_output.c.
char * SDDS_CreateDescription | ( | char * | text, |
char * | contents ) |
Creates a description block for the SDDS layout.
This function allocates and constructs a description block containing the provided text and contents. It formats the description in the SDDS namelist format.
text | The descriptive text. |
contents | The contents of the description. |
NULL
if both text
and contents
are NULL
. Definition at line 207 of file SDDSmpi_output.c.
char * SDDS_CreateNamelistField | ( | char * | name, |
char * | value ) |
Creates a namelist field string from a name and value.
This function allocates and constructs a string representing a namelist field in the format name=value
or name="value"
depending on the content of the value. It handles escaping of double quotes within the value and ensures proper formatting based on the presence of special characters.
name | The name of the field. |
value | The value of the field. |
NULL
if the name is NULL
or empty. sprintf(contents, "%s%s=%s, ", contents, name, value);
Definition at line 156 of file SDDSmpi_output.c.
char * SDDS_CreateParameterDefinition | ( | PARAMETER_DEFINITION * | parameter_definition | ) |
Creates a parameter definition block for the SDDS layout.
This function allocates and constructs a parameter definition block based on the provided PARAMETER_DEFINITION
structure. It includes fields such as name
, symbol
, units
, description
, format_string
, type
, and fixed_value
.
parameter_definition | Pointer to the PARAMETER_DEFINITION structure. |
Definition at line 231 of file SDDSmpi_output.c.
void SDDS_MPI_BOMB | ( | char * | text, |
MPI_File * | mpi_file ) |
Terminates the program after handling errors and cleaning up MPI resources.
This function prints all accumulated SDDS errors to stderr
using SDDS_PrintErrors
. If a custom error message (text
) is provided, it is printed to stderr
. If an MPI file pointer (mpi_file
) is provided, the MPI file is closed. Finally, the MPI environment is finalized, and the program exits with a status of 1.
text | A custom error message to display. Can be NULL . |
mpi_file | Pointer to an MPI_File to be closed. Can be NULL . |
Definition at line 681 of file SDDSmpi_output.c.
int32_t SDDS_MPI_DisconnectFile | ( | SDDS_DATASET * | SDDS_dataset | ) |
Disconnects the MPI file associated with the SDDS dataset.
This function checks the validity of the dataset and ensures that the file is connected and has a valid filename. It then closes the MPI file and marks the dataset as disconnected.
SDDS_dataset | Pointer to the SDDS_DATASET structure whose file is to be disconnected. |
1
if the file was successfully disconnected, 0
otherwise. Definition at line 1089 of file SDDSmpi_output.c.
int32_t SDDS_MPI_File_Open | ( | MPI_DATASET * | MPI_dataset, |
char * | filename, | ||
unsigned long | flags ) |
Opens an MPI file with the specified flags.
This function opens an MPI file using the given filename and flags, setting the appropriate MPI file mode based on the flags. It also initializes the MPI dataset's debug file pointer and other related fields. If the file is successfully opened, it returns 1; otherwise, it handles the error and may exit the program.
MPI_dataset | Pointer to the MPI_DATASET structure to initialize. |
filename | The name of the file to open. |
flags | Flags indicating the mode in which to open the file (e.g., read-only, write-only, read-write). |
1
if the file was successfully opened, 0
otherwise. Definition at line 113 of file SDDSmpi_output.c.
void SDDS_MPI_GOTO_ERROR | ( | FILE * | fp, |
char * | str, | ||
int32_t | mpierr, | ||
int32_t | exit_code ) |
Handles MPI errors by printing an error message and optionally exiting.
Retrieves the MPI error string corresponding to the given error code. If a string is provided, it prints the string followed by the MPI error message to the specified file pointer. If exit_code
is non-zero, the program exits with a status of 1.
fp | File pointer to write the error message to. |
str | Custom error message to prefix to the MPI error string. Can be NULL . |
mpierr | The MPI error code. |
exit_code | If non-zero, the function will terminate the program. |
Definition at line 93 of file SDDSmpi_output.c.
int32_t SDDS_MPI_InitializeCopy | ( | SDDS_DATASET * | SDDS_target, |
SDDS_DATASET * | SDDS_source, | ||
char * | filename, | ||
short | column_major ) |
Initializes a copy of an SDDS dataset for MPI output.
This function creates a new SDDS dataset (SDDS_target
) by copying the layout from an existing dataset (SDDS_source
). It sets up the target dataset for MPI output, opens the specified file, and writes the layout to the file. The function also sets the data mode to column-major if specified.
SDDS_target | Pointer to the target SDDS_DATASET structure to initialize. |
SDDS_source | Pointer to the source SDDS_DATASET structure to copy from. |
filename | The name of the file to initialize for output. |
column_major | If non-zero, data will be written in column-major order. |
1
if the copy and initialization were successful, 0
otherwise. Definition at line 1009 of file SDDSmpi_output.c.
int32_t SDDS_MPI_InitializeOutput | ( | SDDS_DATASET * | SDDS_dataset, |
char * | description, | ||
char * | contents, | ||
char * | filename, | ||
unsigned long | flags, | ||
short | column_major ) |
Initializes the SDDS dataset for MPI output.
This function sets up the SDDS dataset for parallel output using MPI. It initializes the dataset with the provided description, contents, and filename, sets the column major order if specified, and opens the MPI file for writing. It also logs the initialization if MPI debugging is enabled.
SDDS_dataset | Pointer to the SDDS_DATASET structure to initialize. |
description | A description of the dataset. |
contents | Additional contents for the dataset description. |
filename | The name of the file to initialize for output. |
flags | Flags indicating the mode in which to open the file (e.g., read-only, write-only, read-write). |
column_major | If non-zero, data will be written in column-major order. |
1
if initialization was successful, 0
otherwise. Definition at line 975 of file SDDSmpi_output.c.
int32_t SDDS_MPI_ReconnectFile | ( | SDDS_DATASET * | SDDS_dataset | ) |
Reconnects the MPI file associated with the SDDS dataset.
This function checks the validity of the dataset and ensures that the file is currently disconnected and has a valid filename. It then reopens the MPI file in read-write mode, updates the file view, and marks the dataset as connected.
SDDS_dataset | Pointer to the SDDS_DATASET structure whose file is to be reconnected. |
1
if the file was successfully reconnected, 0
otherwise. Definition at line 1126 of file SDDSmpi_output.c.
void SDDS_MPI_Setup | ( | SDDS_DATASET * | SDDS_dataset, |
int32_t | parallel_io, | ||
int32_t | n_processors, | ||
int32_t | myid, | ||
MPI_Comm | comm, | ||
short | master_read ) |
Sets up the SDDS dataset for MPI operations.
This function initializes the SDDS_DATASET
structure for MPI-based parallel I/O. It zeroes out the dataset, allocates and initializes the MPI_DATASET
structure if parallel I/O is enabled, and sets MPI-related fields such as the number of processors, process ID, and MPI communicator.
SDDS_dataset | Pointer to the SDDS_DATASET structure to set up. |
parallel_io | If non-zero, the dataset will be set up for parallel I/O using MPI. |
n_processors | The total number of MPI processes. |
myid | The MPI process ID of the current process. |
comm | The MPI communicator to use for I/O operations. |
master_read | If non-zero, the master process will handle read operations. |
Definition at line 1060 of file SDDSmpi_output.c.
int32_t SDDS_MPI_Terminate | ( | SDDS_DATASET * | SDDS_dataset | ) |
Terminates the SDDS dataset by freeing all allocated resources and closing MPI files.
This function performs comprehensive cleanup of the SDDS_DATASET
structure, freeing all dynamically allocated memory associated with parameters, arrays, columns, and associates. It also closes the MPI file, finalizes MPI, and resets the dataset's layout and data structures.
SDDS_dataset | Pointer to the SDDS_DATASET structure to terminate. |
1
if termination was successful, 0
otherwise. Definition at line 771 of file SDDSmpi_output.c.
int32_t SDDS_MPI_WriteAsciiString | ( | SDDS_DATASET * | SDDS_dataset, |
char * | string ) |
Writes an ASCII string to the SDDS dataset using MPI.
This function writes the provided string to the SDDS dataset's MPI file. It handles buffering to optimize writes and manages buffer overflows by writing buffer contents to the file when necessary. Returns 1
on success, 0
on failure.
SDDS_dataset | Pointer to the SDDS_DATASET structure. |
string | The ASCII string to write. |
1
if the string was successfully written, 0
otherwise. Definition at line 390 of file SDDSmpi_output.c.
int32_t SDDS_MPI_WriteLayout | ( | SDDS_DATASET * | SDDS_dataset | ) |
Writes the layout of the SDDS dataset to the MPI file.
This function writes the SDDS dataset layout information to the associated MPI file. It sets the file view, checks and saves the dataset, determines the byte order, allocates and manages the write buffer, and writes various layout components including description, parameters, arrays, columns, associates, and data mode. It ensures proper synchronization and handles errors appropriately. Only the MPI process with rank 0 performs the actual write operations.
SDDS_dataset | Pointer to the SDDS_DATASET structure. |
1
if the layout was successfully written, 0
otherwise. Definition at line 454 of file SDDSmpi_output.c.
int32_t SDDS_MPI_WritePage | ( | SDDS_DATASET * | SDDS_dataset | ) |
Writes a page of data to the MPI file associated with the SDDS dataset.
This function checks the validity of the dataset and ensures that the layout has been written and that the file is connected. If these conditions are met, it proceeds to write a binary page using SDDS_MPI_WriteBinaryPage
.
SDDS_dataset | Pointer to the SDDS_DATASET structure containing the dataset information. |
1
if the page was successfully written, 0
otherwise. Definition at line 701 of file SDDSmpi_output.c.
char SDDS_mpi_error_str[MPI_MAX_ERROR_STRING] |
Definition at line 28 of file SDDSmpi_output.c.
int32_t SDDS_mpi_error_str_len |
Definition at line 27 of file SDDSmpi_output.c.
char* SDDS_MPI_FILE_TYPE[2] = {"external32", "native"} |
Definition at line 30 of file SDDSmpi_output.c.
|
static |
Definition at line 32 of file SDDSmpi_output.c.