first post!
major edit..
I’ve got this program for computing a dot product, compiled using gcc with -fopenmp. The problem is, it’s not creating the number of threads that I tell it to create. On one computer it will constantly spawn 2 threads, on another 4. Neither of those numbers are the numbers given to them. I’m using the (static, chunksize) scheduling which is an indirect way of being able to choose how many threads I want created by changing the chunksize. I feel like there’s something in the runtime that’s overriding my instructions, since all the computers are using the same executable. I’ve also noticed that if I give the program a chunksize that’s equal to the total load, it will use one thread but still spawn the same number of threads that it was before. What am I doing wrong?
#pragma omp parallel shared(vector1, vector2, loadsize, vectorsize, final_sum) private(i, threadsum, threadid)
{
threadsum = 0;
threadid = omp_get_thread_num();
#pragma omp for schedule(static, loadsize)
for (i = 0; i < vectorsize; i++){
threadsum += vector1[i] * vector2[i];}
printf("thread %d reached up to index %d with a sum of %d\n", threadid, (i-1), threadsum);
#pragma omp critical
final_sum += threadsum;
}
printf("final sum: %d", final_sum);
Thanks,
Zak
As far as I know, the chunksize represents the amount of work to be performed by the thread. It never controls the spawning of the threads. As you can see from your code, the threads are spawned when you invoke
Not when you invoke
The static and dynamic scheduling are used to determine the amount of work allocated to a thread, either at compile time or run time. So, don’t confuse scheduling to the number of threads.
If you need to control the number of threads, use