Parallel example showing the very basic usage of SIONlib using MPI.
More examples can be found in 'examples' folder of the SIONlib installation.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include "sion.h"
#define BUFFER_SIZE (1024 * 1024)
int main(int argc, char** argv)
{
MPI_Init(&argc, &argv);
int size, rank;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
char localbuffer[BUFFER_SIZE];
memset(localbuffer, 'A', BUFFER_SIZE);
size_t bwrote =
sion_write(localbuffer, 1, BUFFER_SIZE, sid);
printf("Task %02d: wrote bytes: %zu\n", rank, bwrote);
size_t bread =
sion_read(localbuffer, 1, BUFFER_SIZE, sid);
printf("Task %02d: read bytes: %zu\n", rank, bread);
printf(
"Task %02d: at end of file: %s\n", rank, (
sion_eof(sid)) ?
"true" :
"false");
MPI_Finalize();
return 0;
}
size_t sion_write(const void *data, size_t size, size_t nitems, int sid)
Write data to a SIONlib file.
size_t sion_read(void *data, size_t size, size_t nitems, int sid)
Read data from SIONlib file.
int sion_eof(int sid)
Function that indicates whether the end of this logical file has been reached.
@ SION_OPEN_WRITE
open the file for writing only
@ SION_OPEN_READ
open the file for reading only
int sion_paropen_mpi(const char *filename, sion_open_mode mode, MPI_Comm communicator, const sion_mpi_options *options)
Open a SIONlib file from multiple MPI processes.
int sion_parclose_mpi(int sid)
Close a SIONlib file using MPI.