SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
simple/sionpar.c

Parallel example showing the very basic usage of SIONlib using MPI.

More examples can be found in 'examples' folder of the SIONlib installation.

/****************************************************************************
** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
*****************************************************************************
** Copyright (c) 2008-2019 **
** Forschungszentrum Juelich, Juelich Supercomputing Centre **
** **
** See the file COPYRIGHT in the package base directory for details **
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include "sion.h"
#define FNAMELEN 255
#define BUFSIZE (1024 * 1024)
int main(int argc, char** argv)
{
/* for SIONlib open call */
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;
/* other variables */
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);
/* allocate and initalize a buffer */
localbuffer = (char*)malloc(BUFSIZE);
memset(localbuffer, 'A', BUFSIZE);
/* inital parameters */
strcpy(fname, "parfile.sion");
numFiles = 1;
gComm = lComm = MPI_COMM_WORLD;
chunksize = 10 * 1024 * 1024;
fsblksize = -1;
globalrank = rank;
fileptr = NULL;
/* write */
sid = sion_paropen_mpi(fname, "bw", &numFiles, gComm, &lComm, &chunksize,
&fsblksize, &globalrank, &fileptr, &newfname);
left = BUFSIZE;
bwrote = sion_fwrite(localbuffer, 1, left, sid);
printf("Task %02d: wrote bytes: %zd\n", rank, bwrote);
printf("Task %02d: wrote sionfile -> %s\n", rank, newfname);
/* read */
sid = sion_paropen_mpi(fname, "br", &numFiles, gComm, &lComm, &chunksize,
&fsblksize, &globalrank, &fileptr, &newfname);
while (!sion_feof(sid)) {
btoread = sion_bytes_avail_in_chunk(sid);
bread = sion_fread(localbuffer, 1, btoread, sid);
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.
Definition: sion_common.c:609
size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid)
Write data to sion file.
Definition: sion_common.c:470
sion_int64 sion_bytes_avail_in_chunk(int sid)
Function that returns the number of bytes available in the current chunk.
Definition: sion_common.c:894
int sion_feof(int sid)
Function that indicates whether the end of file is reached for this task.
Definition: sion_common.c:809
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.
Definition: sion_mpi_gen.c:85
int sion_parclose_mpi(int sid)
Close a sion file using MPI.
Definition: sion_mpi_gen.c:230