Why is #define throwing "error: expected declaration specifiers"?
Why is #define throwing "error: expected declaration specifiers"?
我是新手,如果我的格式有点不对,请见谅。
我正在编写一个简单的 OpenMP 程序以掌握它的窍门,但由于一个奇怪的编译错误,我完全停止了我的轨道。我的串行实现编译得很好(使用 gnu11),但我的并行编译似乎由于某些我找不到的原因而失败。
直到失败点的整个代码如下(之后是我从 make
收到的错误)
#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
我是否遗漏了一些深入的 C 语言语法提示,或者它是否更明显一些?
这是因为您在函数外部调用 omp_set_num_threads()
。
我是新手,如果我的格式有点不对,请见谅。 我正在编写一个简单的 OpenMP 程序以掌握它的窍门,但由于一个奇怪的编译错误,我完全停止了我的轨道。我的串行实现编译得很好(使用 gnu11),但我的并行编译似乎由于某些我找不到的原因而失败。
直到失败点的整个代码如下(之后是我从 make
收到的错误)
#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
我是否遗漏了一些深入的 C 语言语法提示,或者它是否更明显一些?
这是因为您在函数外部调用 omp_set_num_threads()
。