title: Using GDB to debug an MPI program in Fortran
body: <p>I read <a href="https://stackoverflow.com/a/363829/5825294">this</a> and arrived <a href="https://www.open-mpi.org/faq/?category=debugging#serial-debuggers" rel="nofollow noreferrer">here</a>, so now <strong>I think I should</strong> (if not so, please, tell me) rewrite the code</p>
  
  <pre><code>{
      int i = 0;
      char hostname[256];
      gethostname(hostname, sizeof(hostname));
      printf("PID %d on %s ready for attach\n", getpid(), hostname);
      fflush(stdout);
      while (0 == i)
          sleep(5);
  }
  </code></pre>
  
  <p>in Fortran. From <a href="https://stackoverflow.com/a/36975708/5825294">this answer</a> I understood that in Fortran I could simply use <code>MPI_Get_processor_name</code> in place of <code>gethostname</code>. Everything else is simple but <code>flush</code>. What about it?</p>
  
  <p>Where should I put it? In the main program <em>after</em> <code>MPI_Init</code>?
  And then? What should I do?</p>
  
  <p>For what concerns the compile options, I referred to <a href="https://gcc.gnu.org/bugs/segfault.html" rel="nofollow noreferrer">this</a> and used <code>-v -da -Q</code> as options to the <code>mpifort</code> wrapper.</p>
  
  <p><a href="https://stackoverflow.com/questions/34486294/gdb-debugger-in-mpi">This solution</a> doesn't fit my case, since I need to run the program on 27 processes as minimum, so I'd like to check one process only.</p>