Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Discussions

omp_set_num_threads broken when compiling with iface:cvf

Mick_Pont
Beginner
466 Views
The omp_set_num_threads() function seems not to have an iface:cvf variant available.
I'm using this compiler:
Intel Visual Fortran Compiler XE for applications running on IA-32, Version 12.1.0.233 Build 20110811
on a 32-bit Windows system.

Take this program proga.f90:

Program main
Integer, External :: omp_get_max_threads
External :: omp_set_num_threads
Integer maxthd
maxthd = 2
Write(*,*) 'maxthd = ', maxthd
Call omp_set_num_threads(maxthd)
Write(*,*) 'omp_get_max_threads() returns ', omp_get_max_threads()
End Program main

and compile it like this:

ifort /Qopenmp proga.f90

Running it you get the expected results:
proga.exe
maxthd = 2
omp_get_max_threads() returns 2

But if you switch on /iface:cvf this happens:

ifort /Qopenmp /iface:cvf proga.f90
proga.exe
maxthd = 2
omp_get_max_threads() returns 32768

In a real OpenMP program that leads to a major resource problem.

I suspect that there is no CVF variant of omp_set_num_threads, and the __cdecl variant always gets linked in instead. If I modify my program to introduce an explicit interface for omp_set_num_threads(), telling the compiler that omp_set_num_threads is in fact __cdecl like this:

Module CPROC
Interface
Subroutine omp_set_num_threads(n)
!DEC$ ATTRIBUTES C :: omp_set_num_threads
End Subroutine omp_set_num_threads
End Interface
End Module CPROC
Program main
Use cproc
Integer, External :: omp_get_max_threads
! external omp_set_num_threads
Integer maxthd
maxthd = 2
Write(*,*) 'maxthd = ', maxthd
call omp_set_num_threads(maxthd)
Write(*,*) 'omp_get_max_threads() returns ', omp_get_max_threads()
End Program main

then everything works fine.

Mick Pont
0 Kudos
1 Reply
Steven_L_Intel1
Employee
466 Views
Yes, we've had that reported before. The OpenMP library people tell me that the STDCALL routines in the library are not supported and that they will be removed. Include omp_lib.f90 to get the correct declarations.
0 Kudos
Reply