Witam,
gdy próbuję kompilować przykładowo taki kod:
#include
#include
#include
#define NUM_LOOPS 200
int
main(int argc, char *argv[])
{
double **A;
double *u, *v;
long rows = 5000, columns = 5000;
time_t begin_t, end_t;
long i, j, k;
u = (double*)malloc(columns * sizeof(double));
v = (double*)malloc(rows * sizeof(double));
A = (double**)malloc(rows * sizeof(double*));
for (i = 0; i < rows; i++)
A[i] = (double*)malloc(columns * sizeof(double));
for (i = 0; i < columns; i++) {
u[i] = (double)(i / 1000.0f);
for ( j = 0; j < rows; j++ )
A[j][i] = (double)(i * j / 1000.0f);
}
begin_t = time(NULL);
for (k = 0; k < NUM_LOOPS; k++) {
#pragma omp parallel for shared(A, v, u, rows, columns) private(i, j)
for (i = 0; i < rows; i++) {
v[i] = 0.0f;
for (j = 0; j < columns; j++)
v[i] = v[i] + A[i][j] * u[j];
}
}
end_t = time(NULL);
printf("Czas obliczen: %f.\n", difftime(end_t, begin_t));
free(u);
free(v);
for (i = 0; i < rows; i++)
free(A[i]);
free(A);
return 0;
}
Codeblocks wywala taki komunikat:
Compiling: D:\OpenMP\main.cpp
Linking console executable: D:\OpenMP\main.exe
D:\OpenMP\main.o:main.cpp:(.text+0x175): undefined reference to `GOMP_parallel_start'
D:\OpenMP\main.o:main.cpp:(.text+0x186): undefined reference to `GOMP_parallel_end'
D:\OpenMP\main.o:main.cpp:(.text+0x26d): undefined reference to `omp_get_num_threads'
D:\OpenMP\main.o:main.cpp:(.text+0x274): undefined reference to `omp_get_thread_num'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
4 errors, 0 warnings
Co innego kiedy program skompiluje bez użycia codeblocks tylko samego kompilatora gcc z lini poleceń
mingw32-g++.exe -fopenmp program.c -o program
wtedy nie ma żadnych problemów program się kompiluje i działa jak powinien.
Żeby nie było niedomówień codeblocks także korzysta z gcc (wersja 4.4.0).
Nie jestem do końca pewien w czym tkwi problem ale widocznie codeblocks ma problem z flagą -fopenmp kiedy ją usunę program nie wywala żadnych błędów.
Proszę o pomoc.