[MPICH] Program crashes when multiple threads make MPI Calls
Ashok Babu Amara
ashok.amara at gmail.com
Thu Feb 9 12:43:55 CST 2006
Hi All,
I am making MPI calls from two threads and it doesn't seem to be
working. I have one thread constantly doing MPI_Send's and MPI_Recv's
and another thread which is constantly doing MPI_Allreduce.
When I run the program it either hangs or prints this message :
[0] Abort: header->id != c->next_packet_expected at line 730 in file
mpid/vapi/viacheck.c
The version of MPICH being used is 1.2.6 and the thread level support
is MPI_THREAD_FUNNELED.
Can someone advise what is possibly wrong ?
I have attached the code that is being tested.
Thanks,
- Ashok
-------------- next part --------------
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include "mpi.h"
int myRank;
int numProcs;
MPI_Comm com1;
MPI_Comm com2;
void* t1Main(void*);
void* t2Main(void*);
void* t1Main(void* data)
{
int retCode;
int val;
MPI_Status status;
while(1)
{
if(myRank == 0)
{
retCode = MPI_Send(&val, 1, MPI_INT, 1, 0, com1);
assert(retCode == MPI_SUCCESS);
retCode = MPI_Recv(&val, 1, MPI_INT, 1, 0, com1, &status);
assert(retCode == MPI_SUCCESS);
}
else
{
retCode = MPI_Recv(&val, 1, MPI_INT, 0, 0, com1, &status);
assert(retCode == MPI_SUCCESS);
retCode = MPI_Send(&val, 1, MPI_INT, 0, 0, com1);
assert(retCode == MPI_SUCCESS);
}
printf("%d: Send & Recv done\n", myRank);
}
}
void* t2Main(void* data)
{
int val;
int retCode;
val = 20;
while(1)
{
retCode = MPI_Allreduce(&myRank, &val, 1, MPI_INT, MPI_MAX, com2);
assert(retCode == MPI_SUCCESS);
printf("%d: MPI_Allreduce done\n", myRank);
}
}
int main(int argc, char** argv)
{
int provided;
int retCode;
pthread_t thandle1;
pthread_t thandle2;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
retCode = MPI_Comm_dup(MPI_COMM_WORLD, &com1);
assert(retCode == MPI_SUCCESS);
retCode = MPI_Comm_dup(MPI_COMM_WORLD, &com2);
assert(retCode == MPI_SUCCESS);
retCode = pthread_create( &thandle1, NULL, t1Main, NULL);
assert(retCode == 0);
retCode = pthread_create( &thandle2, NULL, t2Main, NULL);
assert(retCode == 0);
pthread_join(thandle1, NULL);
pthread_join(thandle2, NULL);
}
More information about the mpich-discuss
mailing list