On Aug 21, 2005, at 7:04 PM, Lord ROCKSTEADY wrote:
> Hello,
> here is some code which gives problems when I run. It only gives
> problems when the Barrier (*) is NOT commented out...
> What can I be doing wrong, since everything seems OK to me ?
>
> ( I know I didn't lutexed numprocs and myid, but that's not the
> problem...)
The problem is that LAM/MPI does not support MPI_THREAD_MULTIPLE. It
supports MPI_THREAD_SINGLE to MPI_THREAD_SERIALIZED. Since
MPI_THREAD_SERIALIZED is essentially a big lock around all MPI
functions, you're entering a deadlock state with your code. When you
have the barrier, you're enforcing a synchronization point, creating
the deadlock situation.
You should probably check the last argument to MPI_THREAD_INIT - it
will tell you whether your MPI implementation supports
THREAD_MULTIPLE or not. LAM will return MPI_THREAD_SERIALIZED if you
request MPI_THREAD_MULTIPLE, as the standard allows it to do.
Brian
> #include <pthread.h>
> #include <iostream>
> #include <semaphore.h>
> #include <mpi.h>
>
> #pragma comment (lib,"pthreadVC1.lib")
>
> using namespace std;
>
> sem_t thread_work,gotoEnd;
> int numprocs, myid;
>
> void * scheduler(void *null){
>
> sem_post(&thread_work);
>
> if(myid==0){
> for(int i=1;i<numprocs;i++){
> int send=i;
> MPI_Send(&send, 1, MPI_INT, i, 1,MPI_COMM_WORLD);
> }
> }
>
> sem_wait(&gotoEnd);
>
> // MPI_Barrier(MPI_COMM_WORLD); --> (*) this gives a problem....
>
> MPI_Finalize();
> return((void *)0);
> }
>
> void * worker(void *worker){
> sem_wait(&thread_work);
> printf("\nworker gestart op node %d",myid);fflush(stdout);
> if(myid!=0){
> MPI_Status status;
> int getal[3]={0};
> int index;
> MPI_Request request[3];
> MPI_Irecv(&getal[0],1, MPI_INT, 0,1, MPI_COMM_WORLD,&request
> [0]);
> MPI_Irecv(&getal[1],1, MPI_INT, 0,2, MPI_COMM_WORLD,&request
> [1]);
> MPI_Irecv(&getal[2],1, MPI_INT, 0,3, MPI_COMM_WORLD,&request
> [2]);
>
> MPI_Waitany(3, request,&index,&status);
>
> for(int i=0;i<3;i++){
> if(i!=index)
> MPI_Request_free(&request[i]);
> }
>
> printf("\nworker-%d; rcvd: %d uit:%d en index:%d",myid,getal
> [1],status.MPI_TAG,index);fflush(stdout);
> }
> sem_post(&gotoEnd);
> return((void *)0);
> }
>
> int main(){
> pthread_t thread[2];
>
> sem_init(&thread_work,NULL,0);
> sem_init(&gotoEnd,NULL,0);
>
> MPI_Init_thread( NULL, NULL, MPI_THREAD_MULTIPLE, NULL);
> MPI_Comm_size(MPI_COMM_WORLD,
> &numprocs);
> MPI_Comm_rank(MPI_COMM_WORLD,&myid);
>
> int status;
> pthread_attr_t attr;
>
> pthread_attr_init(&attr);
> pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
> pthread_create(&thread[0],&attr,scheduler,NULL);/*sheduler*/
> pthread_create(&thread[1],&attr,worker,NULL);/*worker*/
>
> pthread_join(thread[0],(void**)&status);
> pthread_join(thread[1],(void**)&status);
> pthread_exit(NULL);
> }
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
--
Brian Barrett
LAM/MPI developer and all around nice guy
Have a LAM/MPI day: http://www.lam-mpi.org/
|