Re: [f2py] control number of OpenMP threads at runtime

Steve Schmerler <[email protected]>
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
On Sep 17 18:05 -0700, Kevin Mitchell  wrote:
> I would say it's odd that it is not recognizing the environment
> variable. You can always  check that it is visible to fortran via f2py
> with getenv http://darbujan.fzu.cz/cgi-bin/info2www?%28g77%29GetEnv+Intrinsic.
> You could also look at setting the maximum number of threads via
> omplib. If it really isn't visible for some reason, you could always
> 
>  use use(OMP_LIB)
> 
> and then omp_set_num_threads()
> http://gcc.gnu.org/onlinedocs/gcc-4.4.1/libgomp/omp_005fset_005fnum_005fthreads.html#omp_005fset_005fnum_005fthreads

Sorry for the late response.

Well what can I say .. yes it works now. I can't reproduce the case
where it didn't. The extension module reacts to OMP_NUM_THREADS. I also
added an extra input arg to the subroutine which then calls
omp_set_num_threads().

For reference, here are the relevant parts of the Makefile used to build
the extension. Thanks.

-------------------------------------------------------------------------
FILE=flib
FORT=$(FILE).f90
PYF=$(FILE).pyf
EXT_MODULE=_$(FILE)
SO=$(EXT_MODULE).so

F90=gfortran
F90FLAGS=-x f95-cpp-input 
ARCH=-mmmx -m3dnow -msse2 -msse -msse3
#
##F90=ifort
##F90FLAGS=-fpp
##ARCH=-xSSE3

# gfortran
OMP_F90_FLAGS=-fopenmp -D__OPENMP
F2PY_OMP_F90_FLAGS=-lgomp
#
# ifort 
##OMP_F90_FLAGS=-openmp -D__OPENMP 
##F2PY_OMP_F90_FLAGS=-liomp5
#
# no OpenMP
##OMP_F90_FLAGS=
##F2PY_OMP_F90_FLAGS=

F2PY_FLAGS=--opt='-O3' \
			-DF2PY_REPORT_ON_ARRAY_COPY=1 \
			--f90exec=$(F90) \
			--arch="$(ARCH)" \
			--f90flags="$(F90FLAGS) $(OMP_F90_FLAGS)" $(F2PY_OMP_F90_FLAGS)

all: $(SO)

pyf: $(PYF)

$(PYF): $(FORT)
	f2py -h $(PYF) $(FORT) -m $(EXT_MODULE) --overwrite-signature

$(SO): $(PYF) $(FORT)
	f2py -c $(PYF) $(FORT) $(F2PY_FLAGS)
-------------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.