Forum > General

Parallel procedures

(1/2) > >>

beria:
Question! An important one! Urgent! I hope who knows...
 Is it possible to write a procedure in FPC which is guaranteed to work outside of using the main program thread, even if it is pending and idle with zero load.....  That is, in any case, involving only and exclusively other physical and logical processors. If anything, I use the standard calls of the "MTProcs" module, but it's no problem to rewrite everything for any alternate library as well...
The methods built into the LCL interface biblioteks are not suggested, because I don't use them at all...
ps: I suspect that the question is very simple, but I really didn't understand it, even after reading all the written sources.... :-(
pps: it's the third day I can't figure it out...


Arioch:

--- Quote from: beria on October 08, 2022, 03:41:12 pm ---procedure in FPC which is guaranteed to work outside of using the main program thread, even if it is pending and idle with zero load

That is, in any case, involving only and exclusively other physical and logical processors. If anything, I use the standard calls of the "MTProcs" module, but it's no problem to rewrite everything for any alternate library as well...

--- End quote ---

Those all are different things.

1. running in other thread (on any core)
2. running on different virtual core (any physical core) - not every CPU have (and have enabled) HyperThreading or SMT; AMD Bullldozer cores are half-phyisical half-virtual, flamewars about properly counting and comparing them to Intel HT cores were fierce
3. running on different physical core (on any processor)
4. outside on different processor  - not many mainboards today have more than one processor

What exactly do you want and why?

What should your procedure do if called from main thread?

What does "other core/processor" even mean when main thread "is pending and idle with zero load"?
What you said in other words means the main thread does not exist this moment on none of the cores at all, every core this moment is "different" core.

beria:

--- Quote from: Arioch on October 08, 2022, 03:51:54 pm ---
--- Quote from: beria on October 08, 2022, 03:41:12 pm ---procedure in FPC which is guaranteed to work outside of using the main program thread, even if it is pending and idle with zero load

That is, in any case, involving only and exclusively other physical and logical processors. If anything, I use the standard calls of the "MTProcs" module, but it's no problem to rewrite everything for any alternate library as well...

--- End quote ---

Those all are different things.

1. running in other thread (on any core)
2. running on different virtual core (any physical core) - not every CPU have (and have enabled) HyperThreading or SMT; AMD Bullldozer cores are half-phyisical half-virtual, flamewars about properly counting and comparing them to Intel HT cores were fierce
3. running on different physical core (on any processor)
4. outside on different processor  - not many mainboards today have more than one processor

What exactly do you want and why?

What should your procedure do if called from main thread?

What does "other core/processor" even mean when main thread "is pending and idle with zero load"?
What you said in other words means the main thread does not exist this moment on none of the cores at all, every core this moment is "different" core.

--- End quote ---
No argument. That's a poor way of putting it. I'll try a better one...
How to make the procedure use only those physical (logical) processors that are outside the main program thread....
That is, at the moment of start of a parallelized computing procedure, the load on that thread which provides the main program's logic should not change in any way...
At the moment, the default logic for the console application, as can be seen by the CPU load, evenly and equally, loads all the existing physical and logical processors....
Or alternatively, I need to define the whole program as one of the threads, and then let the thread manager manage them by its own logic, but this is not at all what I want....

MarkMLl:

--- Quote from: beria on October 08, 2022, 05:48:07 pm ---How to make the procedure use only those physical (logical) processors that are outside the main program thread....

--- End quote ---

You've not told us what OS you're running. On unix you'd use whatever facilities are available to set process affinity... which might or might not separate things at the thread level (you need to consider the implication of multiple threads sharing memory, which can play havoc on a system with multi-level cache).

MarkMLl

Arioch:
> That is, at the moment of start of a parallelized computing procedure, the load on that thread which provides the main program's logic should not change in any way...

In relaxed term - you need to set your computing thread to be low-priority, so the main thread would keep having upper hand over it, if they clash.

And i think that is not possible in general terms - there are dozens if not hundreds of other processes in the system and you are not in control of their load.
They can increase their own load any second, which would possbily be added burden to your CPU cache and execution units.

I believe in the end CPU afifnity is up to OS administartor to decide, not to the program.

It seems you want your main thread to exclusively own some CPU core and not let anyone else share it.
If i would notice any program on my 3-cores desktop trying to pull it behind my back - i would be very upset.

So it seems you have to provide documentation to OS administrators how to setup their OS to make best use of your program, IF they would opt-in. They, not you.

https://en.wikipedia.org/wiki/Processor_affinity
https://stackoverflow.com/questions/1407786/how-to-set-cpu-affinity-of-a-particular-pthread
https://stackoverflow.com/questions/762961/setthreadaffinitymask-is-ignored-any-ideas
https://winbuzzer.com/2020/07/03/how-to-set-cpu-affinity-in-windows-10-with-task-manager-or-system-properties-xcxwbt/
https://windowsnotes.ru/powershell-2/nastrojka-processor-affinity-s-pomoshhyu-powershell/

et cetera

Navigation

[0] Message Index

[#] Next page

Go to full version