title: Is that possible to let Fortran source code detect compiler flags?
body: <p>The question is inspired by <a href="https://stackoverflow.com/questions/66296334/openmp-with-blas">OpenMP with BLAS</a></p>
  <p>The motivation is, I want the Fortran source code to be flexible to the complier options related to serial/parallel BLAS. I may specify <code>-mkl=parallel</code> for <code>mkl</code> or <code>USE_OPENMP=1</code> for <code>lopenblas</code> in the <code>Makefile</code>.
  I may do <code>make ifort</code> or <code>make gfortran</code> or <code>make blah blah</code> to switch the libaries in the <code>Makefile</code>.
  But,</p>
  <p>a) If I use <code>-mkl=parallel</code> in the <code>Makefile</code>, I need to set <code>call mkl_set_num_threads(numthreads) </code> in the source code,</p>
  <p>b) If I use <code>OpenBLAS</code> with <code>USE_OPENMP=1</code>, I may need <code>openblas_set_num_threads(num_threads)</code> in the source code
  <a href="https://rdrr.io/github/wrathematics/openblasctl/man/openblas_set_num_threads.html#:%7E:text=threads%20to%20use.-,Details,t%20simply%20call%20R%27s%20Sys" rel="nofollow noreferrer">https://rdrr.io/github/wrathematics/openblasctl/man/openblas_set_num_threads.html#:~:text=threads%20to%20use.-,Details,t%20simply%20call%20R%27s%20Sys</a>.</p>
  <p>c) for the time being if there is only <code>lblas</code> and/or with <code>-mkl=sequential</code>, I have to manually configurate <code>dgemm</code> threads (as kind of block decomposition), regardless <code>OMP_NUM_THREADS</code>. That's ok, but I need to use <code>if</code> to control the source code goes in that way, if the source code has lines for a) and b)</p>
  <p>The manually programming <code>dgemm</code> threads in c) is somehow universal. When I would like to exploit parallel blas from libraries, things can be complicated it seems such that I don't know how to switch in source code regarding the compiler options.</p>
  <p>Addition, <code>OMP_NUM_THREADS</code> from enviroment file, <code>.bashrc</code>, is not preferable. (Sorry I should have mentioned this point earlier) The source code read an input file which specify the number of cores being used, and use <code>omp_set_num_thread</code> to set the targeted number of cores, than from the enviroment file.</p>
  <p>Addition2, from my test on <code>MKL</code>, <code>OMP_NUM_THREADS</code> cannot surpress <code>call mkl_set_num_threads</code>. Namely, I have to specify <code>call mkl_set_num_threads</code> to work with <code>-mkl=parallel</code> flag.</p>