Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7679 Discussions

Intel c + + compiler multithreading, out-of-order execution loop

qingkong_y_
Beginner
287 Views

Hi,

     When I use MVC++ compiler running normally, using Intel c++ compiler the loop execution out-of-order(thread = 1).

The following code:

mNumberOfWorkers=1;

 HANDLE *flag = new HANDLE[mNumberOfWorkers];
 InitializeCriticalSection(&mcsOS);
 for(int i=0; i<mNumberOfWorkers; i++)
 {
  flag=(HANDLE)_beginthreadex(0,0,(unsigned int(__stdcall*)(void*))OSGeoWorker,this,0,0);
 }
 WaitForMultipleObjects(mNumberOfWorkers, flag, true, INFINITE);
 for (int h = 0; h < mNumberOfWorkers; h++)
 {
  CloseHandle(flag);
 }
 delete[] flag;
 DeleteCriticalSection(&mcsOS);

for (int i=0, imax=Size; i<imax; i++)
 {
  image=0.0f;
 }

     The above function OSGeoWorker is not over, When the program execution to image=0.

     The function OSGeoWorker and loop(for (int i=0, imax=Size; i<imax; i++)) run alternately.

     how can I find the error in the program?

     Thank you !

 

 

 

0 Kudos
8 Replies
TimP
Black Belt
287 Views

Do you use equivalent compiler optimization levels for the 2 compilers, e.g.

/Ox /fp:precise for both

or

/Ox /fp:fast for MSVC++ and /Ox /fp:source for ICL?

MSVC has no optimization as aggressive as the ICL defaults.

qingkong_y_
Beginner
287 Views

  The optimization levels of two compilers are same.Has been checked.

Bernard
Black Belt
287 Views

Do you mean that single thread which is executing OSGeoWorker did not terminate? Did you check any terminating conditions inside aferementioned function like: infinite loops?

qingkong_y_
Beginner
287 Views

OSGeoWorker did not terminate.  And the loop executes only 2 or 3 times, than jump to the following loop.

(for (int i=0, imax=Size; i<imax; i++)
 {
  image=0.0f;
 })

Yuan_C_Intel
Employee
287 Views

Hi, Qingkong

I seems cannot reproduce this with a simple test case using your code snippet.

What's the Intel compiler version you are using? And how about the compiler options?

A reproducible test case is preferred to root cause the problem.

Thanks.

Bernard
Black Belt
287 Views

So the function did not terminate.

I think that my advise is still valid. You should check what is happening inside OSGeoWorker function.

Bernard
Black Belt
287 Views

@Qingkong

Can you post source code of OSGeoWorker function?

qingkong_y_
Beginner
287 Views
I found the error. INFINITE set error. Function OSGeoWorker didn't work. Still thank you for your help!
Reply