I am having trouble getting a simple SAXPY program to scale its performance decently using OpenMP.
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main(int argc, char** argv){
int N = atoi(argv[1]), threads = atoi(argv[2]), i;
omp_set_num_threads(threads);
double a = 3.141592, *x, *y, t1, t2;
x = (double*)malloc(sizeof(double)*N);
y = (double*)malloc(sizeof(double)*N);
for(i = 0; i < N; ++i){
x[i] = y[i] = (double)i;
}
t1 = omp_get_wtime();
#pragma omp parallel for default(none) private(i) shared(a, N, x,y)
for(i = 0; i < N; ++i){
y[i] = a*x[i] + y[i];
}
t2 = omp_get_wtime();
printf("%f secs\n", t2-t1);
}
I am compiling as:
gcc main.c -lm -O3 -fopenmp -o prog
And the performance I get by for 10M elements is:
threads = 1 0.015097 secs
threads = 2 0.013954 secs
Any idea what is the problem I am having?