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...)
#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);
}
|