From 034d0ebcb593ec613bcc83fe65af17d937a68787 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Fri, 9 Jan 2004 08:30:19 +0000 Subject: [PATCH] Add support for profiling, both via weak symbols and separate compilation. This commit was SVN r164. --- src/mpi/interface/c/Makefile.am | 7 +-- src/mpi/interface/c/bindings.h | 25 +++++++++ src/mpi/interface/c/comm_set_name.c | 4 +- src/mpi/interface/c/profile/Makefile.am | 6 ++- src/mpi/interface/c/profile/defines.h | 20 ++++++++ src/mpi/interface/c/profiling.h | 25 --------- src/mpi/interface/f77/Makefile.am | 7 +-- src/mpi/interface/f77/bindings.h | 46 +++++++++++++++++ src/mpi/interface/f77/comm_set_name_f.c | 30 ++++------- src/mpi/interface/f77/defines.h | 50 ++++++++++++++++++ src/mpi/interface/f77/profile/Makefile.am | 6 ++- src/mpi/interface/f77/profile/defines.h | 48 ++++++++++++++++++ src/mpi/interface/f77/profile/prototypes.h | 54 ++++++++++++++++++++ src/mpi/interface/f77/profiling.h | 34 ------------- src/mpi/interface/f77/prototypes.h | 59 ++++++++++++++++++++++ 15 files changed, 329 insertions(+), 92 deletions(-) create mode 100644 src/mpi/interface/c/bindings.h create mode 100644 src/mpi/interface/c/profile/defines.h delete mode 100644 src/mpi/interface/c/profiling.h create mode 100644 src/mpi/interface/f77/bindings.h create mode 100644 src/mpi/interface/f77/defines.h create mode 100644 src/mpi/interface/f77/profile/defines.h create mode 100644 src/mpi/interface/f77/profile/prototypes.h delete mode 100644 src/mpi/interface/f77/profiling.h create mode 100644 src/mpi/interface/f77/prototypes.h diff --git a/src/mpi/interface/c/Makefile.am b/src/mpi/interface/c/Makefile.am index b6245de0b1..b60312ea43 100644 --- a/src/mpi/interface/c/Makefile.am +++ b/src/mpi/interface/c/Makefile.am @@ -22,9 +22,10 @@ DIST_SUBDIRS = profile noinst_LTLIBRARIES = libmpi_c.la libmpi_c_la_SOURCES = \ + bindings.h \ + bindings_profiling.h \ comm_get_name.c \ comm_set_name.c \ - datatype_get_name.c \ - datatype_set_name.c \ - profiling.h + init.c \ + finalize.c \ libmpi_c_la_LIBADD = $(profile_lib) diff --git a/src/mpi/interface/c/bindings.h b/src/mpi/interface/c/bindings.h new file mode 100644 index 0000000000..1dd5e9686e --- /dev/null +++ b/src/mpi/interface/c/bindings.h @@ -0,0 +1,25 @@ +/* + * $HEADER$ + */ + +#ifndef LAM_C_BINDINGS_H +#define LAM_C_BINDINGS_H + +#include "lam_config.h" +#include "mpi.h" + +#ifndef LAM_PROFILING_DEFINES +#define LAM_PROFILING_DEFINES 0 +#endif + +/* If compiling in the profile directory, then we don't have weak + symbols and therefore we need the defines to map from MPI->PMPI. + NOTE: pragma weak stuff is handled on a file-by-file basis; it + doesn't work to simply list all of the pragmas in a top-level + header file. */ + +#if LAM_PROFILING_DEFINES +#include "mpi/c/profile/defines.h" +#endif + +#endif /* LAM_C_BINDINGS_H */ diff --git a/src/mpi/interface/c/comm_set_name.c b/src/mpi/interface/c/comm_set_name.c index 953c647bd2..c47f0fbbba 100644 --- a/src/mpi/interface/c/comm_set_name.c +++ b/src/mpi/interface/c/comm_set_name.c @@ -6,8 +6,7 @@ #include -#include "mpi.h" -#include "mpi/c/profiling.h" +#include "mpi/c/bindings.h" #include "lam/util/strncpy.h" #include "communicator.h" #include "totalview.h" @@ -16,6 +15,7 @@ #pragma weak PMPI_Comm_set_name = MPI_Comm_set_name #endif + int MPI_Comm_set_name(MPI_Comm comm, char *name) { diff --git a/src/mpi/interface/c/profile/Makefile.am b/src/mpi/interface/c/profile/Makefile.am index 9954cf4fa6..5a81c79377 100644 --- a/src/mpi/interface/c/profile/Makefile.am +++ b/src/mpi/interface/c/profile/Makefile.am @@ -9,11 +9,13 @@ AM_CPPFLAGS = -DLAM_PROFILING_DEFINES=1 noinst_LTLIBRARIES = libmpi_c_profile.la +noinst_HEADERS = defines.h + nodist_libmpi_c_profile_la_SOURCES= \ pcomm_get_name.c \ pcomm_set_name.c \ - pdatatype_get_name.c \ - pdatatype_set_name.c + pinit.c \ + pfinalize.c # Sym link in the sources from the real MPI directory diff --git a/src/mpi/interface/c/profile/defines.h b/src/mpi/interface/c/profile/defines.h new file mode 100644 index 0000000000..80ecbea62c --- /dev/null +++ b/src/mpi/interface/c/profile/defines.h @@ -0,0 +1,20 @@ +/* + * $HEADER$ + */ + +#ifndef LAM_C_PROFILE_DEFINES_H +#define LAM_C_PROFILE_DEFINES_H + +/* + * This file contains the #defines for the profiled versions of all + * the MPI C bindings. It is only included if we do not have weak + * symbols, or weak symbol support was explicitly disabled. + */ + +#if LAM_PROFILING_DEFINES +#define MPI_Comm_set_name PMPI_Comm_set_name +#define MPI_Init PMPI_Init +#define MPI_Finalize PMPI_Finalize +#endif + +#endif /* LAM_C_PROFILE_DEFINES_H */ diff --git a/src/mpi/interface/c/profiling.h b/src/mpi/interface/c/profiling.h deleted file mode 100644 index 54fdbda24f..0000000000 --- a/src/mpi/interface/c/profiling.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * $HEADER$ - */ - -#ifndef LAM_MPI_C_PROFILING_H -#define LAM_MPI_C_PROFILING_H - -#include "lam_config.h" - -/* Unless explicitly asked for (i.e., when we're compiling in - src/mpi//profile, don't automatically convert MPI_Foo -> - PMPI_Foo via #defines. */ - -#ifndef LAM_PROFILING_DEFINES -#define LAM_PROFILING_DEFINES 0 -#endif - -/* If requested, add a #define for each MPI function to convert it to - it's PMPI equivalent. */ - -#if LAM_PROFILING_DEFINES -#define MPI_Comm_set_name PMPI_Comm_set_name -#endif - -#endif /* LAM_MPI_C_PROFILING_H */ diff --git a/src/mpi/interface/f77/Makefile.am b/src/mpi/interface/f77/Makefile.am index 3495feaee8..7e6bbaf0e2 100644 --- a/src/mpi/interface/f77/Makefile.am +++ b/src/mpi/interface/f77/Makefile.am @@ -22,10 +22,11 @@ DIST_SUBDIRS = profile noinst_LTLIBRARIES = libmpi_f77.la libmpi_f77_la_SOURCES = \ + bindings.h \ comm_get_name_f.c \ comm_set_name_f.c \ - datatype_get_name_f.c \ - datatype_set_name_f.c \ - profiling.h + init_f.c \ + finalize_f.c \ + prototypes.h libmpi_f77_la_LIBADD = $(profile_lib) diff --git a/src/mpi/interface/f77/bindings.h b/src/mpi/interface/f77/bindings.h new file mode 100644 index 0000000000..760c6486b8 --- /dev/null +++ b/src/mpi/interface/f77/bindings.h @@ -0,0 +1,46 @@ +/* + * $HEADER$ + */ + +#ifndef LAM_F77_BINDINGS_H +#define LAM_F77_BINDINGS_H + +#include "lam_config.h" +#include "mpi.h" + +/* + * If we have no weak symbols, then get the #defines to map from the + * LAM-native mpi_foo_f function to the profiled or non-profiled + * function name in the right fortran external symbol convention. + * Yes, kids, that's one of 8 possible sets of #define's. :-\ + */ + +#include "mpi/f77/prototypes.h" + +#if LAM_HAVE_WEAK_SYMBOLS +/* If we have weak symbols, then we compile the functions as the + LAM-native mpi_foo_f and use the weak symbols to create the + aliases. We include the prototypes for the profiled versions of + the MPI functions here because some compilers won't generate weak + symbols unless the real symbols are at least prototyped. We only + include the profiled prototypes if we're doing weak symbols because + the profiled prototypes are generated with #defines that map + mpi->pmpi and MPI->PMPI, which screws up the non-weak-symbols stuff + (because they have their own #defines). */ +#include "mpi/f77/profile/prototypes.h" +#else +/* We don't have weak symbols. */ +#if LAM_PROFILING_DEFINES +/* If we're compiling in the profile/ directory, then + LAM_PROFILING_DEFINES will be 1. In this case, get the defines + mapping from mpi_foo_f to the profiling name in the proper symbol + convention. */ +#include "mpi/f77/profile/defines.h" +#else +/* Otherwise, we're compiling in the main directory, so get the + defines mapping from mpi_foo_f to the proper symbol convention. */ +#include "mpi/f77/defines.h" +#endif +#endif + +#endif /* LAM_F77_BINDINGS_H */ diff --git a/src/mpi/interface/f77/comm_set_name_f.c b/src/mpi/interface/f77/comm_set_name_f.c index ec3b738fa1..3c099dc508 100644 --- a/src/mpi/interface/f77/comm_set_name_f.c +++ b/src/mpi/interface/f77/comm_set_name_f.c @@ -4,41 +4,29 @@ #include "lam_config.h" -#include - #include "mpi.h" -#if 0 -/* JMS Need to continue here */ -#include "mpi/f77/profiling.h" -#endif +#include "mpi/f77/bindings.h" #if LAM_HAVE_WEAK_SYMBOLS -#include "mpi/f77/weak_prototypes.h" +#pragma weak MPI_COMM_SET_NAME = mpi_comm_set_name_f +#pragma weak mpi_comm_set_name = mpi_comm_set_name_f #pragma weak mpi_comm_set_name_ = mpi_comm_set_name_f #pragma weak mpi_comm_set_name__ = mpi_comm_set_name_f -#pragma weak mpi_comm_set_name = mpi_comm_set_name_f -#pragma weak MPI_COMM_SET_NAME = mpi_comm_set_name_f - #if LAM_WANT_MPI_PROFILING +#pragma weak PMPI_COMM_SET_NAME = mpi_comm_set_name_f +#pragma weak pmpi_comm_set_name = mpi_comm_set_name_f #pragma weak pmpi_comm_set_name_ = mpi_comm_set_name_f #pragma weak pmpi_comm_set_name__ = mpi_comm_set_name_f -#pragma weak pmpi_comm_set_name = mpi_comm_set_name_f -#pragma weak PMPI_COMM_SET_NAME = mpi_comm_set_name_f - -#endif -#else -#if 0 -/* JMS Need to continue here */ -//#include "mpi-fortran-" #endif #endif -int -mpi_comm_set_name_f(int *comm, char *name) + +void +mpi_comm_set_name_f(int *comm, char *name, int *ierror, int charlen) { /* JMS: Translate comm from int to MPI_Comm */ MPI_Comm c_comm = MPI_COMM_WORLD; - return MPI_Comm_set_name(c_comm, name); + *ierror = MPI_Comm_set_name(c_comm, name); } diff --git a/src/mpi/interface/f77/defines.h b/src/mpi/interface/f77/defines.h new file mode 100644 index 0000000000..2d6fb624cc --- /dev/null +++ b/src/mpi/interface/f77/defines.h @@ -0,0 +1,50 @@ +/* + * $HEADER$ + */ + +#ifndef LAM_F77_DEFINES_H +#define LAM_F77_DEFINES_H + +/* + * This file makes a mapping from mpi_foo_f to the proper fortran + * external symbol convention via 4 sets of #define's. + * + * This file is never included at the same time as + * mpi/f77/profile/prototypes.h (some of the #define's conflict). + */ + +/* + * First, all caps. + */ +#if LAM_F77_CAPS +#define mpi_comm_set_name_f MPI_COMM_SET_NAME +#define mpi_init_f MPI_INIT +#define mpi_finalize_f MPI_FINALIZE + +/* + * Second, all lower case. + */ +#elif LAM_F77_PLAIN +#define mpi_comm_set_name_f mpi_comm_set_name +#define mpi_init_f mpi_init +#define mpi_finalize_f mpi_finalize + +/* + * Third, one trailing underscore. + */ +#elif LAM_F77_SINGLE_UNDERSCORE +#define mpi_comm_set_name_f mpi_comm_set_name_ +#define mpi_init_f mpi_init_ +#define mpi_finalize_f mpi_finalize_ + +/* + * Fourth, two trailing underscores. + */ +#elif LAM_F77_DOUBLE_UNDERSCORE +#define mpi_comm_set_name_f mpi_comm_set_name__ +#define mpi_init_f mpi_init__ +#define mpi_finalize_f mpi_finalize__ + +#endif + +#endif /* LAM_F77_DEFINES_H */ diff --git a/src/mpi/interface/f77/profile/Makefile.am b/src/mpi/interface/f77/profile/Makefile.am index c82db6884b..a0de42e25e 100644 --- a/src/mpi/interface/f77/profile/Makefile.am +++ b/src/mpi/interface/f77/profile/Makefile.am @@ -9,11 +9,13 @@ AM_CPPFLAGS = -DLAM_PROFILING_DEFINES=1 noinst_LTLIBRARIES = libmpi_f77_profile.la +noinst_HEADERS = defines.h + nodist_libmpi_f77_profile_la_SOURCES= \ pcomm_get_name_f.c \ pcomm_set_name_f.c \ - pdatatype_get_name_f.c \ - pdatatype_set_name_f.c + pinit_f.c \ + pfinalize_f.c # Sym link in the sources from the real MPI directory diff --git a/src/mpi/interface/f77/profile/defines.h b/src/mpi/interface/f77/profile/defines.h new file mode 100644 index 0000000000..4864326647 --- /dev/null +++ b/src/mpi/interface/f77/profile/defines.h @@ -0,0 +1,48 @@ +/* + * $HEADER$ + */ + +#ifndef LAM_F77_PROFILE_DEFINES_H +#define LAM_F77_PROFILE_DEFINES_H + +/* + * This file makes a mapping from mpi_foo_f to the profiled version of + * the proper fortran external symbol convention via 4 sets of + * #define's. + */ + +/* + * First, all caps. + */ +#if LAM_F77_CAPS +#define mpi_comm_set_name_f PMPI_COMM_SET_NAME +#define mpi_init_f PMPI_INIT +#define mpi_finalize_f PMPI_FINALIZE + +/* + * Second, all lower case. + */ +#elif LAM_F77_PLAIN +#define mpi_comm_set_name_f pmpi_comm_set_name +#define mpi_init_f pmpi_init +#define mpi_finalize_f pmpi_finalize + +/* + * Third, one trailing underscore. + */ +#elif LAM_F77_SINGLE_UNDERSCORE +#define mpi_comm_set_name_f pmpi_comm_set_name_ +#define mpi_init_f pmpi_init_ +#define mpi_finalize_f pmpi_finalize_ + +/* + * Fourth, two trailing underscores. + */ +#elif LAM_F77_DOUBLE_UNDERSCORE +#define mpi_comm_set_name_f pmpi_comm_set_name__ +#define mpi_init_f pmpi_init__ +#define mpi_finalize_f pmpi_finalize__ + +#endif + +#endif /* LAM_F77_PROFILE_DEFINES_H */ diff --git a/src/mpi/interface/f77/profile/prototypes.h b/src/mpi/interface/f77/profile/prototypes.h new file mode 100644 index 0000000000..d27090028a --- /dev/null +++ b/src/mpi/interface/f77/profile/prototypes.h @@ -0,0 +1,54 @@ +/* + * $HEADER$ + */ + +#ifndef LAM_F77_PROTOTYPES_PROFILING_H +#define LAM_F77_PROTOTYPES_PROFILING_H + +/* + * This file prototypes all profiled MPI fortran functions in all four + * fortran symbol conventions. It is only included when we need the + * profiling prototypes. + * + * Save some coding (i.e., don't re-specify all the return types and + * function arguments) -- make #define's to make from mpi->pmpi and + * then include mpi/f77/prototypes.h. + * + * This file is never included at the same time as + * mpi/f77/defines.h (some of the #define's conflict). + */ + +/* + * First, all caps. + */ +#define MPI_COMM_SET_NAME PMPI_COMM_SET_NAME +#define MPI_INIT PMPI_INIT +#define MPI_FINALIZE PMPI_FINALIZE + +/* + * Second, all lower case. + */ +#define mpi_comm_set_name pmpi_comm_set_name +#define mpi_init pmpi_init +#define mpi_finalize pmpi_finalize + +/* + * Third, one trailing underscore. + */ +#define mpi_comm_set_name_ pmpi_comm_set_name_ +#define mpi_init_ pmpi_init_ +#define mpi_finalize_ pmpi_finalize_ + +/* + * Fourth, two trailing underscores. + */ +#define mpi_comm_set_name__ pmpi_comm_set_name__ +#define mpi_init__ pmpi_init__ +#define mpi_finalize__ pmpi_finalize__ + +/* + * Now include the real prototypes. Magic. :-) + */ +#include "mpi/f77/prototypes.h" + +#endif /* LAM_F77_PROTOTYPES_PROFILING_H */ diff --git a/src/mpi/interface/f77/profiling.h b/src/mpi/interface/f77/profiling.h deleted file mode 100644 index a3b68be2b0..0000000000 --- a/src/mpi/interface/f77/profiling.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * $HEADER$ - */ - -#ifndef LAM_MPI_F77_PROFILING_H -#define LAM_MPI_F77_PROFILING_H - -#include "lam_config.h" - -/* Unless explicitly asked for (i.e., when we're compiling in - src/mpi//profile, don't automatically convert MPI_Foo -> - PMPI_Foo via #defines. */ - -#ifndef LAM_PROFILING_DEFINES -#define LAM_PROFILING_DEFINES 0 -#endif - -/* If requested, add a #define for each MPI function to convert it to - it's PMPI equivalent. */ - -#if LAM_PROFILING_DEFINES -#if LAM_FORTRAN_CAPS -#define mpi_comm_set_name_f MPI_COMM_SET_NAME -#elif LAM_FORTRAN_NO_UNDERSCORE -#define mpi_comm_set_name_f mpi_comm_set_name -#elif LAM_FORTRAN_SINGLE_UNDERSCORE -#define mpi_comm_set_name_f mpi_comm_set_name_ -#elif LAM_FORTRAN_DOUBLE_UNDERSCORE -#define mpi_comm_set_name_f mpi_comm_set_name__ -#else -#error I do not know how your fortran compiler exports symbols. :-( -#endif - -#endif /* LAM_MPI_F77_PROFILING_H */ diff --git a/src/mpi/interface/f77/prototypes.h b/src/mpi/interface/f77/prototypes.h new file mode 100644 index 0000000000..846fc49675 --- /dev/null +++ b/src/mpi/interface/f77/prototypes.h @@ -0,0 +1,59 @@ +/* + * $HEADER$ + */ + +/* + * THIS FILE IS SPECIAL: IT HAS NOT MULTIPLE-INCLUDE PROTECTION! + * + * It is designed to be included twice: once by mpi/f77/prototypes.h + * to get all the "native" prototypes, then again by + * mpi/f77/profile/prototypes after a bunch of #define's have been + * applied to map mpi->pmpi and MPI->PMPI. + * + * This is necessary to get the profiling prototypes. This is even + * necessary when using weak symbols because some compilers will not + * generate a weak symbol unless the "real" function is at least + * prototyped. + */ + +/* + * This file prototypes all MPI fortran functions in all four fortran + * symbol conventions as well as all the internal "real" LAM wrapper + * functions (different from any of the four fortran symbol + * conventions for clarity, at the cost of more typing for me...). + */ + +/* + * Zeroth, the LAM wrapper functions, with a "_f" suffix. + */ +void mpi_comm_set_name_f(int *comm, char *name, int *ierror, int charlen); +void mpi_init_f(int *ierror); +void mpi_finalize_f(int *ierror); + +/* + * First, all caps. + */ +void MPI_COMM_SET_NAME(int *comm, char *name, int *ierror, int charlen); +void MPI_INIT(void *ierror); +void MPI_FINALIZE(int *ierror); + +/* + * Second, all lower case. + */ +void mpi_comm_set_name(int *comm, char *name, int *ierror, int charlen); +void mpi_init(int *ierror); +void mpi_finalize(int *ierror); + +/* + * Third, one trailing underscore. + */ +void mpi_comm_set_name_(int *comm, char *name, int *ierror, int charlen); +void mpi_init_(int *ierror); +void mpi_finalize_(int *ierror); + +/* + * Fourth, two trailing underscores. + */ +void mpi_comm_set_name__(int *comm, char *name, int *ierror, int charlen); +void mpi_init__(int *ierror); +void mpi_finalize__(int *ierror);