Page 1 of 2

Activate multi-core

Posted: Wed Apr 19, 2017 4:24 pm
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!

Re: Activate multi-core

Posted: Wed Apr 19, 2017 4:33 pm
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

Re: Activate multi-core

Posted: Wed Apr 19, 2017 5:16 pm
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.

Re: Activate multi-core

Posted: Wed Apr 19, 2017 5:35 pm
by marcoagpinto
why can't it work out of the box?

Re: Activate multi-core

Posted: Wed Apr 19, 2017 5:49 pm
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 :)

Re: Activate multi-core

Posted: Wed Apr 19, 2017 5:52 pm
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

Re: Activate multi-core

Posted: Wed Apr 19, 2017 6:03 pm
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:

Re: Activate multi-core

Posted: Wed Apr 19, 2017 6:10 pm
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:

Re: Activate multi-core

Posted: Wed Apr 19, 2017 6:11 pm
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.

Re: Activate multi-core

Posted: Wed Apr 19, 2017 6:32 pm
by jack
perhaps someone with experience in cloud computing could give advice?

Re: Activate multi-core

Posted: Wed Apr 19, 2017 8:12 pm
by IdeasVacuum
...still do not know what you are doing in detail, so really impossible to help.

Re: Activate multi-core

Posted: Thu Apr 20, 2017 6:02 pm
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.

Re: Activate multi-core

Posted: Thu Apr 20, 2017 6:09 pm
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).

Re: Activate multi-core

Posted: Thu Apr 20, 2017 6:10 pm
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

Re: Activate multi-core

Posted: Fri Apr 21, 2017 9:49 am
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.