I'm new so apologies if my formatting is a little off. I'm writing a simple OpenMP program in order to get the hang of it, and I've been stopped completely dead in my tracks by a strange compilation error. My serial implementation compiles just fine (with gnu11), but my parallel compilation seems to fail for some reason I can't locate.
The entire code up to the point of failure is as follows (and the error I receive from make
follows thereafter)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define N_THR 1
#define MIN_SIZE 3 //NOTE: min_size is inclusive here
#ifdef _OPENMP
#include <omp.h>
#undef N_THR
#define N_THR 4
#undef MIN_SIZE
#define MIN_SIZE N_THR
//omp_set_dynamic(false); //we need to explicitly disable dynamic teams to force 4 threads
omp_set_num_threads(N_THR);
#endif
gcc maze.c -o maze
gcc maze.c -fopenmp -o mazep
maze.c:11:16: error: expected declaration specifiers or ‘...’ before numeric constant
#define N_THR 4
^
maze.c:15:22: note: in expansion of macro ‘N_THR’
omp_set_num_threads(N_THR);
^~~~~
make: *** [Makefile:5: parallel] Error 1
Is there some deep C language syntax hint I'm missing or is it something a little more obvious?
CodePudding user response:
It's because you are calling omp_set_num_threads()
outside of a function.
CodePudding user response:
omp_set_num_threads(N_THR);
I don't think you can call functions inside preprocessor blocks