Hello
I have a code where I need to initialise a massive array with random numbers. For increasing problem size, this part of the program is becoming a drag. I want to use Intel VSL to do this, but I'm having trouble meshing the current problem with the indended use of the VSL routines.
Code:
for (i = 0; i < N1; i++) { for (j = 0; j < N2; j++) { for (k = 0; k < N3; k++) { DP0[i][j][k] = 0.0; P0[i][j][k] = drand48() * 2.0 - 1.0; } } }
This is my first attempt to implement it in parallel:
/* Implement parallel RNG with Intel VSL */ VSLStreamStatePtr* stream = (VSLStreamStatePtr *) malloc(nthreads * sizeof(VSLStreamStatePtr)); // Initialise the streams for( i=0; i<nthreads; i++) { vslNewStream(&stream[i], VSL_BRNG_MT2203+i, SEED); } double t0 = omp_get_wtime(); #pragma omp parallel for private(i,j,k,l) for (i = 0; i < N1; i++) { for (j = 0; j < N2; j++) { for (k = 0; k < N3; k++) { DP0[i][j][k] = 0.0; vdRngUniform( METHOD, stream[omp_get_thread_num()], 1, &P0[i][j][k], -1.0, 1.0 ); } } }
Two things are troubling me:
1. For test case of N1=N2=N3=512. The original with dran48() runs in 1.5s single threaded. The new version runs in 5s in seral. It scales with more threads. Now is this serial time difference to be expected since I'm using another BRNG? I have no idea about relative performance between the two.
2. VSL is about vectors! My implementation is scalar because I also want to initialise DP0 to 0.0 at the same time. Can the intel compiler vectorise the k loop so that the DP0 and P0 are vectorised? The vec-report is complaining about non-existance flow dependencies between DP0 and P0.
Thanks.
James