How to use GDB with openMP and concurrent programming?
I was provided with a text file as input with 1,000,000 entries between 0 and 9. Each entry corresponds to a vote for a candidate made by a national. I was asked to read the file in sequence and then determine who won the race. I've been asked to do this with both parallel and non-parallel programming. My parallel function (pCounter) is not working and I am trying to figure out why, but I cannot get GDB to work in openMP. It just "continues" over the function when I want it to "walk". Does anyone know how I can use GDB for openMP and parallel programming?
EDIT When I try to execute a parallel function I get the following output:
[New Thread 0x7ffff619e700 (LWP 11152)]
[New Thread 0x7ffff599d700 (LWP 11153)]
[New Thread 0x7ffff519c700 (LWP 11154)]
Compiler line: g++ -g homework_5_1.cpp -o hw51 -std=c++11 -fopenmp
code:
void sCounter(myint *x, myint len){
myint candidates[10];
for(int i=0; i<10; ++i){
candidates[i]=0;
}
for(int i=0; i<len; ++i){
candidates[x[i]]+=1;
}
int winner=0;
for(int i=0; i<10; ++i){
if(i==winner)
++i;
if(candidates[i]>candidates[winner]){
winner=i;
i=0;
}
}
cout<<"The winner is candidate "<<winner<<endl;
for(int i=0; i<10; i++){
cout<<candidates[i]<<" ";
}
cout<<endl;
int sum=0;
for(int i=0; i<10; ++i){
sum+=candidates[i];
}
cout<<sum<<endl;
}
void pCounter(myint *x, myint len){
myint numberOfThreads;
myint candidates[10];
for(int i=0; i<10; ++i){
candidates[i]=0;
}
int winner=0;
#pragma omp parallel
{
#pragma omp for
for(int i=0; i<len; ++i){
candidates[x[i]]+=1;
}
#pragma omp for
for(int i=0; i<10; ++i){
if(i==winner)
++i;
if(candidates[i]>candidates[winner]){
winner=i;
i=0;
}
}
}
cout<<"The winner is candidate "<<winner<<endl;
for(int i=0; i<10; i++){
cout<<candidates[i]<<" ";
}
cout<<endl;
int sum=0;
for(int i=0; i<10; ++i){
sum+=candidates[i];
}
cout<<sum<<endl;
}
source to share
No one has answered this question yet
Check out similar questions: