简体   繁体   中英

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

Each line of the recipe is run in a separate shell. So in this case, you're running one shell, setting OMP_NUM_THREADS , then exiting that shell and running another one (without that variable).

You can just put the variable definition and the call to cowichan_openmp on the same line:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM