I have Parallel Scan Algorithm: Hillis & Steele (1986) and I want to execute inner for loop parallel.
Error C3015 initialization in OpenMP 'for' statement has improper form OpenMP c:\users\matja\documents\visual studio 2015\projects\psseminar\openmp\main.c
#include <omp.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <windows.h>
// ...
for (long long m = 0; m < M; m++)
{
long long offset = (long long)pow(2, m);
#pragma omp parallel for firstprivate(N, m, offset)
for (long long n = offset; n < N; n++)
{
long long ai = n - offset;
long long bi = n;
// ...
}
}
// ...
According to MSDN, the error that OP posted is raised when the OpenMP for is not fully explicited. This may happen because the compiler does not fully understand the C99 language used by the statement
for (long long n = offset; n < N; n++)
Despite I don't have a Visual C++ compiler, I see that gcc 4.8.5 and icc 16.0.3 fail to compile it requiring the code to be compiled with the appropriate C99 language variant (i.e.
-std=c99). After googling a bit I have not found the proper flag for MSVC (in fact, wikipedia claims that support ins MSVC 2013 was limited (see)). So one alternative you could try is to convert that code into
long long m; for (m = 0; m < M; m++) { long long offset = (long long)pow(2, m); long long n; #pragma omp parallel for firstprivate(N, m, offset) for (n = offset; n < N; n++) { long long ai = n - offset; long long bi = n; // ... } }
Additionally, note that you probably can get rid off the
firstprivate clause for
N,
m and
offset and change them into
shared if you dont modify within the parallel loop.
BTW, I disagree with user6716329's answer where they claim that
#pragma omp parallel for is restricted to
int or
unsigned int because the following code works flawslessly in either gcc 4.8.5 and icc 16.0.3.
#include <omp.h> #include <stdio.h> void main (void) { long long m; #pragma omp parallel for schedule for (m = 0; m < 16; m++) { printf ("thread = %d, m = %d\n", omp_get_thread_num(), m); } }