/****************************************************************************
**  SIONLIB     http://www.fz-juelich.de/jsc/sionlib                       **
*****************************************************************************
**  Copyright (c) 2008-2015                                                **
**  Forschungszentrum Juelich, Juelich Supercomputing Centre               **
**                                                                         **
**  See the file COPYRIGHT in the package base directory for details       **
****************************************************************************/

/*!
 * \file
 *
 * \ref api_page
 */

#ifndef SION_SION_MPI
#define SION_SION_MPI

#ifdef MPI_VERSION
#include "sion_datatypes_mpi.h"

#ifdef __cplusplus
extern "C" {
#endif
  int lsion_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);

  int lsion_parclose_mpi(   int      sid  );
  int lsion_parreinit_mpi(  int sid,
			   sion_int64 chunksize );

/* new mapped functions */

/* open function:
   write-mode:
     if numFiles > 1  --> mapping_filenrs, mapping_lranks contains local mappping
    */

  int lsion_paropen_mapped_mpi(    char          *fname,
				  const char    *file_mode,
				  int           *numFiles,
				  MPI_Comm       gComm,
				  int           *nlocaltasks,
				  int          **globalranks,
				  sion_int64   **chunksizes,
				  int          **mapping_filenrs, 
				  int          **mapping_lranks,
				  sion_int32    *fsblksize,
				  FILE         **fileptr);

  int lsion_parclose_mapped_mpi(   int      sid  );

  /* Serialization */
  int lsion_startof_transaction_mpi(   int      sid  );
  int lsion_endof_transaction_mpi  (   int      sid  );
  size_t lsion_coll_fwrite_mpi(const void *data, size_t size, size_t nitems, int sid);
  size_t lsion_coll_fread_mpi( void *data, size_t size, size_t nitems, int sid);

  /* for backward compatibility */
  int lsion_paropen_comms_mpi(char *fname,
			     const char *file_mode,
			     int *numFiles,
			     MPI_Comm gComm,
			     MPI_Comm lComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, FILE **fileptr, char *newfname);
  int lsion_paropen_multi_mpi(char *fname,
			     const char *file_mode,
			     int *numFiles,
			     MPI_Comm gComm,
			     MPI_Comm *lComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, FILE **fileptr, char *newfname);


#ifdef __cplusplus
}
#endif
  
#else 
  #define lsion_paropen_mpi "lsion_paropen_mpi not defined if mpi.h not included, please include mpi.h before including sion_mpi.h"
#endif


#endif
