c++ - OpenMP count the number of iteration in cycle which is making each thread -


i decided count number of iteration in cycle making each thread. must declare variable , thread number of each iteration right? got number of threads ( 0,1,2,3) 4 threads. when created variables calculate sum of each thread got problem.

#include <iostream> #include <time.h> #include <math.h> #include "fact.h" #include <cstdlib>; #include <conio.h>; #include <omp.h> using namespace std; int main() { clock_t t1,t2; int n; long double exp=0; long double y; int p; int axe; cout<<"enter n:"; cin>>n; t1=clock();  int a=0,b=0,c=0,d=0;     #pragma omp parallel num_threads(4) reduction (+:exp) for(int i=1; i<n; i++) {         int l=omp_get_thread_num();         cout<<l<<endl;         if (l=0) {a++;}         else if (l=1) {b++;}         else if (l=2) {c++;}         else   {d++;}     p=i+1;     exp=exp+(1/((fact(p))));  }  t2=clock(); double total_clock; total_clock=t2-t1; long double total_exp; total_exp=exp+2; cout<<endl; cout<<endl; cout<<total_clock<<"\t time used parralel calculations"<<endl; cout<<total_exp<<endl; cout<<a<<" thread one"<<endl; cout<<b<<"thread two"<<endl; cout<<c<<"thread three"<<endl; cout<<d<<"thread fourth"<<endl;     return 0;} 

i not getting errors shows me not proper number of iteration in cycle each thread making. in work calculated exponent. 2.71

you need use if (l == 0) etc. instead of if (l = 0). latter assigns 0 l rather comparing l 0.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -