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

Reserving a core for a thread

dondilworth
New Contributor II
7,484 Views
My multi-threaded program works, but I find that running with several cores actually takes longer than does a single-thread run. Here's what is going on:

1. Several threads are started. They each go into a DO WHILE loop, waiting for a flag in an indexed variable in a named COMMON block.

2. When the flag is set, the thread starts some serious number crunching, using data taken from another indexed set of variables. When the routine finishes, it sets another flag, also in an indexed array.

3. The calling program waits until all threads have finished, checking the flags in another DO WHILE loop, and then reads out the answers from the indexed variables. Then it starts over with another set of input data, and so on.

This should run faster with several threads running in parallel, but it doesn't. Possible reasons:

1. One of the threads is in a core being used by Windows for something else. It cannot complete its task until Windows lets it run, and the calling program has to wait for that.

2. The several threads do not in fact run in parallel. If they go individually, that would also be very slow.

Is there any way to ensure that my threads get their own cores, and they all run in parallel?
0 Kudos
43 Replies
dondilworth
New Contributor II
624 Views
This is more or less what I experience: too many threads slows things down. Anyway, it's time to move on. I can get a slight improvement in speed with some problems, but a decrease with others. I conclude that OpenMP is a nice idea -- but one that does not work very well for the kind of problems I have. Had to try it, and I'm glad I posted in this forum. I appreciate all of the intelligent suggestions made by the posters. But there is no simple solution that works well and reliably. I'll use the feature in the cases when it works, and not worry about it otherwise.

Thank you, everyone.
0 Kudos
jimdempseyatthecove
Honored Contributor III
624 Views
>> I conclude that OpenMP is a nice idea -- but one that does not work very well for the kind of problems I have. Had to try it, and I'm glad I posted in this forum.

I am glad you gave it a try.

If compute time is a serious concern, then I would suggest you have a more experienced programmer look at the application as a whole. I expect that they will see something that you have been unable to convey to us on this forum.

Jim Dempsey
0 Kudos
Reply