To debug your multithreaded program at the thread level, you can use dbx. The following example illustrates this method of debugging with LSF Suite.
Add a variable to block the process until you attach with dbx.
In this sample program, simple-comm, the wait_for_dbx variable is set to 1 to create a wait loop. It is placed before the function or functions to be debugged.
#include <stdio.h> #include "mpi.h" void main( int argc, char **argv ) { MPI_Comm comm_dup; int error; int wait_for_dbx = 1; if((error = (MPI_Init(&argc, &argv))) != MPI_SUCCESS) { printf("Bad Init\n"); exit(-1); } while (wait_for_dbx); error = MPI_Comm_dup(MPI_COMM_WORLD, &comm_dup); if (error != MPI_SUCCESS) { printf("Bad Dup\n"); exit(-1); } error = MPI_Comm_free(&comm_dup); if (error != MPI_SUCCESS) { printf("Bad Comm free\n"); exit(-1); } MPI_Finalize(); } |
Compile the code, then run it.
After compiling the program, run it using bsub. (See the LSF Batch User's Guide for more information.)
% bsub -n 4 -Ip simple-comm
Identify the processes to which you want to attach the debugger.
Use bjobs to obtain information about the processes in the task. (See the LSF Batch User's Guide for more about getting information about processes.)
Attach the debugger to the processes that you would like to debug.
Attach the debugger to the processes. If you would like to debug only a subset of the processes, you must set up a conditional in such a way that the while statement is executed in only the process(es) that you will debug.
% dbx simple-comm 10838 Attached to process 10838 with 2 LWPs t@1 (l@1) stopped in main at line 18 in file "simple-comm.c" 18 while (wait_for_dbx);
Set your variable such that it will allow the process to unblock.
At the dbx prompt, use assign to change the value of the variable (here wait_for_dbx) and, hence, unblock the processes.
(dbx) assign wait_for_dbx = 0
Debug the processes.
After you have attached and set the instrumentation code appropriately, you can start debugging the processes as you normally would with dbx.