I'm trying to use a parallel code in c++ program using open-MP. this Code without openmp runs well. I see this crash in line 65 and 66 when parallel code is solved .
Exception thrown at 0x00007FF6021F251F in openmp.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
my code is:
#include <stdio.h>
#include <iostream>
#include <omp.h>
#include <math.h>
#include <Windows.h>
using namespace std;
int i, j, m;
double**** g, **** f;
int n = 50;
LARGE_INTEGER StartingTime, EndingTime, ElapsedMicroseconds;
LARGE_INTEGER Frequency;
int main()
{
QueryPerformanceFrequency(&Frequency);
QueryPerformanceCounter(&StartingTime);
f = new double*** [n];
g = new double*** [n];
for (int i = 0; i < n; i++)
{
f[i] = new double** [n];
g[i] = new double** [n];
for (int j = 0; j < n; j++)
{
f[i][j] = new double* [n];
g[i][j] = new double* [n];
for (int k = 0; k < n; k++)
{
f[i][j][k] = new double[n];
g[i][j][k] = new double[n];
}
}
}
# pragma omp parallel
{
m = omp_get_num_procs();
printf("number of processor= %d \n", m);
m = omp_in_parallel();
printf("if program in paralle=1 or serial=0 ?? %d \n", m);
m = omp_get_max_threads();
printf("muaximum number of thread= %d \n", m);
m = omp_get_num_threads();
printf("number of threads= %d \n", m);
m = omp_get_thread_num();
printf("thread number is= %d \n", m);
#pragma omp for schedule (static,10)
for(i=0 ; i <n ;i++)
for (j = 0; j < n; j++)
for(int k=0;k<n;k++)
for(int a=0;a<n;a++)
{
f[i][j][a][k] = 1;
g[i][j][a][k] = 2;
}
}
QueryPerformanceCounter(&EndingTime);
ElapsedMicroseconds.QuadPart = EndingTime.QuadPart - StartingTime.QuadPart;
ElapsedMicroseconds.QuadPart *= 1000000000;
ElapsedMicroseconds.QuadPart /= Frequency.QuadPart;
cout << "time : " << ElapsedMicroseconds.QuadPart << endl;
}
Can you help me solve the problem?
User contributions licensed under CC BY-SA 3.0