1

I have a Fortran program that runs a series of identical calculations on a number of different input data. After doing these calculations the code then always writes a GNUplot script that does some diagnostic plotting (nothing too difficult) and runs it using execute_command_line in Linux.

This usually works well, but after some time I think there must be a memory leak of some kind that works cumulative, because the GNUplotting becomes slower and slower. At some point it virtually stalls.

My question is therefore: Is it possible to interrupt the call to execute_command_line using the keyboard without killing the main Fortran program? Needless to say, CTRL-C kills everything, which is not what I want: I want the main program to continue.

I have been playing with the optional flag wait=.true. but this does not help.

Also, I know that the memory leak has to be fixed (or whatever the cause is), but for now I would like to first see the diagnostic output.

Toon
  • 187
  • 11

1 Answers1

0

The only solution I have been able to come up with is kind of a workaround:

  • Modify the shell script so that it

    • runs the Fortran program in the background: ./mpirun prog_name options &
    • gets the PID of this proces: proc_PID=$!
    • waits for the process: wait $proc_PID
    • traps an interrupt signal: trap handler SIGINT
    • lets the handler send a SIGURS1 signal: function handler() { kill -SIGUSR1 $proc_PID }
  • modify the Fortran code so that it catches the SIGUSR1 signal and does what you want with it. For example by having a look here.

By running the mpi process in the background you avoid killing mpirun with SIGINT, which cannot be trapped but you send instead a SIGURS1, which is properly propagated to the mpi processes where it can be handled with directly.

As a side note, however, I realized that this will not solve my problem as my problem was related to an external call to gnuplot using execute_command_line. Since I had a cumulative memory leak, at some point this call started taking for ever because memory resources became scarcer. So the only thing I could have done is manually killing the gnuplot process.

Better, of course, was fixing the memory leak, which I did.

Community
  • 1
  • 1
Toon
  • 187
  • 11