From: Julian S. <js...@ac...> - 2013-01-30 15:11:57
|
> But the problem is I am unable to get valgrind to point out the problem in > the MPI code. The output from that run is included below (if it is all > right, I will include the source code also): > > r31i2n2% m hello_mpi_c.c > #include <stdio.h> > #include <mpi.h> > > int main(int argc, char **argv) > { > int ierr, myid, npes; > int len; > char name[MPI_MAX_PROCESSOR_NAME]; > > ierr = MPI_Init(&argc, &argv); > #ifdef MACROTEST > #define MACROTEST 10 > #endif > ierr = MPI_Comm_rank(MPI_COMM_WORLD, &myid); > ierr = MPI_Comm_size(MPI_COMM_WORLD, &npes); > ierr = MPI_Get_processor_name( name, &len ); > > printf("Hello from rank %d out of %d; procname = %s\n", myid, npes, > name); > > #ifdef MACROTEST > printf("Test Macro: %d\n", MACROTEST); > #endif > #ifdef BUG > { > int* x = (int*)malloc(10 * sizeof(int)); > x[10] = 0; // problem 1: heap block overrun > printf("Print something %d\n",x[10]); > } // problem 2: memory leak -- x not freed > #endif > > ierr = MPI_Finalize(); > > } Two things: (1) rerun the MPI version but with the extra argument -v for valgrind, and post the results here. This will make it possible to see if interception of malloc etc failed for some reason. (2) send (in private email) the executable corresponding to the above program to me, so I can have a look at the code for main and see if the compiler optimised out the test, since the allocation and assignment have no useful side effects. J |