Skip to content

Commit

Permalink
Address MPI tracing issues on Darwin.
Browse files Browse the repository at this point in the history
  • Loading branch information
theurich committed Oct 23, 2023
1 parent 53028df commit 1bed7e4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
16 changes: 12 additions & 4 deletions build/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2022,10 +2022,14 @@ ifeq ($(ESMF_TRACE_BUILD_SHARED),ON)
ESMF_TRACE_LDPRELOAD := $(ESMF_LIBDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX)
ESMF_PRELOADSCRIPT = $(ESMF_LIBDIR)/preload.sh

ifneq ($(ESMF_OS),Darwin)
ESMF_ENV_PRELOAD = LD_PRELOAD
ifeq ($(ESMF_OS),Darwin)
ESMF_ENV_PRELOAD = DYLD_INSERT_LIBRARIES
ESMF_ENV_PRELOAD_DELIMIT = ':'
ESMF_SL_PRELOAD_LIBLINKER = $(ESMF_F90LINKER)
else
ESMF_ENV_PRELOAD = DYLD_INSERT_LIBRARIES
ESMF_ENV_PRELOAD = LD_PRELOAD
ESMF_ENV_PRELOAD_DELIMIT = ' '
ESMF_SL_PRELOAD_LIBLINKER = $(ESMF_SL_LIBLINKER)
endif

# MPI implementations do not pick up LD_PRELOAD
Expand All @@ -2048,7 +2052,11 @@ endif
build_preload_script:
-@echo "#!/bin/sh" > $(ESMF_PRELOADDIR)/preload.sh
-@echo "# Script to preload ESMF dynamic trace library" >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'env LD_PRELOAD="$$LD_PRELOAD $(ESMF_PRELOADDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX)" $$*' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'if [ "$$$(ESMF_ENV_PRELOAD)" != "" ]; then' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'env $(ESMF_ENV_PRELOAD)="$$$(ESMF_ENV_PRELOAD)$(ESMF_ENV_PRELOAD_DELIMIT)$(ESMF_PRELOADDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX)" $$*' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'else' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'env $(ESMF_ENV_PRELOAD)="$(ESMF_PRELOADDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX)" $$*' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'fi' >> $(ESMF_PRELOADDIR)/preload.sh
chmod 755 $(ESMF_PRELOADDIR)/preload.sh

ESMF_TRACE_STATICLINKLIBS := -lesmftrace_static
Expand Down
3 changes: 2 additions & 1 deletion src/Infrastructure/Trace/preload/gen_wrappers_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
* This file was generated by gen_wrappers_mpi.py.
* !! DO NOT EDIT !!
*
* Functions that will be preloaded with LD_PRELOAD, thereby
* Functions that will be preloaded with LD_PRELOAD
* (or DYLD_INSERT_LIBRARIES on Darwin), thereby
* overriding system library functions so we can call into our
* wrapper function.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Trace/preload/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ifeq ($(ESMF_OS),MinGW)
endif

tracelib_preload: preload.o preload_mpi.o wrappers.o wrappers_mpi.o
$(ESMF_SL_LIBLINKER) $(ESMF_SL_LIBOPTS) -o $(ESMF_LDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX) $^ $(ESMF_CXXLINKOPTS) $(ESMF_CXXLINKPATHS) $(ESMF_CXXLINKRPATHS) $(ESMF_CXXLINKLIBS) $(ESMF_TRACE_ESMFLIB)
$(ESMF_SL_PRELOAD_LIBLINKER) $(ESMF_SL_LIBOPTS) -o $(ESMF_LDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX) $^ $(ESMF_CXXLINKOPTS) $(ESMF_CXXLINKPATHS) $(ESMF_CXXLINKRPATHS) $(ESMF_CXXLINKLIBS) $(ESMF_TRACE_ESMFLIB)
$(MAKE) ESMF_PRELOADDIR=$(ESMF_LIBDIR) build_preload_script

tracelib_static: wrappers_io.o wrappers_mpi.o wrappers.o
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/Trace/preload/preload.C
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extern "C" {
/**
* Called into from ESMCI_Trace.C when the trace
* is opened and can receive events. The linker will preload
* this symbol when LD_PRELOAD is specified so we can
* catch this notification.
* this symbol when LD_PRELOAD (or DYLD_INSERT_LIBRARIES on Darwin)
* is specified so we can catch this notification.
*/
int c_esmftrace_notify_wrappers(int initialized) {
if (initialized == 1) {
Expand Down
3 changes: 2 additions & 1 deletion src/Infrastructure/Trace/preload/preload_io.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
*
* preload_io.c
*
* Functions that will be preloaded with LD_PRELOAD, thereby
* Functions that will be preloaded with LD_PRELOAD,
* (or DYLD_INSERT_LIBRARIES on Darwin), thereby
* overriding system library functions so we can call into our
* wrapper function.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Infrastructure/Trace/preload/preload_mpi.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* This file was generated by gen_wrappers_mpi.py.
* !! DO NOT EDIT !!
*
* Functions that will be preloaded with LD_PRELOAD, thereby
* Functions that will be preloaded with LD_PRELOAD,
* (or DYLD_INSERT_LIBRARIES on Darwin), thereby
* overriding system library functions so we can call into our
* wrapper function.
*
Expand Down
10 changes: 6 additions & 4 deletions src/Infrastructure/Trace/tests/ESMF_TraceMPIUTest.F90
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ program ESMF_TraceMPIUTest

!------------------------------------------------------------------------
!NEX_UTest
write(failMsg, *) "MPI_ALLREDUCE failed with ierr =", ierr
write(name, *) "Test MPI_ALLREDUCE ierr==0"
write(failMsg, *) "MPI_ALLREDUCE failed with ierr=", ierr
#if (!defined ESMF_MPIUNI && defined ESMF_TESTTRACE)
call ESMF_Test((ierr==0), name, failMsg, result, ESMF_SRCLINE)
#else
Expand All @@ -119,8 +120,8 @@ program ESMF_TraceMPIUTest

!------------------------------------------------------------------------
!NEX_UTest
print *, "MPI_ALLREDUCE returned ", recv
write(failMsg, *) "MPI_ALLREDUCE produced unexpected result. Expected 4, got ", recv
write(name, *) "Test MPI_ALLREDUCE recv==4"
write(failMsg, *) "MPI_ALLREDUCE produced unexpected result. recv=", recv
#if (!defined ESMF_MPIUNI && defined ESMF_TESTTRACE)
call ESMF_Test((recv==petCount), name, failMsg, result, ESMF_SRCLINE)
#else
Expand All @@ -133,7 +134,8 @@ program ESMF_TraceMPIUTest

!------------------------------------------------------------------------
!NEX_UTest
write(failMsg, *) "MPI call not profiled"
write(name, *) "Test MPI_ALLREDUCE call recorded as profiled"
write(failMsg, *) "MPI_ALLREDUCE call not profiled"
#if (!defined ESMF_MPIUNI && defined ESMF_TESTTRACE)
call ESMF_Test((mpicheck==1), name, failMsg, result, ESMF_SRCLINE)
#else
Expand Down

0 comments on commit 1bed7e4

Please sign in to comment.