Sommaire
Create an executable
In the tutorial below you will have to replace everything that is in cursive red with your own personal names. The rest is just copy-paste.
Execute the following in the same terminal/window!
1) Create directory
First you should come up with a name for your executable. To make the rest of this tutorial easier set the variable 'My_Abs' to the name of your choice:
My_Abs=name_of_my_executable
Then create yourself a directory under your home(!) (so it gets backup up) in which you want to create the executable.
I usually call mineFor example:
mkdir -p ~/gem/v_5.1.1/Abs/... ${My_Abs}
2) Populate directory
Go into the executable directory you just created above. For example:
cd ~/gem/v_5.1.1/Abs/${My_Abs}
a) Clone the Git repository you want
Before cloning anything make sure the owner of the code you want
...
to clone has commited all modifications! Otherwise you will not get them. Then you can clone the source code with:
git clone full_Abs_directory_of_sourcecode_to_clone/gem
Or you can clone my latest verison withFor example:
git clone ~winger/gem/v_5.1.1/Abs/UQAM_development_FLake_CLASSlatest/gem
then change into 'gem' directory:
cd gem
If you get something like the following your cloning was successful:
Volet |
---|
Cloning into 'gem'... done. Updating files: 100% (2367/2367), done. |
b) Uncommited changes
Only ifthere were uncommited changes to the code you would like to get as well you will have to copy the modified files by hand. This is not elegant at all, but if you want to make sure you got all modifications you can also remove your source code and then copy the source code you want by hand. For example:
cd ~/gem/v_5.1.1/Abs/${My_Abs}/gem/src
rm -rf gemdyn modelutils rpnphy
cd full_Abs_directory_of_sourcecode_to_clone/gem/src
rsync -ruvt gemdyn modelutils rpnphy ~/gem/v_5.1.1/Abs/${My_Abs}/gem/src
c) Create working directories
Change into 'gem' directory that came with the clone:
cd ~/gem/v_5.1.1/Abs/${My_Abs}/gem
...
So the object files, libraries and executables will not be under your home, create links for the directories 'build' and 'work'. Pick a place under which you want to keep the object files, libraries and executables. Preferably under the default(!) space of you professors, for example:
work_space=~/projectsproject/def-professor/${USER}/GEM_WORK_DIR # Set 'professor' to the CC name of your professor. You can find all of them under ~/projects.
Create the directories and the links (using ${My_Abs} from above) :
mkdir -p ${work_space}/${My_Abs}/build
mkdir -p ${work_space}/${My_Abs}/work
ln -s ${work_space}/${My_Abs}/build
ln -s ${work_space}/${My_Abs}/work
d) Check directory content
Execute a simple 'ls' command to check if your directory content looks okay:
ls -al
If the list you are getting looks like the following your initial setup looks fine:
Volet |
---|
drwxr-xr-x. ... 25600 Jul 17 14:20 . |
3) Create the
...
executable
a) Acquire compiler
Only needed once per window/terminal!
You can used the same alias used to acquire the compiler to run GEM:
511
b) If you are not already in it, go into the 'gem' directory of your abs-directory:
module add intel/2021.2.0 fftw-intel-2021cd ~/gem/v_5.1.1/Abs/${My_Abs}/gem
cb) Set the variable 'abs_dir' to the name of your executable directory, including the 'gem' directory (needed under de))
abs_dir=$(pwd)
cd) Change into 'build' directory:
cd build
de) Create make files and dependencies
(Only needed once and whenever you add any new routines or add include files or module "use" lines to an existing routine.)
cmake -DCOMPILER=intel -DCMAKE_VERBOSE_MAKEFILE=ON -DWORK_PREFIX=${abs_dir}/work ${abs_dir}/project
ef) Compile and create executable
make work-j4 maingemdm
If the executable got created, you will find it underYou can add the key '-j4' to use 4 cores in parallel:
make -j4 work
3) Modify the source code
Once you set the environment the variables $gemdyn and $rpnphy will get set, pointing to the source code in the environment:
${gemdyn}/src/*/*
${rpnphy}/src/*/*
ls -lh src/maingem/maingemdm
It should have close to 50 MB.
4) Modify source code (optional)
a) You can find the main GEM routines under .../gem/src/*/*, for example :
Most dynamic routines are under:
.../gem/src/gemdyn/base
Most physics routines are under:
.../gem/src/rpnphy/base
Most surface routines are under:
.../gem/src/rpnphy/surface
Find and edit the You can check there which routines you want to modify.
b) Recreate the executable
Once you know which modified the routine(s) you want to modify go back into your "executable directory". Then "check out" all the routines you want to modify with:
rde co subroutine.F90
or
rde co comdeck.cdkYou can also check out several routines at the same time.
Once you modified or copied the routines you want you need to compile them and then recreate the executable, following points b) 2) to 4) aboveyou need to recreate the executable.
To do this you need to go back in the 'build' directory!
Only if you add any new routines or add include files or module "use" lines to an existing routine you first need to recreate the dependencies and make files by re-executing the full cmake command under point 3d) again - see above.
Otherwise, it is enough to just re-execute:
make -j4 maingemdm
If you just want to compile one routine without creating the executable (to save time) you can just compile a routine, for example utils/sfclayer_mod.F90 with:
cd .../build/src/rpnphy
make utils/sfclayer_mod.F90.o
5) Use your executable
To use your own executable set 'GEM_ovbin' in your 'configexp.cfg' to the path of your executable directory, up until but excluding the 'gem' directory. For example:
GEM_ovbin=~/gem/v_5.1.1/Abs/${My_Abs}
Modify compiler flags (optional)
Compile one routine without optimization, '-O0'
- edit the file named CMakeLists.txt in the main directory where the subroutine is situated (for example, src/rpnphy/CMakeLists.txt if the subroutine is situated in the physics directory)
- copy the following example before the last line (add_library...) and modify it according to your needs:
set_source_files_properties(utils/sfclayer_mod.F90 PROPERTIES COMPILE_OPTIONS "-O0")
- make sure you use a recent version of cmake (at least 3.11) - on Narval we do
- you can verify the option was passed by looking at the file flags.make situated in the corresponding directory in the build directory, for example build/src/rpnphy/CMakeFiles/phy.dir/flags.make:
# Custom options: src/rpnphy/CMakeFiles/phy.dir/utils/sfclayer_mod.F90.o_OPTIONS = -O0
Then go back into your 'build' directory and compile with the usual:
make maingemdm
or
make -j4 maingemdm
When compiling this routine now you should see something like the following:
Building Fortran object src/rpnphy/CMakeFiles/phy.dir/utils/sfclayer_mod.F90.o
... -O2 -g -O0 -c ...
The second '-O0' should overwrite the first '-O2'.
Set 'fp-model' to 'precise' or 'strict'
In project/Linux-x86_64-intel.cmake change in line 24 '-fp-model source' to '-fp-model precise' (Vivian) resp. '-fp-model strict' (Ron).
precise | Disables optimizations that are not value-safe on floating-point data. |
strict | Enables precise and except, disables contractions, and enables pragma stdc fenv_access. |
source | Rounds intermediate results to source-defined precision. |