簡體   English   中英

如何在生成文件中使用 OpenMP?

[英]How to use OpenMP in a makefile?

我正在使用 Makefile 來設置 mo 代碼所需的環境。 我只是在學習並行化,非常感謝您的幫助。

# The list of packages used by the macro:
USED_PKGS = xAODRootAccess xAODTruth xAODJet xAODMissingET
test: test.o
    `root-config --ld` -o $@ `root-config --libs` \
        -L$(ROOTCOREDIR)/lib `rc get_ldflags $(USED_PKGS)` $^
clean:
    rm -f test.o
    rm -f test
.SUFFIXES: .C .o
.C.o:
    `root-config --cxx` -c -o $@ `root-config --cflags` \
        -I$(ROOTCOREDIR)/include `rc get_cxxflags $(USED_PKGS)` $<

我已經安裝了 OpenMPI 並將其添加到 PATH 和 LD_LIBRARY_PATH。

我的代碼非常簡單,只想根據 Makefile 對其進行檢查:

int main()
{
    int i;
#pragma omp parallel for
    for ( i = 0; i < 1e8; i++ )
    {
        int y = 2*i;
    }
}

好的,所以我在玩了之后自己想通了。 如果其他人正在尋找相同的東西,Makefile 應該如下所示:

# The list of packages used by the macro:
USED_PKGS = xAODRootAccess xAODTruth xAODJet xAODMissingET
test: test.o
    `root-config --ld` -o $@ `root-config --libs` \
        -L$(ROOTCOREDIR)/lib `rc get_ldflags $(USED_PKGS)` $^ -fopenmp
clean:
    rm -f test.o
    rm -f test
.SUFFIXES: .C .o
.C.o:
    `root-config --cxx` -c -o $@ `root-config --cflags` \
        -I$(ROOTCOREDIR)/include `rc get_cxxflags $(USED_PKGS)` $< -fopenmp

-fopenmp 應該添加到這兩行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM