Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7833 Discussions

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

qingkong_y_
Beginner
485 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
485 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.

0 Kudos
qingkong_y_
Beginner
485 Views

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

0 Kudos
Bernard
Black Belt
485 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?

0 Kudos
qingkong_y_
Beginner
485 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;
 })

0 Kudos
Yuan_C_Intel
Employee
485 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.

0 Kudos
Bernard
Black Belt
485 Views

So the function did not terminate.

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

0 Kudos
Bernard
Black Belt
485 Views

@Qingkong

Can you post source code of OSGeoWorker function?

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