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

Serial example showing the very basic usage of SIONlib using the serial API.

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 "sion.h"
#define FNAMELEN 255
int main(int argc, char** argv)
{
/* for SIONlib open call */
sion_int32 fsblksize = -1;
sion_int64* chunksizes = NULL;
int* globalranks = NULL;
int ntasks = -1;
int nfiles = 1;
/* other variables */
int sid = 0;
int task = 0;
size_t buffer_size = 1024;
char* buffer = NULL;
size_t bavail = 0;
size_t bread = 0;
size_t bwrote = 0;
/* read */
ntasks = 4;
chunksizes = (sion_int64*)malloc(ntasks * sizeof (sion_int64));
globalranks = (int*)malloc(ntasks * sizeof (int));
buffer = (char*)malloc(buffer_size);
for (task = 0; task < ntasks; ++task) {
chunksizes[task] = 100;
globalranks[task] = task;
}
memset(buffer, 'A', buffer_size);
sid = sion_open("serfile.sion", "wb", &ntasks, &nfiles, &chunksizes,
&fsblksize, &globalranks, NULL);
bwrote = sion_fwrite(buffer, 1, buffer_size, sid);
printf("Wrote %zd bytes\n", bwrote);
sion_close(sid);
free(chunksizes);
chunksizes = NULL;
free(globalranks);
globalranks = NULL;
free(buffer);
buffer = NULL;
/* write */
sid = sion_open("serfile.sion", "rb", &ntasks, &nfiles, &chunksizes,
&fsblksize, &globalranks, NULL);
buffer = (char*)malloc(bavail);
bread = sion_fread(buffer, 1, bavail, sid);
printf("Read %zd bytes\n", bread);
sion_close(sid);
free(chunksizes);
chunksizes = NULL;
free(globalranks);
globalranks = NULL;
free(buffer);
buffer = NULL;
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_open(char *fname, const char *file_mode, int *ntasks, int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize, int **globalranks, FILE **fileptr)
Open a sion file in serial mode.
Definition: sion_serial.c:54
int sion_close(int sid)
Close a sion file.
Definition: sion_serial.c:106