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

#ifndef SION_SION_OMPI_H
#define SION_SION_OMPI_H

#ifdef SION_OMPI

/*!
 * \defgroup ompi MPI+OpenMP Parallel API
 * @{
 * \brief Open (and close) SIONlib files from multiple OpenMP threads on
 *   on multiple MPI processes in parallel
 *
 * \see \ref overview
 */

#include <stdint.h>
#include <stdio.h>

#include <mpi.h>

#include "sion_const.h"
#include "sion_datatypes_mpi.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
 * @brief Open a sion file using OpenMP/MPI.
 *
 * This function opens a sion file using OpenMP/MPI. It processes the
 * OpenMP/MPI specific parts and then passes its arguments on to
 * lsion_generic_paropen().
 *
 * @param[in]       fname        name of file, should be equal on all tasks
 * @param[in]       file_mode    like the type parameter of fopen (currently recognized options: "rb", "wb")
 * @param[in,out]   numFiles     number of multi files to use (-1 for automatic choosing from local communicator)
 * @param[in]       gComm        global communicator
 * @param[in]       lComm        local communicator (= gComm if no adaption to I/O nodes is needed)
 * @param[in,out]   chunksize    maximum size to be written with single write call
 * @param[in,out]   fsblksize    file system block size (-1 for automatic)
 * @param[in,out]   globalrank   global rank of process
 * @param[in,out]   fileptr      file pointer (NULL for not using an external file pointer)
 * @param[out]      newfname     return value for actual file name if using multi files
 *
 * @retval         sid          sion file handle or -1 if error occured
 */
int lsion_paropen_ompi(const char *fname, const char *file_mode, int *numFiles, MPI_Comm gComm, const MPI_Comm *lComm,
  int64_t *chunksize, int32_t *fsblksize, int *globalrank, FILE **fileptr, char **newfname);

/*!\brief closes a SION file previously opened in OpenMP/MPI mode
 *
 * @param[in] *sid					 SION file id
 *
 */
int lsion_parclose_ompi(int sid);

#ifdef __cplusplus
}
#endif

/// @}

#endif

#endif
