Skip to content

Commit

Permalink
Merge pull request ESMCI#1393 from NCAR/ejh_pioperformance
Browse files Browse the repository at this point in the history
First pass at building pioperformance with autotools and externally installed GPTL
  • Loading branch information
edhartnett authored Apr 9, 2019
2 parents a936f8f + cce2306 commit 63717b2
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 2 deletions.
52 changes: 52 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ if test "x$enable_logging" = xyes; then
AC_DEFINE([PIO_ENABLE_LOGGING], 1, [If true, turn on logging.])
fi

# Does the user want to enable timing?
AC_MSG_CHECKING([whether GPTL timing library is used])
AC_ARG_ENABLE([timing],
[AS_HELP_STRING([--enable-timing],
[enable use of the GPTL timing library.])])
test "x$enable_timing" = xyes || enable_timing=no
AC_MSG_RESULT([$enable_timing])
if test "x$enable_timing" = xyes; then
AC_DEFINE([TIMING], 1, [If true, use GPTL timing library.])
fi
AM_CONDITIONAL(USE_GPTL, [test "x$enable_timing" = xyes])

# Does the user want to enable Fortran library?
AC_MSG_CHECKING([whether Fortran library should be build])
AC_ARG_ENABLE([fortran],
Expand Down Expand Up @@ -148,6 +160,44 @@ fi
#AC_CHECK_SIZEOF([MPI_Offset], [], [[#include <mpi.h>]])
#AC_DEFINE([SIZEOF_MPI_OFFSET], [8], [netCDF classic library available])

# If we want the timing library, we must find it.
if test "x$enable_timing" = xyes; then
AC_CHECK_HEADERS([gptl.h])
AC_CHECK_LIB([gptl], [GPTLinitialize], [],
[AC_MSG_ERROR([Can't find or link to the GPTL library.])])
if test "x$enable_fortran" = xyes; then
AC_LANG_PUSH([Fortran])
# AC_CHECK_HEADERS([gptl.inc])
AC_CHECK_LIB([gptlf], [gptlstart], [],
[AC_MSG_ERROR([Can't find or link to the GPTL Fortran library.])])
AC_LANG_POP([Fortran])
fi

# Check for papi library.
AC_CHECK_LIB([papi], [PAPI_library_init])
AC_MSG_CHECKING([whether system can support PAPI])
have_papi=no
if test "x$ac_cv_lib_papi_PAPI_library_init" = xyes; then
# If we have PAPI library, check /proc/sys/kernel/perf_event_paranoid
# to see if we have permissions.
if test -f /proc/sys/kernel/perf_event_paranoid; then
if test `cat /proc/sys/kernel/perf_event_paranoid` != 1; then
AC_MSG_ERROR([PAPI library found, but /proc/sys/kernel/perf_event_paranoid != 1
try sudo sh -c 'echo 1 >/proc/sys/kernel/perf_event_paranoid'])
fi
fi
AC_DEFINE([HAVE_PAPI], [1], [PAPI library is present and usable])
have_papi=yes
fi
AC_MSG_RESULT($have_papi)

# We must have papi to build pioperformance with timing.
if test "x$have_papi" = xno; then
AC_MSG_ERROR([PAPI library not found, but is required if enable-timing is used.])
fi
fi
AM_CONDITIONAL([HAVE_PAPI], [test "x$have_papi" = xyes])

AC_CONFIG_FILES(src/flib/piodarray.F90:src/flib/piodarray.F90.in2)
AC_CONFIG_FILES(src/flib/pionfatt_mod.F90:src/flib/pionfatt_mod.F90.in2)
AC_CONFIG_FILES(src/flib/pionfget_mod.F90:src/flib/pionfget_mod.F90.in2)
Expand All @@ -165,11 +215,13 @@ AC_OUTPUT(Makefile
src/Makefile
src/clib/Makefile
src/flib/Makefile
src/gptl/Makefile
tests/Makefile
tests/cunit/Makefile
tests/unit/Makefile
tests/general/Makefile
tests/general/util/Makefile
tests/performance/Makefile
doc/Makefile
examples/Makefile
examples/c/Makefile)
6 changes: 5 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ if BUILD_FORTRAN
FLIB = flib
endif

SUBDIRS = clib $(FLIB)
if USE_GPTL
GPTL = gptl
endif

SUBDIRS = clib ${GPTL} $(FLIB)

EXTRA_DIST = CMakeLists.txt
23 changes: 23 additions & 0 deletions src/gptl/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This is part of PIO. It creates the Makefile for the GPTL directory.

# Ed Hartnett 4/9/19

# Turn off parallel builds in this directory.
.NOTPARALLEL:

# Build these uninstalled convenience libraries.
noinst_LTLIBRARIES = libperf_utils.la libperf_mod.la

# The convenience libraries depends on their source.
libperf_utils_la_SOURCES = perf_utils.F90
libperf_mod_la_SOURCES = perf_mod.F90 f_wrappers_2.c

# Each mod file depends on the .o file.
perf_utils.mod: perf_utils.$(OBJEXT)
perf_mod.mod: perf_mod.$(OBJEXT)

# Does the user want to build fortran?
#if BUILD_FORTRAN
#endif

EXTRA_DIST = CMakeLists.txt
182 changes: 182 additions & 0 deletions src/gptl/f_wrappers_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
** Fortran wrappers for timing library routines
*/

#include <string.h>
#include <stdlib.h>
#include "private.h" /* MAX_CHARS, bool */
#include "gptl.h" /* function prototypes and HAVE_MPI logic*/

#define gptlevent_name_to_code gptlevent_name_to_code_
#define gptlevent_code_to_name gptlevent_code_to_name_
#define gptlpr_set_append gptlpr_set_append_
#define gptlpr_query_append gptlpr_query_append_
#define gptlpr_set_write gptlpr_set_write_
#define gptlpr_query_write gptlpr_query_write_

/*
** Local function prototypes
*/

int gptlpr_set_append (void);
int gptlpr_query_append (void);
int gptlpr_set_write (void);
int gptlpr_query_write (void);
static int pr_append;

#ifdef HAVE_PAPI
/* int gptl_papilibraryinit (void); */
int gptlevent_name_to_code (const char *str, int *code, int nc);
int gptlevent_code_to_name (int *code, char *str, int nc);

/** GPTL_PAPIlibraryinit: Call PAPI_library_init if necessary
**
** Return value: 0 (success) or GPTLerror (failure)
*/

int GPTL_PAPIlibraryinit ()
{
int ret;

if ((ret = PAPI_is_initialized ()) == PAPI_NOT_INITED) {
if ((ret = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) {
fprintf (stderr, "GPTL_PAPIlibraryinit: ret=%d PAPI_VER_CURRENT=%d\n",
ret, (int) PAPI_VER_CURRENT);
return GPTLerror ("GPTL_PAPIlibraryinit: PAPI_library_init failure:%s\n",
PAPI_strerror (ret));
}
}
return 0;
}

#endif

/*
** GPTLpr_set_append: set GPTLpr_file and GPTLpr_summary_file
** to use append mode
*/

int GPTLpr_set_append (void)
{
pr_append = true;
return 0;
}

/*
** GPTLpr_query_append: query whether GPTLpr_file and GPTLpr_summary_file
** use append mode
*/

int GPTLpr_query_append (void)
{
if (pr_append)
return 1;
else
return 0;
}

/*
** GPTLpr_set_write: set GPTLpr_file and GPTLpr_summary_file
** to use write mode
*/

int GPTLpr_set_write (void)
{
pr_append = false;
return 0;
}

/*
** GPTLpr_query_write: query whether GPTLpr_file and GPTLpr_summary_file
** use write mode
*/

int GPTLpr_query_write (void)
{
if (pr_append)
return 0;
else
return 1;
}


/*
** Fortran wrapper functions start here
*/

int gptlpr_set_append (void)
{
return GPTLpr_set_append ();
}

int gptlpr_query_append (void)
{
return GPTLpr_set_append ();
}

int gptlpr_set_write (void)
{
return GPTLpr_set_append ();
}

int gptlpr_query_write (void)
{
return GPTLpr_set_append ();
}

#ifdef HAVE_PAPI
#include <papi.h>

int gptl_papilibraryinit (void)
{
return GPTL_PAPIlibraryinit ();
}

int gptlevent_name_to_code (const char *str, int *code, int nc)
{
char cname[PAPI_MAX_STR_LEN+1];
int numchars = MIN (nc, PAPI_MAX_STR_LEN);

strncpy (cname, str, numchars);
cname[numchars] = '\0';

/* "code" is an int* and is an output variable */

return GPTLevent_name_to_code (cname, code);
}

int gptlevent_code_to_name (int *code, char *str, int nc)
{
int i;

if (nc < PAPI_MAX_STR_LEN)
return GPTLerror ("gptl_event_code_to_name: output name must hold at least %d characters\n",
PAPI_MAX_STR_LEN);

if (GPTLevent_code_to_name (*code, str) == 0) {
for (i = strlen(str); i < nc; ++i)
str[i] = ' ';
} else {
return GPTLerror ("");
}
return 0;
}

#else

int gptl_papilibraryinit (void)
{
return 0;
}

int gptlevent_name_to_code (const char *str, int *code, int nc)
{
return GPTLevent_name_to_code (str, code);
}

int gptlevent_code_to_name (const int *code, char *str, int nc)
{
return GPTLevent_code_to_name (*code, str);
}

#endif
5 changes: 4 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
if BUILD_FORTRAN
UNIT = unit
GENERAL = general
if USE_GPTL
PERFORMANCE = performance
endif
endif

SUBDIRS = cunit ${UNIT} ${GENERAL}
SUBDIRS = cunit ${UNIT} ${GENERAL} ${PERFORMANCE}

EXTRA_DIST = CMakeLists.txt
36 changes: 36 additions & 0 deletions tests/performance/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## This is the automake file for building the Fortran performance
## tests for the PIO library.

# Ed Hartnett 4/6/19

# Parallel builds don't currently work in this directory.
.NOTPARALLEL:

# Put together AM_CPPFLAGS and AM_LDFLAGS.
include $(top_srcdir)/set_flags.am

# Link to test util library and PIO Fortran and C libs.
LDADD = $(top_builddir)/src/gptl/libperf_mod.la \
$(top_builddir)/src/gptl/libperf_utils.la \
${top_builddir}/tests/general/libpio_tutil.la \
${top_builddir}/src/flib/libpiof.la \
${top_builddir}/src/clib/libpio.la

# Find perf_mod and perf_util.
AM_CPPFLAGS += -I$(top_builddir)/src/gptl

# Find pio_tutil.mod
AM_CPPFLAGS += -I$(top_builddir)/tests/general

# Build the test for make check.
check_PROGRAMS = pioperformance

pioperformance_SOURCES = pioperformance.F90

# Tests will run from a bash script.
#TESTS = run_tests.sh

EXTRA_DIST = CMakeLists.txt gensimple.pl

# Clean up files produced during testing.
CLEANFILES = *.nc *.log *.mod

0 comments on commit 63717b2

Please sign in to comment.