Search code examples
c++makefileopenmp

Change value of a variable in makefile


So, im trying to change the value of threads in openMP using OMP_NUM_THREADS. When i type export OMP_NUM_THREADS=value in prompt it works fine, it changes the number of threads, but when i try to do this in a makefile it doesn't work. My makefile:

run:
export OMP_NUM_THREADS=4
./cowichan_openmp vecdiff >> out

Solution

  • The reason is, that every line is executed in a new subshell. Also see here.

    You may try:

    run: export OMP_NUM_THREADS=4 ./cowichan_openmp vecdiff >> out

    or as in another answer:

    run: OMP_NUM_THREADS=4 ./cowichan_openmp vecdiff >> out