Commit 456b73f2 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Generalize library core function naming to facilitate re-use.

* By simply defining another prefix in symprefix.h, symbols with another
  prefix will be generated.
parent e534fea0
......@@ -34,6 +34,7 @@ EXTRA_DIST=xpfpa.h xpfpa_func.h cfortran.h
coreincludedir = $(includedir)/core
coreinclude_HEADERS=core/core.h \
core/symprefix.h \
core/ppm_combinatorics.h \
core/ppm_extents.h \
core/ppm_random.h
\ No newline at end of file
core/ppm_random.h
../../src/core/symprefix.h
\ No newline at end of file
......@@ -56,6 +56,7 @@ libscalesppm_a_SOURCES=ppm/scales_ppm.f90 \
solver/solver_all.f90 \
\
core/core.c core/core.h core/core_cf.c \
core/symprefix.h \
core/ppm_statistics.f90 \
core/ppm_combinatorics.f90 core/ppm_combinatorics.h \
core/ppm_combinatorics_c.c core/ppm_combinatorics_fwrap.c \
......
......@@ -55,29 +55,32 @@
#endif
#include <stdio.h>
#include <cfortran.h>
#include "core.h"
#include "symprefix.h"
MPI_Comm PPM_default_comm = MPI_COMM_WORLD;
MPI_Comm SymPrefix(default_comm) = MPI_COMM_WORLD;
static void
PPM_set_default_comm_f(MPI_Fint *comm_f)
SymPrefix(set_default_comm_f)(MPI_Fint *comm_f)
{
#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;
MPI_Comm_f2c(*comm_f):SymPrefix(default_comm);
#else
MPI_Comm comm_c = *comm_f;
#endif
PPM_default_comm = comm_c;
SymPrefix(default_comm) = comm_c;
}
FCALLSCSUB1(PPM_set_default_comm_f, PPM_SET_DEFAULT_COMM,
ppm_set_default_comm, PVOID)
FCALLSCSUB1(SymPrefix(set_default_comm_f), SYMPREFIX(SET_DEFAULT_COMM),
symprefix(set_default_comm), PVOID)
static void
PPM_abort_f(MPI_Fint *comm_f, const char *msg, const char *source, int line)
SymPrefix(abort_f)(MPI_Fint *comm_f, const char *msg,
const char *source, int line)
{
MPI_Comm comm_c;
#if defined(USE_MPI)
......@@ -87,14 +90,14 @@ PPM_abort_f(MPI_Fint *comm_f, const char *msg, const char *source, int line)
#else
comm_c = *comm_f;
#endif
PPM_abort(comm_c, msg, source, line);
SymPrefix(abort)(comm_c, msg, source, line);
}
FCALLSCSUB4(PPM_abort_f, PPM_ABORT, ppm_abort, PVOID, STRING,
STRING, INT)
FCALLSCSUB4(SymPrefix(abort_f), SYMPREFIX(ABORT), symprefix(abort),
PVOID, STRING, STRING, INT)
void
PPM_abort_default(MPI_Comm comm, const char *msg, const char *source, int line)
SymPrefix(abort_default)(MPI_Comm comm, const char *msg, const char *source, int line)
{
int flag = 0;
fprintf(stderr, "Fatal error in %s, line %d: %s\n", source, line, msg);
......@@ -108,16 +111,17 @@ PPM_abort_default(MPI_Comm comm, const char *msg, const char *source, int line)
#endif
}
PPM_abort_func PPM_abort = PPM_abort_default;
SymPrefix(abort_func) SymPrefix(abort) = SymPrefix(abort_default);
void
PPM_restore_default_abort_handler()
SymPrefix(restore_default_abort_handler)()
{
PPM_abort = PPM_abort_default;
SymPrefix(abort) = SymPrefix(abort_default);
}
FCALLSCSUB0(PPM_restore_default_abort_handler, PPM_RESTORE_DEFAULT_ABORT_HNDL,
ppm_restore_default_abort_hndl)
FCALLSCSUB0(SymPrefix(restore_default_abort_handler),
SYMPREFIX(RESTORE_DEFAULT_ABORT_HNDL),
symprefix(restore_default_abort_hndl))
/*
* Local Variables:
......
......@@ -75,20 +75,22 @@ enum {
};
#endif
#include "core/symprefix.h"
/**
* functions used as error handler must conform to this interface
*/
typedef void (*PPM_abort_func)(MPI_Comm comm, const char *msg,
const char *source, int line);
typedef void (*SymPrefix(abort_func))(MPI_Comm comm, const char *msg,
const char *source, int line);
/**
* Unless modified, this function pointer will reference PPM_abort_default.
*/
extern PPM_abort_func PPM_abort;
extern SymPrefix(abort_func) SymPrefix(abort);
/**
* communicator object to use by default
*/
extern MPI_Comm PPM_default_comm;
extern MPI_Comm SymPrefix(default_comm);
/**
* This function
......@@ -102,19 +104,20 @@ extern MPI_Comm PPM_default_comm;
* @param line line number of caller
*/
extern void
PPM_abort_default(MPI_Comm comm, const char *msg,
const char *source, int line);
SymPrefix(abort_default)(MPI_Comm comm, const char *msg,
const char *source, int line);
/**
* change default communicator object
*/
extern void
PPM_set_default_comm(MPI_Comm comm);
SymPrefix(set_default_comm)(MPI_Comm comm);
#endif
/*
* Local Variables:
* license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm"
* license-default: "bsd"
* license-markup: "doxygen"
* End:
*/
......@@ -45,10 +45,10 @@
#include <cfortran.h>
#include "core.h"
PROTOCCALLSFSUB1(PPM_SET_DEFAULT_COMM_F, ppm_set_default_comm_f, INT)
PROTOCCALLSFSUB1(SYMPREFIX(SET_DEFAULT_COMM_F), ppm_set_default_comm_f, INT)
void
PPM_set_default_comm(MPI_Comm comm)
SYMPREFIX(set_default_comm)(MPI_Comm comm)
{
MPI_Fint comm_f;
#if defined(USE_MPI)
......@@ -56,10 +56,10 @@ PPM_set_default_comm(MPI_Comm comm)
#else
comm_f = comm;
#endif
PPM_default_comm = comm;
SYMPREFIX(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);
CCALLSFSUB1(SYMPREFIX(SET_DEFAULT_COMM_F), ppm_set_default_comm_f, INT, comm_f);
}
static void
......@@ -69,24 +69,24 @@ abort_ppm_handler_wrapper(MPI_Comm comm, const char msg[],
static void
set_abort_ppm_handler_f(void *abort_ppm_handler);
FCALLSCSUB1(set_abort_ppm_handler_f, PPM_SET_ABORT_HANDLER,
FCALLSCSUB1(set_abort_ppm_handler_f, SYMPREFIX(SET_ABORT_HANDLER),
ppm_set_abort_handler, ROUTINE)
static void
PPM_abort_default_f(MPI_Fint *comm_f, const char *msg, const char *source,
SYMPREFIX(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;
MPI_Comm_f2c(*comm_f):SYMPREFIX(default_comm);
#else
MPI_Comm comm_c = *comm_f;
#endif
PPM_abort_default(comm_c, msg, source, line);
SYMPREFIX(abort_default)(comm_c, msg, source, line);
}
FCALLSCSUB4(PPM_abort_default_f,PPM_ABORT_DEFAULT,ppm_abort_default,
FCALLSCSUB4(SYMPREFIX(abort_default_f),SYMPREFIX(ABORT_DEFAULT),ppm_abort_default,
PVOID,STRING,STRING,INT)
/* this must be the last piece of code in the file because we
......@@ -96,17 +96,17 @@ FCALLSCSUB4(PPM_abort_default_f,PPM_ABORT_DEFAULT,ppm_abort_default,
#define CFC_(UN,LN) (UN)
#undef CFextern
#define CFextern typedef
PROTOCCALLSFSUB4(*PPM_fortran_abort_func,,PVOID,STRING,STRING,INT)
PROTOCCALLSFSUB4(*SYMPREFIX(fortran_abort_func),,PVOID,STRING,STRING,INT)
#undef CFextern
#define CFextern static
static PPM_fortran_abort_func abort_ppm_fortran_fp;
static SYMPREFIX(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;
abort_ppm_fortran_fp = (SYMPREFIX(fortran_abort_func))abort_ppm_handler;
SYMPREFIX(abort) = abort_ppm_handler_wrapper;
}
static void
......
/**
* @file symprefix.h
* @brief Define library-specific symbol prefix macros
*
* @copyright Copyright (C) 2012 Thomas Jahns <jahns@dkrz.de>
*
* @version 1.0
* @author Thomas Jahns <jahns@dkrz.de>
*/
/*
* Keywords:
* 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.
*/
#ifndef SYMPREFIX_H
#define SYMPREFIX_H
/* All upper case fortran names */
#define SYMPREFIX(symbol) PPM_##symbol
/* Mixed case C names */
#define SymPrefix(symbol) PPM_##symbol
/* All lower case fortran names */
#define symprefix(symbol) ppm_##symbol
#endif
/*
* Local Variables:
* license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm"
* license-default: "bsd"
* license-markup: "doxygen"
* 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