I'm using Ubuntu 16.04 as Windows subsystem and gcc 5.4 version with bash. My windows version is windows 10 home, and ram is 16GB. My cpu is i7-7700HQ. I am studying computer programming at my university. These days, I am interested in parallel programming, so I've coded many codes, but there are some problems.
int i;
int sum = 0;
clock_t S, E;
S = clock();
#pragma omp parallel for reduction(+:sum)
for(i = 0 ; i < M ; i++){
sum++;
}
E = clock();
printf("\n%d :: time : %lf\n", sum, (double)(E-S)/1000);
return 0;
If I compile this code with commamd, "gcc -openmp test.c -o test" and "time ./test", it shows 100000000 :: time : 203.125000
real 0m0.311s user 0m0.203s sys 0m0.016s.
However,
int i;
int sum = 0;
clock_t S, E;
S = clock();
for(i = 0 ; i < M ; i++){
sum++;
}
E = clock();
printf("\n%d :: time : %lf\n", sum, (double)(E-S)/1000);
return 0;
if is compile this code with command, "gcc -openmp test2.c -o test2" and "time ./test2", it shows 100000000 :: time : 171.875000
real 0m0.295s user 0m0.172s sys 0m0.016s.
If I compile those codes again and again, it sometimes takes same time, but openmp is never faster.
And I edited those codes with vim.
And I tried to compile with command, "gcc -fopenmp test.c" and "time ./penmp". It takes much more time than command, "gcc -openmp test.c."
And if I compile those same codes with visual studio 2017 community, openmp is much more faster.
Please let me know how I can reduce time with openmp.