My project is in c and visual studio 2022. This for loop compiles fine with "Open MP Support" set to "No" in the C/C++ language properties.
#pragma omp parallel for
for (int i=0; i < 10; i++)
{
printf("numThreads = %d\n", omp_get_num_threads());
}
The problem was that it'd never use more than one thread even though omp_get_max_threads() told me there were 24 available.
So i went and enabled Open MP Support, and now the same for loop gives me the following error when i build: "initialization in OpenMP 'for' statement has improper form"
But my loop is very basic and seems to follow the guidelines. I would appreciate help understanding what's causing this.
Also, when i changed the code to:
#pragma omp parallel
for (int i=0; i < 10; i++)
{
printf("numThreads = %d\n", omp_get_num_threads());
}
it compiled, but did not work as I expected, and according to another stack overflow post:
#pragma omp parallel for instructs the comiler to parallelize the next for block. With #pragma omp parallel alone, you have many threads who run the same code. I.e. each thread runs the whole for cycle. The slow down comes from race conditions when several/all threads try to access the same memory. This is rookie mistake number one in using OpenMP.
so I'm definitely trying to use #pragma omp parallel for.