Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Open MP and Win32 APIs

spawn
Beginner
893 Views
1)Can OpenMP be used with Win32 API calls within, say, a simple "for" loop?

Example:

#pragma omp parallel for
for(...)
win32_api (i.e. OpenProcess);

2)I have separate threads calling the same Win32 APIs (i.e. OpenProcess). Is this thread-safe?

Thanks!
0 Kudos
1 Reply
ClayB
New Contributor I
893 Views
Spawn -

On Windows, the Intel OpenMP implementation is built on the Windows APIs, so use of other Win32 API functions should work. However, if you have a specific failure that you are experiencing, please report the problem to Intel through Premier Support.

Since OpenMP is designed for "synchronous" compute-bound computations, it may not be appropriate to use Windows threading functions within OpenMP parallel regions. Interactions of OpenMP synchronization points and blocking API calls could adversely affect performance.

As for your second question, if an API call can be used within a (Win32) threaded code, there should be no problems with using that call within an OpenMP parallel region. I expect documentation from Microsoft(?) would be able to give more specific details of thread safety for Windows API functions.

Besides thread safety, you need to consider algorithmic safety when calling API functions from OpenMP threads. Do you mean to have each thread call the function (i.e., every thread opens a different output file) or should only one thread be calling the routine (i.e. TerminateProcess). If the latter is the case, you should put the API calls in a master or single region within the parallel region.

Just to satisfy my curiosity, can you tell us what sort of application you are using this combination of APIs?

-- clay
0 Kudos
Reply