I have a code that is a mix of Fortran
, C
and R
. it’s a simulation code. The backend/solver is in Fortran
and C
and R
is used as the wrapper for creating simulation workflow and launching the process.
I would like to do some profiling using gprof
so what I did is I added the relevant flags to my makefiles. Here is the structure of directories:
Let’s say my code is located in the following path
/home/myusername/DEV/simcode/src
The parent makefile is located in src
then I have the following sub-makefiles
src/Global/fortran/Makefile
src/TS/c/Makefile
src/TS/fortran/ReadModelData/Makefile
src/TS/fortran/RunSim/Makefile
So I modified all my sub-makefiles in the following fashion:
FC=gfortran
LD=gfortran
OPT=-O2
DBG=-g
PROF= -pg
ifdef SYSTEMROOT
# Windows OS
SIM_GLOBAL = libCodeGlobal.dll
FFLAGS = $(OPT) $(DBG) -cpp -fno-underscoring $(PROF)
LDFLAGS = $(OPT) $(DBG) $(PROF)
else
ifeq ($(shell uname),Linux)
# GNU/Linux OS
SIM_GLOBAL = libCodeGlobal.so
FFLAGS = $(OPT) $(DBG) -cpp -fPIC -fno-underscoring $(PROF)
LDFLAGS = $(OPT) $(DBG) $(PROF)
else
# Mac OSX
SIM_GLOBAL = libCodeGlobal.dylib
FFLAGS = $(OPT) $(DBG) -cpp -fno-underscoring $(PROF)
LDFLAGS = $(OPT) $(DBG) $(PROF)
endif
endif
I modified all Makefiles in the same manner as they are pretty much the same. The I ran
make clean
make all
In
/home/myusername/DEV/simcode/src
Where my parent Makefile is located. Then I ran
R CMD INSTALL .
This is how I install my code, this installs my code on a path such as
/home/myusername/R/x86_64-pc-linux-gnu-library/4.0/MYCODE
where my *so
files are located.
Then simply opened an R
session by typing R
in terminal and loading my code in it
library(MYCODE)
Then running a simulation test case
source("path to the test case file which is an `R` script")
Based on what I understood this process should create a file called gmon.out
which is the could be used to analyze the performance using gprof
, but I don’t get the gmon.out
file.
I checked the installation of gprof
and it is installed, i also ran a simple test case to see if it creates gprof
file and it properly did, so the problem should be coming from my Simulation code and probably my makefiles.
Any help would be appreciated. Concerning my operating system I’m working on linux if it helps.