我正在尝试配置我的netbeans来处理我的并行编程C ++代码。我可以使用命令行(cygwin)编译该代码,但现在为了进一步调试和编码更复杂的事情,我想转移到一些IDE和选择的neatbeans来完成我的任务。有人建议我在netbeans中单击构建我的应用程序按钮后,如何添加-fopenmp
来编译我的应用程序。 (已经使用netbeans_配置了GCC和G ++。以下是我使用netbeans构建代码时出现的错误:
cd 'D:\University\PARALLEL\ParallelTesting'
C:\dev_softwares\cygwin64\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/d/University/PARALLEL/ParallelTesting'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/paralleltesting.exe
make[2]: Entering directory '/cygdrive/d/University/PARALLEL/ParallelTesting'
mkdir -p dist/Debug/Cygwin-Windows
g++ -o dist/Debug/Cygwin-Windows/paralleltesting build/Debug/Cygwin-Windows/main.o
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/d/University/PARALLEL/ParallelTesting/main.cpp:26: undefined reference to `omp_get_thread_num'
/cygdrive/d/University/PARALLEL/ParallelTesting/main.cpp:26:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `omp_get_thread_num'
/cygdrive/d/University/PARALLEL/ParallelTesting/main.cpp:32: undefined reference to `omp_get_num_threads'
/cygdrive/d/University/PARALLEL/ParallelTesting/main.cpp:32:(.text+0x34): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `omp_get_num_threads'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/Cygwin-Windows/paralleltesting.exe' failed
p.s:并行编程世界的新手,已经使用netbeans配置了gcc。
我的测试并行代码:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int nthreads, tid;
/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
} /* All threads join master thread and disband */
}