Skip to content

CoderFAQ

Patrick Heidegger edited this page Apr 19, 2023 · 10 revisions

Coding in Python

Switch Compilers

Create a new build directory when switching to another compiler!

clang

Using gfortran

export CC=clang; export CXX=clang++; export FC=gfortran 

you can also use the Intel Fortran compiler (see below for compilervars.sh)

export CC=clang; export CXX=clang++; export FC=ifort 

intel

to download the intel compilers follow the instructions on the intel homepage. You will need at least the basekit and the hpckit. Additionally, you need to activate the API kits, e.g., via calling

. /opt/intel/oneapi/setvars.sh

for all users or

. ~/intel/oneapi/setvars.sh

for a single user. You can add one of these commands to your .bashrc / .zshrc file to activate automatically when opening the terminal. Check your installation by typing icc --version and icpc --version.

another, perhaps deprecated way is to source compilervars.sh to set your path, e.g.,

source /opt/intel/compilers_and_libraries/linux/bin/compilervars.sh intel64

in your .bashrc.

To use the intel compilers, then set the environment variables:

export CC=icc; export CXX=icpc; export FC=ifort 

before you do the first cmake / ccmake in your build folder. If you have no ifort you can use gfortran. Note that icc and icpc are deprecated and will be replaced by ipx and icpx in future.

Parallel make

For a standard freshly created cfs build directory no parallel make (make -j) is possible for the initial make due to the integration of cfsdeps via external projects. However, there is a chance that it works with precompiled cfsdeps as

make cfsdeps -j

after that you can build cfs via

make cfsbin -j

or just

make -j

CMake Hints and Tricks

  • To export all variables available within cmake call DISPLAY_ALL_VARIABLES() which is defined in CFS_macros.cmake
  • if you use cmake .. instead of ccmake .. you see the full output. cmake .. does twice configure and then generate.
  • useful cmake variables: https://cmake.org/Wiki/CMake_Useful_Variables

Linker Problems

Very helpful is to see what is actually compiled and linked:

export VERBOSE=1

Then execute "make". You can now examine the gcc command end even copy -> modify -> paste. Unset by unset VERBOSE

A log file of all the linking options might be cleaned to separate lines via

sed 's|../../|\n|g' link_release.txt

You might want to add the linker command -Wl,--verbose so see how the libs are searched.

This is a script for searching for (unresolved) symbols. You have to edit the symbol and search path inside the script. https://cfs.mdmt.tuwien.ac.at/trac/attachment/wiki/DevelopCfs/recursive_nm.py

Segmentation faults

The message means that the application tried to access invalid memory - typically via null or uninitialized pointer. In the CFS case, when CFS runs with

cfs -f

might also mean that an exception occured. You then see the error message followed by the segmentation fault.

For PiezoSIMP one mechanic and one electrostatic load must be defined
In file 'NO_FILENAME'
Segmentation fault

Memory debugging

valgrind --tool=memcheck --suppressions=cfs.supp --track-origins=yes cfs -m bulk2d_3.mesh mech
  • generate a suppressions file with the help of
valgrind --tool=memcheck --gen-suppressions=all --leak-check=full cfs -m bulk2d_5.mesh mec
  • Eclipse has a valgrind plugin which is a good frontend

Profiling

  • To enable debug info in release mode (line numbers) add in ccmake after toggling to advanced mode for CMAKE_CXX_FLAGS_RELEASE the option -g

Clone this wiki locally