I have a simple dissemination barrier implemented in OpenMP that has a potential deadlock and I have not been able to figure out why.
The threads share a common data structure flags which looks something like this:
// each other.
typedef struct Flags{
int myflags[2][MAX_THREADS];
int *partnerFlags[2][MAX_THREADS];
}Flags;
#pragma omp parallel shared(processors, rounds, totalTime)
{
int parity = 0;
int sense = 1;
int threadID = omp_get_thread_num();
int i;
Flags *localFlags = &processors[threadID];
for(i=0; i<MAX_BARRIERS; i++) {
double startTime = omp_get_wtime();
disseminationBarrier(localFlags, &sense, &parity, &rounds);
double endTime = omp_get_wtime();
double elapsedTime = (endTime - startTime);
printf("Time spent at the barrier(in ms) %d by thread %d is %lf\n", i, threadID, (elapsedTime / 1000.0));
#pragma omp critical
{
totalTime = totalTime + elapsedTime;
}
}
}
The code for the dissemination function looks something like this
void disseminationBarrier(Flags *localFlags, int *sense, int *parity, int *rounds){
int i;
for(i=0; i<*rounds; i++) {
*localFlags->partnerFlags[*parity][i] = *sense;
while(localFlags->myflags[*parity][i] != *sense); -> Point of probable deadlock
}
if(*parity) {
*sense = !*sense;
}
*parity = 1- *parity;
}