을 행의 합계 2.718로 계산하기로 결정했습니다. OpenMP가없는 코드가 완벽하게 작동하며 계산을 위해 걸리는 시간을 측정했습니다. 그러나 OpenMP를 사용하여 계산을 평준화 할 때 오류가 발생했습니다. 코어 i7 (8 코어 4 로직 4 물리)에서 프로그램을 실행하고 있습니다. 사람들이 말하는 것처럼 openMP를 사용하지 않고 두 배나 빠른 시간을 가져야합니다.OpenMP C++ (compliring with trouble)
#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 for 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 the time is used for parralel calculations"<<endl;
cout<<total_exp<<endl;
cin.get();
getch();
return 0;
}
사실() 수
long double fact(int N)
{
if(N < 0)
return 0;
if (N == 0)
return 1;
else
return N * fact(N - 1);
}
오류 3 오류 C3005의 계승을 계산하는 함수를 사용하여 : : 다음은 내 코드입니다 : C "병렬"지시문의 OpenMP의 예기치 않은 토큰 : \ 사용자 \ александр 문서는 비주얼 스튜디오 2012 \ 프로젝트 \ \ \의 ConsoleApplication1 \의 ConsoleApplication1 \ openmp.cpp 18
AFAIK VS는 OpenMP를 사용하기 위해 특별한 설정이 필요합니다. – maverik
세미콜론이 없어야한다고 생각합니다. –
사실이 경우 컴파일러 오류 메시지는 매우 명확하고 오류에 국한됩니다. –