2012-06-18 21 views
5

¡Soy nuevo en la programación de MPI! Traté de medir el ancho de banda de comunicación punto a punto entre los procesadores de forma práctica. ¡Pero ahora tengo una falla de segmentación! No entiendo por qué sucede esto. También probé valgrind en ubuntu, sin embargo no tengo idea. Así que tal vez alguien me puede ayudar: DMPI Error de segmentación en MPI_Isend()

gracias por la rápida respuesta, pero esto no cambia el problema :( Acabo de actualizar el error

Aquí el código fuente

#include "mpi.h" 
#include <stdio.h> 
#include <stdlib.h> 

int main(int argc, char *argv[]){ 

int myrank, size; 
MPI_Init(&argc, &argv); 
MPI_Comm_rank(MPI_COMM_WORLD, &myrank); 
MPI_Comm_size(MPI_COMM_WORLD, &size); 

int *arraySend = (int *)malloc(25000*sizeof(int)); 
int *arrayRecv = (int *)malloc(25000*sizeof(int)); 
double startTime = 0.0, endTime = 0.0; 
MPI_Status status,statusSend, statusRecv; 
MPI_Request requestSend, requestRecv; 

if(size != 2){ 
    if(myrank == 0){ 
     printf("only two processors!\n"); 
     MPI_Finalize(); 
     return 0; 
    } 
} 

if(myrank == 0){ 
    startTime = MPI_Wtime(); 
    MPI_Send(&arraySend, 25000, MPI_INT, 1, 0,MPI_COMM_WORLD); 
}else{ 
    MPI_Recv(&arrayRecv, 25000, MPI_INT, 0, 0, MPI_COMM_WORLD, &status); 
} 

if(myrank == 0){ 
    endTime = MPI_Wtime(); 
    printf("100k Bytes blocking: %f Mb/s\n", 0.1/(endTime-startTime)); 
    startTime = MPI_Wtime(); 
    MPI_Isend(&arraySend, 25000, MPI_INT, 1, 0, MPI_COMM_WORLD, &requestSend); 
    MPI_Wait(&requestSend, &statusSend); 
    }else{ 
    MPI_Irecv(&arrayRecv,25000,MPI_INT,0,0,MPI_COMM_WORLD, &requestRecv); 
    MPI_Wait(&requestRecv, &statusRecv); 
    } 

if(myrank == 0){ 
    endTime = MPI_Wtime(); 
    printf("100k Bytes non-blocking: %f Mb/s\n", 0.1/(endTime-startTime)); 
} 
free(arraySend); 
free(arrayRecv); 
MPI_Finalize(); 
return 0; 
} 

y aquí el error actualiza!

$ mpirun -np 2 nr2 
[P90:05046] *** Process received signal *** 
[P90:05046] Signal: Segmentation fault (11) 
[P90:05046] Signal code: Address not mapped (1) 
[P90:05046] Failing at address: 0x7fff54fd8000 
[P90:05046] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10060) [0x7f8474777060] 
[P90:05046] [ 1] /lib/x86_64-linux-gnu/libc.so.6(+0x131b99) [0x7f84744f7b99] 
[P90:05046] [ 2] /usr/lib/libmpi.so.0(ompi_convertor_pack+0x14d) [0x7f84749c75dd] 
[P90:05046] [ 3] /usr/lib/openmpi/lib/openmpi/mca_btl_sm.so(+0x1de8) [0x7f846fe14de8] 
[P90:05046] [ 4] /usr/lib/openmpi/lib/openmpi/mca_pml_ob1.so(+0xd97e) [0x7f8470c6c97e] 
[P90:05046] [ 5] /usr/lib/openmpi/lib/openmpi/mca_pml_ob1.so(+0x8900) [0x7f8470c67900] 
[P90:05046] [ 6] /usr/lib/openmpi/lib/openmpi/mca_btl_sm.so(+0x4188) [0x7f846fe17188] 
[P90:05046] [ 7] /usr/lib/libopen-pal.so.0(opal_progress+0x5b) [0x7f8473f330db] 
[P90:05046] [ 8] /usr/lib/openmpi/lib/openmpi/mca_pml_ob1.so(+0x6fd5) [0x7f8470c65fd5] 
[P90:05046] [ 9] /usr/lib/libmpi.so.0(PMPI_Send+0x195) [0x7f84749e1805] 
[P90:05046] [10] nr2(main+0xe1) [0x400c55] 
[P90:05046] [11] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7f84743e730d] 
[P90:05046] [12] nr2() [0x400ab9] 
[P90:05046] *** End of error message *** 
-------------------------------------------------------------------------- 
mpirun noticed that process rank 0 with PID 5046 on node P90 exited on signal 11 
(Segmentation fault). 
+0

¿Has visto alguna diferencia en la velocidad entre las operaciones de bloqueo y la combinación de las operaciones no bloqueantes seguido imeddiately por unas esperas? –

Respuesta

5

el tamaño de su matriz pasada es incorrecta.

sizeof(arraySend) debe ser simple 25000 como MPI deduce automáticamente el tamaño como define el tipo de datos (aquí MPI_INT). Ony, si tienes una matriz de bits, normalmente necesitas sizeof (...) en tu código.

Trate de asignar la memoria en la pila en lugar de la pila, por ejemplo en lugar de:

int *arraySend = (int *)malloc(25000*sizeof(int)); 

uso int arraySend [25000];

y luego use arraySend en lugar de &arraySend en sus llamadas mpi.

Si puede usar C++, también puede usar los agradables encabezados mpp boost donde el tamaño se calcula automáticamente a partir de los datos pasados.

+0

ohhh eso fue estúpido ^^ pero esto no lo resuelve :( – samsemilia7

+1

También '& arraySend' no es un puntero a la memoria asignada, sino un puntero al puntero de tipo' int * '. También es un problema. –

+0

gracias todos ustedes, me equivoqué con los punteros: D – samsemilia7

0

si está utilizando una aplicación MPI decente, puede utilizar mpirun -gdb, más doc here

Cuestiones relacionadas