Skip to content

Commit

Permalink
Merge pull request ESMCI#1395 from NCAR/ejh_perf_doc
Browse files Browse the repository at this point in the history
More work on pioperformance in autotools build, plus some documentation
  • Loading branch information
edhartnett authored Apr 11, 2019
2 parents 94e2405 + 8976ba8 commit a29460e
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 89 deletions.
42 changes: 23 additions & 19 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
## Ed Hartnett 8/16/17

# Initialize autoconf and automake.
AC_INIT(pio, 2.4.1)
AC_INIT(pio, 2.4.2-development)
AC_CONFIG_SRCDIR(src/clib/pio_darray.c)
AM_INIT_AUTOMAKE([foreign serial-tests])

# The PIO version, again.
AC_DEFINE([PIO_VERSION_MAJOR], [2], [PIO major version])
AC_DEFINE([PIO_VERSION_MINOR], [4], [PIO minor version])
AC_DEFINE([PIO_VERSION_PATCH], [1], [PIO patch version])
AC_DEFINE([PIO_VERSION_PATCH], [2], [PIO patch version])

# Once more for the documentation.
AC_SUBST([VERSION_MAJOR], [2])
AC_SUBST([VERSION_MINOR], [4])
AC_SUBST([VERSION_PATCH], [1])
AC_SUBST([VERSION_PATCH], [2])

# The m4 directory holds macros for autoconf.
AC_CONFIG_MACRO_DIR([m4])
Expand Down Expand Up @@ -63,8 +63,15 @@ if test "x$enable_timing" = xyes; then
fi
AM_CONDITIONAL(USE_GPTL, [test "x$enable_timing" = xyes])

# Does the user want to disable papi?
AC_MSG_CHECKING([whether PAPI should be enabled (if enable-timing is used)])
AC_ARG_ENABLE([papi], [AS_HELP_STRING([--disable-papi],
[disable PAPI library use])])
test "x$enable_papi" = xno || enable_papi=yes
AC_MSG_RESULT($enable_papi)

# Does the user want to enable Fortran library?
AC_MSG_CHECKING([whether Fortran library should be build])
AC_MSG_CHECKING([whether Fortran library should be built])
AC_ARG_ENABLE([fortran],
[AS_HELP_STRING([--enable-fortran],
[build the PIO Fortran library.])])
Expand Down Expand Up @@ -92,7 +99,7 @@ AM_CONDITIONAL(BUILD_DOCS, [test "x$enable_docs" = xyes])

# Is doxygen installed?
AC_CHECK_PROGS([DOXYGEN], [doxygen])
if test -z "$DOXYGEN" -a test "x$enable_docs" = xyes; then
if test -z "$DOXYGEN" -a "x$enable_docs" = xyes; then
AC_MSG_ERROR([Doxygen not found but --enable-docs used.])
fi

Expand Down Expand Up @@ -177,24 +184,21 @@ if test "x$enable_timing" = xyes; then
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'])
if test $enable_papi = yes; then
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_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])

Expand Down
2 changes: 1 addition & 1 deletion src/gptl/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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
libperf_mod_la_SOURCES = perf_mod.F90 f_wrappers_2.c private.h

# Each mod file depends on the .o file.
perf_utils.mod: perf_utils.$(OBJEXT)
Expand Down
111 changes: 57 additions & 54 deletions src/gptl/f_wrappers_2.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*
** Fortran wrappers for timing library routines
** Fortran wrappers for timing library routines that are not in GPTL.
* Ed Hartnett 4/9/19
*/

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

#define gptlevent_name_to_code gptlevent_name_to_code_
#define gptlevent_code_to_name gptlevent_code_to_name_
Expand All @@ -30,23 +34,23 @@ 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)
*/
**
** 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));
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;
return 0;
}

#endif
Expand All @@ -58,8 +62,8 @@ int GPTL_PAPIlibraryinit ()

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

/*
Expand All @@ -69,10 +73,10 @@ int GPTLpr_set_append (void)

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

/*
Expand All @@ -82,8 +86,8 @@ int GPTLpr_query_append (void)

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

/*
Expand All @@ -93,10 +97,10 @@ int GPTLpr_set_write (void)

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


Expand All @@ -106,77 +110,76 @@ int GPTLpr_query_write (void)

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

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

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

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

#ifdef HAVE_PAPI
#include <papi.h>

int gptl_papilibraryinit (void)
{
return GPTL_PAPIlibraryinit ();
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);
char cname[PAPI_MAX_STR_LEN+1];
int numchars = MIN (nc, PAPI_MAX_STR_LEN);

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

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

return GPTLevent_name_to_code (cname, code);
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;

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) {
int i;
for (i = strlen(str); i < nc; ++i)
str[i] = ' ';
} else {
return GPTLerror ("");
}
return 0;
}

#else

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

int gptlevent_name_to_code (const char *str, int *code, int nc)
{
return GPTLevent_name_to_code (str, code);
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);
return GPTLevent_code_to_name (*code, str);
}

#endif
18 changes: 9 additions & 9 deletions src/gptl/perf_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -913,12 +913,12 @@ subroutine t_prf(filename, mpicom, num_outpe, stride_outpe, &
unitn = shr_file_getUnit()

! determine what the current output mode is (append or write)
if (GPTLpr_query_write() == 1) then
pr_write = .true.
ierr = GPTLpr_set_append()
else
pr_write=.false.
endif
! if (GPTLpr_query_write() == 1) then
! pr_write = .true.
! ierr = GPTLpr_set_append()
! else
pr_write=.false.
! endif

! Determine whether to write all data to a single fie
if (present(single_file)) then
Expand Down Expand Up @@ -1100,9 +1100,9 @@ subroutine t_prf(filename, mpicom, num_outpe, stride_outpe, &
call shr_file_freeUnit( unitn )

! reset GPTL output mode
if (pr_write) then
ierr = GPTLpr_set_write()
endif
! if (pr_write) then
! ierr = GPTLpr_set_write()
! endif

!$OMP END MASTER
call t_stopf("t_prf")
Expand Down
9 changes: 5 additions & 4 deletions tests/performance/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ AM_CPPFLAGS += -I$(top_builddir)/src/gptl
AM_CPPFLAGS += -I$(top_builddir)/tests/general

# Build the test for make check.
check_PROGRAMS = pioperformance
check_PROGRAMS = pioperf

pioperformance_SOURCES = pioperformance.F90
pioperf_SOURCES = pioperformance.F90

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

EXTRA_DIST = CMakeLists.txt gensimple.pl
EXTRA_DIST = CMakeLists.txt gensimple.pl Pioperformance.md pioperf.nl \
run_tests.sh

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

0 comments on commit a29460e

Please sign in to comment.