visual studio 2010 - OpenMP C++ (trouble with compliling) -


i decided calculate e sum of rows 2.718.... code without openmp works , measured time taking calculations. when used openmp parralelize calculation however, got error. running program on core i7(8 cores 4 logic , 4 physical). people must time twice fast without using openmp. below code:

  #include <iostream>   #include <time.h>   #include <math.h>   #include "fact.h"    #include <cstdlib>;   #include <conio.h>;   using namespace std;    int main()   { clock_t t1,t2; int n; long double exp=0; long double y; int p; cout<<"enter n:"; cin>>n; t1=clock();     #pragma omp parallel num_threads(2); for(int i=1; i<n; i++) { 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<<total_clock<<"\n time used parralel calculations"<<endl; cout<<total_exp<<endl;  cin.get(); getch();     return 0;      } 

fact() using function calculate factorial of number

    long double fact(int n)       {     if(n < 0)        return 0;    if (n == 0)      return 1;     else      return n * fact(n - 1);      } 

error 3 error c3005: ;: unexpected token in directive openmp "parallel for" c:\users\александр\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\openmp.cpp 18

when using openmp pragmas, semicolons not needed, hence:

"#pragma omp parallel num_threads(2);"

should "#pragma omp parallel num_threads(2)"

without ;


Comments

Popular posts from this blog

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

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -