Debugging 2D Matrix Allocation & Parallel Computation in C with MPI & Various Methods - Pr, Assignments of Computer Science

Hints and instructions for debugging mpi applications in cosc 6374 – parallel computation course by edgar gabriel. It covers two methods for allocating 2d matrices in c, their memory locations, and the relevance of these methods when sending matrices to other processes using mpi. Additionally, it discusses debugging techniques for sequential and parallel applications, including printf statements, assertions, and using a debugger.

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-j94
koofers-user-j94 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Edgar Gabriel
COSC 6374
Parallel Computation
Debugging MPI applications
Edgar Gabriel
Spring 2009
COSC 6374 Parallel Computation
Edgar Gabriel
Hint for the Homework
Allocating 2-D matrices in C, Method 1
default method recommended in all C books
Problem: &(A[i][NCOLUMNS-1]+1) ≠ &(A[i+1][0])
/* Method 1 to allocate a 2D matrix */
A = ( double **) malloc ( NROWS * sizeof ( double *));
for ( i=0; i<NROWS; i++ ) {
A[i] = (double*) malloc (NCOLUMNS*sizeof(double ));
}
/* How to free a 2D matrix allocated with Method 1 */
for ( i=0; i<NROWS; i++ ) {
free ( A[i] );
}
free (A);
pf3
pf4
pf5

Partial preview of the text

Download Debugging 2D Matrix Allocation & Parallel Computation in C with MPI & Various Methods - Pr and more Assignments Computer Science in PDF only on Docsity!

Edgar Gabriel

COSC 6374

Parallel Computation

Debugging MPI applications

Edgar Gabriel

Spring 2009

COSC 6374 – Parallel ComputationEdgar Gabriel

Hint for the Homework

  • Allocating 2-D matrices in C, Method 1
    • default method recommended in all C books
    • Problem: &(A[i][NCOLUMNS-1]+1) ≠ &(A[i+1][0])

/* Method 1 to allocate a 2D matrix */ A = ( double *) malloc ( NROWS * sizeof ( double )); for ( i=0; i<NROWS; i++ ) { A[i] = (double) malloc (NCOLUMNSsizeof(double )); }

/* How to free a 2D matrix allocated with Method 1 */ for ( i=0; i<NROWS; i++ ) { free ( A[i] ); } free (A);

COSC 6374 – Parallel ComputationEdgar Gabriel

Hint for the Homework

  • Allocating 2-D matrices in C, Method 2

/* Method 2 to allocate a 2D matrix / A = ( double ) malloc ( NROWS * sizeof ( double )); A[0] = (double) malloc (NROWSNCOLUMNSsizeof(double)); for ( i=1; i<NROWS; i++ ) { A[i] = &(A[0]+iNCOLUMNS); }

/* How to free a 2D matrix allocated with Method 2 */ free (A[0]); free (A);

COSC 6374 – Parallel ComputationEdgar Gabriel

Hint for the Homework

  • Comparing now the two methods + a statically defined

matrix of dimensions 4x

Method 1 A= 0x602010 A[0]= 0x &(A[0][0]) = 0x &(A[1][0]) = 0x &(A[2][0]) = 0x602a &(A[3][0]) = 0x602f Matrix A has been freed Method 2 A = 0x602010 A[0] = 0x &(A[0][0]) = 0x &(A[1][0]) = 0x &(A[2][0]) = 0x602a &(A[3][0]) = 0x602f Matrix A has freed Static matrix B = 0x7fff8ade7b00 B[0] = 0x7fff8ade7b &(B[0][0]) = 0x7fff8ade7b &(B[1][0]) = 0x7fff8ade &(B[2][0]) = 0x7fff8ade &(B[3][0]) = 0x7fff8ade8a

COSC 6374 – Parallel ComputationEdgar Gabriel

Using a debugger

  • For a source file to be visible in the debugger, you have

to compile the source code with the –g option, e.g.

gabriel@salmon>mpicc –g –o test test.c

  • Avoid using optimization flags, such as –O3 when you would like to debug the code
  • Two types of debugger
  • Command line debugger, such as gdb
  • Graphical debuggers, such as ddd (which is a GUI to gdb)

COSC 6374 – Parallel ComputationEdgar Gabriel

Start

app.

Load application into the debugger

Debugger points to the problem

Show the value of a variable when the problem occurred

Show source code of app.

COSC 6374 – Parallel ComputationEdgar Gabriel

gdb commands

  • Setting breakpoints: debugger stops execution at the

specified line. Example

(gdb) break errexample.c:

(gdb) break myfunc

  • Stepping through the source code

(gdb) next (skips subroutines/functions) (gdb) step (enters subroutines/functions)

  • Continue execution (not step by step anymore)

(gdb) cont

  • Quit debugger

(gdb) quit

COSC 6374 – Parallel ComputationEdgar Gabriel

COSC 6374 – Parallel ComputationEdgar Gabriel

Attaching to a

process

  • Menu File
  • Bullet: attach

to processes

  • Choose the PID

which you would

like to debug

COSC 6374 – Parallel ComputationEdgar Gabriel

Debugging parallel applications (III)

  • Some MPI libraries support the startup of a debugger in

the mpirun command, including Open MPI

mpirun –np 2 ddd ./colltest

  • only if all processes are running locally
  • Starts one ddd session per process
  • Not useful for large numbers of processes