Commit 362206d0 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Put C/Fortran interface functions into separate source file.

* This is meant to decrease interdependence of Fortran and C bindings.
parent 98d9fa60
......@@ -55,7 +55,7 @@ libscalesppm_a_SOURCES=ppm/scales_ppm.f90 \
solver/solvers.f90 \
solver/solver_all.f90 \
\
core/core.c core/core.h \
core/core.c core/core.h core/core_cf.c \
core/ppm_statistics.f90 \
core/ppm_combinatorics.f90 \
core/ppm_math_extensions.f90 \
......
......@@ -78,21 +78,6 @@ PPM_set_default_comm_f(MPI_Fint *comm_f)
PPM_default_comm = comm_c;
}
PROTOCCALLSFSUB1(PPM_SET_DEFAULT_COMM_F, ppm_set_default_comm_f, INT)
void
PPM_set_default_comm(MPI_Comm comm)
{
MPI_Fint comm_f;
#if defined(USE_MPI)
comm_f = MPI_Comm_c2f(comm);
#else
comm_f = comm;
#endif
PPM_default_comm = comm;
CCALLSFSUB1(PPM_SET_DEFAULT_COMM_F, ppm_set_default_comm_f, INT, comm_f);
}
FCALLSCSUB1(PPM_set_default_comm_f, PPM_SET_DEFAULT_COMM,
ppm_set_default_comm, PVOID)
......@@ -137,78 +122,9 @@ PPM_restore_default_abort_handler()
PPM_abort = PPM_abort_default;
}
FCALLSCSUB0(PPM_restore_default_abort_handler, PPM_RESTORE_DEFAULT_ABORT_HNDL,
ppm_restore_default_abort_hndl)
static void
abort_ppm_handler_wrapper(MPI_Comm comm, const char msg[],
const char source[], int line);
static void
set_abort_ppm_handler_f(void *abort_ppm_handler);
FCALLSCSUB1(set_abort_ppm_handler_f, PPM_SET_ABORT_HANDLER,
ppm_set_abort_handler, ROUTINE)
static void
PPM_abort_default_f(MPI_Fint *comm_f, const char *msg, const char *source,
int line)
{
#if defined(USE_MPI)
int flag = 0;
MPI_Comm comm_c = (MPI_Initialized(&flag) == MPI_SUCCESS && flag)?
MPI_Comm_f2c(*comm_f):PPM_default_comm;
#else
MPI_Comm comm_c = *comm_f;
#endif
PPM_abort_default(comm_c, msg, source, line);
}
FCALLSCSUB4(PPM_abort_default_f,PPM_ABORT_DEFAULT,ppm_abort_default,
PVOID,STRING,STRING,INT)
/* this must be the last piece of code in the file because we
* redefine a cfortran.h internal here, to allow calls to Fortran
* function pointers */
#undef CFC_
#define CFC_(UN,LN) (UN)
#undef CFextern
#define CFextern typedef
PROTOCCALLSFSUB4(*PPM_fortran_abort_func,,PVOID,STRING,STRING,INT)
#undef CFextern
#define CFextern static
static PPM_fortran_abort_func abort_ppm_fortran_fp;
static void
set_abort_ppm_handler_f(void *abort_ppm_handler)
{
abort_ppm_fortran_fp = (PPM_fortran_abort_func)abort_ppm_handler;
PPM_abort = abort_ppm_handler_wrapper;
}
static void
abort_ppm_handler_wrapper(MPI_Comm comm, const char msg[],
const char source[], int line)
{
#if defined(USE_MPI)
int flag = 0;
MPI_Fint comm_f = (MPI_Initialized(&flag) == MPI_SUCCESS && flag)?
MPI_Comm_c2f(comm):(MPI_Fint)0;
#else
MPI_Fint comm_f = comm;
#endif
/* cfortran.h does not understand const char * */
char *msg_arg = (char *)msg, *source_arg = (char *)source;
#undef CPPPROTOCLSFSUB14
#define CPPPROTOCLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE)
CCALLSFSUB4(*abort_ppm_fortran_fp,,PVOID,STRING,STRING,INT,
&comm_f, msg_arg, source_arg, line);
}
/*
* Local Variables:
* license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm"
......
/*
* @file core_cf.c
* @brief ScalES-PPM core library C/Fortran interface
*
* Copyright (C) 2012 Thomas Jahns <jahns@dkrz.de>
*
* @version 1.0
* Keywords:
* @author Thomas Jahns <jahns@dkrz.de>
* Maintainer: Thomas Jahns <jahns@dkrz.de>
* URL: https://www.dkrz.de/redmine/projects/show/scales-ppm
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the DKRZ GmbH nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <cfortran.h>
#include "core.h"
PROTOCCALLSFSUB1(PPM_SET_DEFAULT_COMM_F, ppm_set_default_comm_f, INT)
void
PPM_set_default_comm(MPI_Comm comm)
{
MPI_Fint comm_f;
#if defined(USE_MPI)
comm_f = MPI_Comm_c2f(comm);
#else
comm_f = comm;
#endif
PPM_default_comm = comm;
/* FIXME: convert this to function pointer, default NULL,
* initialized by Fortran interface */
CCALLSFSUB1(PPM_SET_DEFAULT_COMM_F, ppm_set_default_comm_f, INT, comm_f);
}
static void
abort_ppm_handler_wrapper(MPI_Comm comm, const char msg[],
const char source[], int line);
static void
set_abort_ppm_handler_f(void *abort_ppm_handler);
FCALLSCSUB1(set_abort_ppm_handler_f, PPM_SET_ABORT_HANDLER,
ppm_set_abort_handler, ROUTINE)
static void
PPM_abort_default_f(MPI_Fint *comm_f, const char *msg, const char *source,
int line)
{
#if defined(USE_MPI)
int flag = 0;
MPI_Comm comm_c = (MPI_Initialized(&flag) == MPI_SUCCESS && flag)?
MPI_Comm_f2c(*comm_f):PPM_default_comm;
#else
MPI_Comm comm_c = *comm_f;
#endif
PPM_abort_default(comm_c, msg, source, line);
}
FCALLSCSUB4(PPM_abort_default_f,PPM_ABORT_DEFAULT,ppm_abort_default,
PVOID,STRING,STRING,INT)
/* this must be the last piece of code in the file because we
* redefine a cfortran.h internal here, to allow calls to Fortran
* function pointers */
#undef CFC_
#define CFC_(UN,LN) (UN)
#undef CFextern
#define CFextern typedef
PROTOCCALLSFSUB4(*PPM_fortran_abort_func,,PVOID,STRING,STRING,INT)
#undef CFextern
#define CFextern static
static PPM_fortran_abort_func abort_ppm_fortran_fp;
static void
set_abort_ppm_handler_f(void *abort_ppm_handler)
{
abort_ppm_fortran_fp = (PPM_fortran_abort_func)abort_ppm_handler;
PPM_abort = abort_ppm_handler_wrapper;
}
static void
abort_ppm_handler_wrapper(MPI_Comm comm, const char msg[],
const char source[], int line)
{
#if defined(USE_MPI)
int flag = 0;
MPI_Fint comm_f = (MPI_Initialized(&flag) == MPI_SUCCESS && flag)?
MPI_Comm_c2f(comm):(MPI_Fint)0;
#else
MPI_Fint comm_f = comm;
#endif
/* cfortran.h does not understand const char * */
char *msg_arg = (char *)msg, *source_arg = (char *)source;
#undef CPPPROTOCLSFSUB14
#define CPPPROTOCLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE)
CCALLSFSUB4(*abort_ppm_fortran_fp,,PVOID,STRING,STRING,INT,
&comm_f, msg_arg, source_arg, line);
}
/*
* Local Variables:
* license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm"
* license-markup: "doxygen"
* license-default: "bsd"
* End:
*/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment