0

我正在使用 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;
    }
}
4

1 回答 1

1

好的,所以我在玩了之后自己想通了。如果其他人正在寻找相同的东西,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 应该添加到这两行。

于 2018-09-18T08:00:18.200 回答