-1
これは、Piをモンテカルロ法で計算するコードです。私たちは入力を与えます:thread_count - プロセッサスレッドの数、n - ランダムに生成されたポイントの数 がここに出力でrandのC++/OpenMPエラー
using namespace std;
int main (int argc, char* argv[]) {
/*sprawdzanie danych: thread_count - liczba wątków, n - liczba punktów*/
if (argc != 3) {
cout << "Co Ty piszesz!. Ma być: ./pi <thread_count> <n>" << endl;
exit(-1);
}
/*Sprawiamy by liczby były całkowite*/
int thread_count = atoi(argv[1]);
long n = atoi(argv[2]);
/*Test wartosci liczb*/
if (thread_count <= 0 || n <= 0) {
cout << "Co Ty piszesz!. Ma byc większe od 0" << endl;
exit(-1);
}
unsigned ziarno;
double x, y;
long int Ustrzelone = 0;
double Start = omp_get_wtime();
#pragma omp parallel default(none) private(x,y, ziarno) firstprivate(n) reduction(+:Ustrzelone) num_threads(thread_count)
{
ziarno = 25231 + 16*omp_get_thread_num();
#pragma omp for schedule(dynamic)
for(long i = 0; i <= n; i++) {
x = (double) rand_r(&ziarno)/RAND_MAX * 2 - 1;
y = (double) rand_r(&ziarno)/RAND_MAX * 2 - 1;
if ((x*x) + (y*y) <= 1.0) {
Ustrzelone += 1;
}
}
}
double Stop = omp_get_wtime();
double czas_obliczen = 1000 * (Stop - Start);
/*Ustawienie ilosci liczb po przecinku i wyswietlenie wyniku*/
cout.precision(15);
//double pi = (double) 4*Ustrzelone/n;
//cout << "Pi wynosi " << pi << endl;
cout << czas_obliczen << endl;
return 0;
以下の私のコードだ私はそのようなエラーが出る: [Error] 'rand_r' was not declared in this scope
多くの時間を持っていないので、あなたはそれを改善するための方法をいくつかの結論に私を持って来ることを願って、この放置。
ありがとうございます。
あなたがいや私はそれが欠落していないよ ''の#include –
が欠落している: 'の#include の#includeを #include #include 「 –
panicagaming
YouTube **は欠けています!あなたの質問に適切な[mcve] **を提供してください**。 – Zulan