Activate multi-core

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 947
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Activate multi-core

Post by marcoagpinto »

Hello!

Is there a command or option that AUTOMATICALLY makes my code use all the machine's cores?

I have been using mum's i7 4-core to produce data using my PhD project but it is still slow as hell...

I am also using my dual-core Celeron (netbook) but it takes around 18-19 hours.

Thanks!
User avatar
mk-soft
Always Here
Always Here
Posts: 5401
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Activate multi-core

Post by mk-soft »

Your code must support this ...
The use of threads is required. The distribution of the threads on the processors then the operating system for you
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Activate multi-core

Post by Fig »

What do you do ? Does your code would take advantage of parallel processing your data ?

If you want to use all your core you need Pb's thread commands.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
marcoagpinto
Addict
Addict
Posts: 947
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Activate multi-core

Post by marcoagpinto »

why can't it work out of the box?
firace
Addict
Addict
Posts: 902
Joined: Wed Nov 09, 2011 8:58 am

Re: Activate multi-core

Post by firace »

Fig wrote:What do you do ? Does your code would take advantage of parallel processing your data ?

If you want to use all your core you need Pb's thread commands.
Another proven way, which I sometimes use, is simply launching several instances of your executable, each doing separate portions of the job. The processes will nicely spread over all cores. But of course this would only work for relatively simple things.

I call it the lazy and poor man's approach to parallel processing :)
User avatar
marcoagpinto
Addict
Addict
Posts: 947
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Activate multi-core

Post by marcoagpinto »

[17:41] <marcoagpinto> red=0
[17:41] <marcoagpinto> for f=1 to 100
[17:41] <marcoagpinto> red+1
[17:41] <marcoagpinto> next f
[17:41] <marcoagpinto> -------
[17:41] <marcoagpinto> blue=0
[17:42] <marcoagpinto> for f=1 to 100
[17:42] <marcoagpinto> blue+1
[17:42] <marcoagpinto> next f
[17:42] <marcoagpinto> ----
[17:42] <marcoagpinto> :)
[17:42] <marcoagpinto> is it dangerous and hard to do?
[17:42] <marcoagpinto> :p
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Activate multi-core

Post by IdeasVacuum »

marcoagpinto
I am also using my dual-core Celeron (netbook) but it takes around 18-19 hours.
What, exactly, takes 18-19 hours? :shock:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Activate multi-core

Post by Fig »

firace wrote:Another proven way, which I sometimes use, is simply launching several instances of your executable, each doing separate portions of the job. The processes will nicely spread over all cores. But of course this would only work for relatively simple things.
I call it the lazy and poor man's approach to parallel processing :)
Good trick ! :wink:
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
marcoagpinto
Addict
Addict
Posts: 947
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Activate multi-core

Post by marcoagpinto »

IdeasVacuum wrote:marcoagpinto
I am also using my dual-core Celeron (netbook) but it takes around 18-19 hours.
What, exactly, takes 18-19 hours? :shock:
Well, I have to run simulations in possible scenarios.

121 simulations for each scenario.

Since it eats all 8 GB RAM, I divided it in three: 40 + 40 + 41.

I can only use mum's laptop when she is not there... once or twice a day.

My dual-core Celeron netbook takes 18-19 hours for each series and I leave it on most of the time to advance.
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Activate multi-core

Post by jack »

perhaps someone with experience in cloud computing could give advice?
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Activate multi-core

Post by IdeasVacuum »

...still do not know what you are doing in detail, so really impossible to help.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Activate multi-core

Post by jack »

have a look at this post by MichaelW http://www.freebasic.net/forum/viewtopi ... 46#p205146
it's about controlling which cores are used by a thread, it's not in PB but I hope it helps.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Activate multi-core

Post by Lunasole »

marcoagpinto wrote:why can't it work out of the box?
It works on some languages, not in PB.

What you need is only to write code using threads, that will lead to 100% usage of all CPU cores.
If it is hard for you to write multhithreaded code, you can do multithreading by another crude way -- running several executables simultaneously (they will run on different cores, you can use also tools like Process Hacker to easily change affinity mask of those executables).
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Activate multi-core

Post by Shield »

On Windows, the function to assign a thread to a specific CPU/core is SetProcessAffinityMask().
-> https://msdn.microsoft.com/en-us/librar ... s.85).aspx
marcoagpinto wrote:why can't it work out of the box?
Because it is impossible. Your code must specifically be designed to be able to leverage multiple cores.
If it could work "out of the box", the entire parallel process branch in computer science wouldn't exist. :)

The first question is: is it even possible to run your code multi-threaded?
You'd have to give us more information.
Another proven way, which I sometimes use, is simply launching several instances of your executable, each doing separate portions of the job.
This is exactly how it is often done when the code has not been designed to work with multiple threads, so no problem being "lazy" here. :)

__________________________________________________
URL tags added
26.04.2017
RSBasic
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
marcoagpinto
Addict
Addict
Posts: 947
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Activate multi-core

Post by marcoagpinto »

Guys,

Basically I want to do something similar to:
[17:41] <marcoagpinto> red=0
[17:41] <marcoagpinto> for f=1 to 100
[17:41] <marcoagpinto> red+1
[17:41] <marcoagpinto> next f
[17:41] <marcoagpinto> -------
[17:41] <marcoagpinto> blue=0
[17:42] <marcoagpinto> for f=1 to 100
[17:42] <marcoagpinto> blue+1
[17:42] <marcoagpinto> next f

but using more complex variables such as structured arrays and strings.

EDIT: The lines above are from IRC chat. I tried also to get help there.
Post Reply