How can I get a stack trace if my program crashes?#

The classical approach to find the location where your program crashed is to run it in a debugger or inspect a core file with the debugger. A quick way to get the stack trace without the need for a debugger is to compile your program with the following options:

$ ifort -g -O0 -traceback -o my_program my_program.f90

In case of segment violation during execution of the program, detailed information on the location of the problem (call stack trace with routine names and line numbers) will be provided:

$ ./my_program
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source
my_program         0000000000403360  Unknown               Unknown  Unknown    00007F8465324710  Unknown               Unknown  Unknown
my_program         0000000000402F5E  mo_calc_sum_mp_ca          10  my_program.f90
my_program         00000000004031A1  MAIN__                     26  my_program.f90
my_program         0000000000402E5E  Unknown               Unknown  Unknown          00007F8464D9BD5D  Unknown               Unknown  Unknown
my_program         0000000000402D69  Unknown               Unknown  Unknown

Real debuggers like Arm DDT installed on DKRZ HPC systems will allow you to get much more information in case the problem is not easily identified.