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>
#define FNAMELEN 255
#define BUFSIZE (1024 * 1024)
int main(int argc, char** argv)
{
char fname[FNAMELEN];
int numFiles = 0;
MPI_Comm gComm, lComm;
sion_int64 chunksize = 0;
sion_int32 fsblksize = 0;
int globalrank = 0;
FILE* fileptr = NULL;
char* newfname = NULL;
int rank = 0;
int size = 0;
int sid = 0;
sion_int64 left = 0;
size_t btoread = 0;
size_t bread = 0;
size_t bwrote = 0;
char* localbuffer = NULL;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
localbuffer = (char*)malloc(BUFSIZE);
memset(localbuffer, 'A', BUFSIZE);
strcpy(fname, "parfile.sion");
numFiles = 1;
gComm = lComm = MPI_COMM_WORLD;
chunksize = 10 * 1024 * 1024;
fsblksize = -1;
globalrank = rank;
fileptr = NULL;
&fsblksize, &globalrank, &fileptr, &newfname);
left = BUFSIZE;
printf("Task %02d: wrote bytes: %zd\n", rank, bwrote);
printf("Task %02d: wrote sionfile -> %s\n", rank, newfname);
&fsblksize, &globalrank, &fileptr, &newfname);
printf("Task %02d: read bytes: %zd\n", rank, bread);
}
printf("Task %02d: read sionfile -> %s\n", rank, newfname);
MPI_Finalize();
return 0;
}
size_t sion_fread(void *data, size_t size, size_t nitems, int sid)
Read data from sion file.
size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid)
Write data to sion file.
sion_int64 sion_bytes_avail_in_chunk(int sid)
Function that returns the number of bytes available in the current chunk.
int sion_feof(int sid)
Function that indicates whether the end of file is reached for this task.
int sion_paropen_mpi(const char *fname, const char *file_mode, int *numFiles, MPI_Comm gComm, const MPI_Comm *lComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, FILE **fileptr, char **newfname)
Open a sion file using MPI.
int sion_parclose_mpi(int sid)
Close a sion file using MPI.