Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Mick_Pont
Beginner
53 Views

omp_set_num_threads broken with /iface:cvf on Windows

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
3 Replies
Mick_Pont
Beginner
53 Views

Sorry - I just realised I accidentally posted this in the MKL forum instead of the ifort compiler forum.
I will re-post in the correct place.

Mick
Andrey_C_Intel1
Employee
53 Views

Hi Mick.

Your request cannot be solved in compiler's library. The reason is that you want to use the same function and to pass parameter to it using different calling conventions. This will never work, because the function cannot "guess" if it gets the parameter by value or by reference.

In order to not write complex interfaces for all standard OpenMP routines you should usestandard moduleor header provided by the compiler,you can choose any when you need to use OpenMP routines:
useomp_lib
or
include "omp_lib.h"

Using module is prefered variant.Then you can safely specify any allowed calling convention for your own routines.

Regards,
Andrey
SergeyKostrov
Valued Contributor II
53 Views

Quoting Mick Pont
...
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.
...

Hi Mick,

Didthe applicationreally created 32,768 OpenMP threads?
How much memory was allocated forthe application in thatcase?

Best regards,
Sergey
Reply