0
I wanted to know what I can do to decrease the running time using Openmp threads. I made a code to add the values of a size 2² vector, but the time measures are practically equal when I increase the number of threads... should not drop the run time for each thread added?
#include <stdio.h>
#include <omp.h>
#include <math.h>
#include <stdlib.h>
int main(){
long int N = pow(2,27);
long int *vet = malloc(sizeof(long int)*N);
long int i;
int nThreads = omp_get_num_threads();
long int soma = 0;
for(i=0; i<N; i++) vet[i] = i;
#pragma omp parallel for reduction(+:soma)
for(i=0; i<N; i++){
soma += vet[i];
}
printf("Resultado: %ld\n", soma);
return 0;
}
Why don’t you use a string to sum these values ? , much simpler than what you’re doing.
– teste-90
Perhaps the non-parallelizable part is taking the longest run time. Test with a smaller vector or measure only the sum time. It is expected that with many threads there is no real gain, as the system consumes more resources just to scale threads and perform locks.
– user178974
I don’t know, but when I used it I didn’t put #pragma put something like #omp Parallel for reduction(+:soma)
– Junior Nascimento