[問題] OMP問題

看板C_and_CPP作者 (小涼)時間10年前 (2013/10/18 14:23), 編輯推噓2(202)
留言4則, 1人參與, 最新討論串1/1
我是用 dev c++5.5 gcc 4.7.1 還有 將-fopenmp放到 compiler option->general 的第一欄位 (看網路來試著做) 測試一個for迴圈 很簡單 如下 #include <stdio.h> #include <omp.h> #define N 3 int main() { int c[N][N]; int i,j; #pragma omp parallel for private(i,j) for (j = 0; j < N; j++) { for (i = 0; i < N; i++) { c[i] [j]=i*j ; printf("Thread %d: c[%d][%d] =%d\n", omp_get_thread_num(),i,j, c[i][j]); } } return 0; } runing Thread 1: c[0][1] =0 Thread 1: c[1][1] =1 Thread 1: c[2][1] =2 Thread 2: c[0][2] =0 Thread 2: c[1][2] =2 Thread 2: c[2][2] =4 Thread 0: c[0][0] =0 Thread 0: c[1][0] =0 Thread 0: c[2][0] =0 我就直接改我專案 加 #include <omp.h> 在for迴圈前都加一個 #pragma omp parallel for private( ) 結果出現 main.o main.c:(.text+0x2ba):undefined reference to `GOMP_parallel_start' main.o main.c:(.text+0x2ce):undefined reference to `GOMP_parallel_end main.o main.c:(.text+0xac7):undefined reference to `omp_get_num_threads'' main.o main.c:(.text+0xace):undefined reference to `omp_get_thread_num' c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe main.o: bad reloc address 0x0 in section `.pdata' c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe final link failed: Invalid operation 搞不懂?? 找網路資料還是不清楚 來這裡求解 還有請問 for 內 有要連到其他函式(ex gradx) for(i=0;i<N;i++) { c[i]=gradx(&wk[xcp+i]); } omp適合嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.120.96 ※ 編輯: scws 來自: 140.115.120.96 (10/18 14:29)

10/18 19:06, , 1F
你dev c的linker有沒有添加 -fopenmp的選項?
10/18 19:06, 1F

10/18 19:06, , 2F
除了compile要加 linker也要加
10/18 19:06, 2F
我看到我的linker 內是-static-libgcc 所以要將它換成 -fopenmp囉?? 我現在是一個專案形式 那麼project option 內 parameter下的compile和linker 也要加-fopenmp 嗎? 感謝你!! ※ 編輯: scws 來自: 123.110.187.47 (10/18 23:25)

10/22 10:44, , 3F
我是用codeblock 他是linker compiler都有地方讓你加
10/22 10:44, 3F

10/22 10:44, , 4F
參數
10/22 10:44, 4F
文章代碼(AID): #1IODFxYW (C_and_CPP)