我正在研究使用Omp的'C'並行編程。在我的模塊陣列求和parallel.c我包括第一,作爲請求,文件hpc.h是在我的C文件相同的文件夾,幷包含以下代碼:C - Unreferenced Omp函數
/*This header file provides a function double hpc_gettime() that returns the elaps
ed time (in seconds) since "the epoch". The function uses the timing routing of th
e underlying parallel framework (OpenMP or MPI), if enabled; otherwise, the defaul
t is to use the clock_gettime() function.
IMPORTANT NOTE: to work reliably this header file must be the FIRST header file th
at appears in your code.*/
#ifndef HPC_H
#define HPC_H
#if defined(_OPENMP)
#include <omp.h>
/* OpenMP timing routines */
double hpc_gettime(void)
{
return omp_get_wtime();
}
#elif defined(MPI_Init)
/* MPI timing routines */
double hpc_gettime(void)
{
return MPI_Wtime();
}
#else
/* POSIX-based timing routines */
#if _XOPEN_SOURCE < 600
#define _XOPEN_SOURCE 600
#endif
#include <time.h>
double hpc_gettime(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec + (double)ts.tv_nsec/1e9;
}
#endif
#endif
然後我包括omp.h,stdio.h中,stdlib.h中,我編譯的gcc -c -Wall -Wpedantic -fopenmp和它的確定,但是當我gcc -o -fopenmp array-sum-parallel array-sum-parallel.o
鏈接我得到這個錯誤: 陣列 - sum-parallel.c :(.text + 0x9):未定義的引用omp_set_num_threads和所有其他Omp函數。爲什麼?
的'-c'標誌'gcc'只做編譯階段,輸出文件尚未鏈接。最簡單的解決方案,如果你想編譯和鏈接在一個步驟是省略'-c' –
我100%確定你不能*執行*你從任何平臺上'gcc -c -Wall -Wpedantic -fopenmp'獲得的文件。你的意思是當你試圖鏈接它嗎? –
@AjayBrahmakshatriya是的,我的意思是鏈接抱歉。我編輯了這個問題。 – Caramelleamare