nico.ocin
nico.ocin

Reputation: 101

Makefile ignores the command export OMP_NUM_THREADS

I'm compitling and running a C++ program with openMP, with the following makefile

all:        
            g++ -std=c++0x -O2 -fopenmp main.cpp body.cpp -o test
            export OMP_NUM_THREADS=4
            ./test

the variable OMP_NUM_THREADS is ignored, while if i give the three commands manually in the terminal (in the same order), the variable is taken into account and the program runs with the desired number of nodes. Running everything from the terminal has the effect that the OMP_NUM_THREAD variable is whichever value has been set manually before. In the program itself, the variable is untouched, so the program runs just with the number of available nodes.

Thanks a lot for the help!

Ps. Does someone have a good tip on a link/document/video for a nooby introduction to bash programming?

Upvotes: 2

Views: 2248

Answers (2)

Nikolay Hidalgo Diaz
Nikolay Hidalgo Diaz

Reputation: 568

Makefile by default invokes separate shell for each command, this is why the command "export VARIABLE=value" does not affect the commands below, unless .ONESHELL special target appears in the Makefile.

Upvotes: 0

MichaelGoren
MichaelGoren

Reputation: 1001

Move your variable assignment and the export directive from the target part ("all") to the definition part as following:

OMP_NUM_THREADS=4
export OMP_NUM_THREADS

all:        
            g++ -std=c++0x -O2 -fopenmp main.cpp body.cpp -o test
            ./test

Upvotes: 1

Related Questions