Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
parallalization and taskset
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 22

PostPosted: Sat Nov 16, 2024 9:13 pm    Post subject: parallalization and taskset Reply with quote

is it possible have parallalization with taskset?
Code:

m@localhost ~/Desktop/bitmap $ time taskset -c 1 ./desc  && time taskset -c 2 ./desc  && time taskset -c 3 ./desc  && time taskset -c 4 ./desc

real   0m0.019s
user   0m0.013s
sys   0m0.006s

real   0m0.014s
user   0m0.013s
sys   0m0.001s

real   0m0.012s
user   0m0.011s
sys   0m0.001s

real   0m0.012s
user   0m0.012s
sys   0m0.000s


four instance of the program are executed simultaniously with save time?
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22677

PostPosted: Sat Nov 16, 2024 11:32 pm    Post subject: Reply with quote

Why are you using taskset at all? If you want four instances, run four instances:
Code:
for a in {0..3}; do ./desc & done; wait
Let the scheduler sort out where to run them.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 22

PostPosted: Sun Nov 17, 2024 11:07 am    Post subject: Reply with quote

With your method i have no guarante its parallelized in different core with taskset instead i have guarante. Or not?
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22677

PostPosted: Sun Nov 17, 2024 3:48 pm    Post subject: Reply with quote

With taskset, you guarantee that each task either runs on the specified core or, if that core is not available, does not run at all. Without taskset, you let the scheduler pick which core to run each one on, and it will try to run as many things in parallel as you have cores available. Why do you think you need to force particular core assignments for particular processes?
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 22

PostPosted: Sun Nov 17, 2024 4:45 pm    Post subject: Reply with quote

Are you sure that its sufficient & for have parallalization?
I read somewhere that its not sure this
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22677

PostPosted: Sun Nov 17, 2024 5:09 pm    Post subject: Reply with quote

& tells the shell to place the command in the background. Where did you read that this would not work? Have you tried the command I gave you? What went wrong?
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 22

PostPosted: Sun Nov 17, 2024 6:31 pm    Post subject: Reply with quote

Im under c++ and that command no works, i use a series of system(./desc &) or something similar is it correct? Will it works?
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22677

PostPosted: Sun Nov 17, 2024 7:39 pm    Post subject: Reply with quote

If you are using system from C++, why is your opening post expressed as shell? Rather than asking if something will work after I told you it will, why not try it and report whether it works?

I think you should provide a Minimum Reproducible Example demonstrating your problem.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 22

PostPosted: Sun Nov 17, 2024 7:48 pm    Post subject: Reply with quote

Indeed i was wrong im tryng in shell before c++, dont you think its the same? I dont make c++ code yet, do you think system(./desc &) will work and save time with parallelization i wish?
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22677

PostPosted: Sun Nov 17, 2024 8:00 pm    Post subject: Reply with quote

I gave you a loop that should work. I later reiterated that I expect it to work. Yes, system should work fine, since, according to its manual page, that is delegating back to the shell, which is almost always the wrong thing to do in a C++ program. If you need further help, please demonstrate a specific problem.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 22

PostPosted: Sun Nov 17, 2024 8:31 pm    Post subject: Reply with quote

I will make the code c++ in days.
Why its wrong thing which is the correct form? Maybe thread or something similar?
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1701
Location: South America

PostPosted: Sun Nov 17, 2024 8:45 pm    Post subject: Reply with quote

Because a C++ program can do things like spawning processes by using the libc directly (or through some convenience library) instead of invoking the shell.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)


Last edited by GDH-gentoo on Sun Nov 17, 2024 8:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3434

PostPosted: Sun Nov 17, 2024 8:45 pm    Post subject: Reply with quote

Marcofras, you're bouncing around too much. Pause for a minute and focus.
What are you _actually_ trying to do?
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 22

PostPosted: Mon Nov 18, 2024 11:04 am    Post subject: Reply with quote

parallalization, because i had no success with thread (in the past) im opting to divide the program in several subprograms and run parallelized, it seems more easy.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3434

PostPosted: Mon Nov 18, 2024 12:02 pm    Post subject: Reply with quote

Eh... This is clearly a case of https://en.wikipedia.org/wiki/XY_problem.
Regarding your original question:
> is it possible have parallalization with taskset?
The only correct answer is: "Yes but no". Unfortunately, on top of being correct, it is also completely useless.

Parallelization where? Why did you start with shell and then you're suddenly going to cpp? This part is confusing.
More importantly: What is the thing you're trying to write there? What is the problem you're trying to solve? What is standing in your way?

> I think you should provide a Minimum Reproducible Example demonstrating your problem.
Yeah, I second that. Although this technique is primarily used for reporting bugs, it does help with communication in general.
Overkill is still a kill.
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22677

PostPosted: Mon Nov 18, 2024 12:30 pm    Post subject: Reply with quote

Yes, a Minimum Reproducible Example might be overkill here. I asked for it because OP's questions implied to me that he had directly experienced shell background not to exhibit the desired parallelism that I had stated would work. If he was experiencing that lack, we could try to understand why. If he has not tried the solutions given to him, I would like for him to do so or explain why not (particularly since this should be easy to test, due to being independent of the content of ./desc), before we put more work into assuring him again that his doubts are misplaced.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 22

PostPosted: Mon Nov 18, 2024 2:41 pm    Post subject: Reply with quote

the original problem is i need parallalization for save time, i tried thread in desc that parallelize the function shap but it doesn' t work and freeze in ruuntime
Code:

thread th1(shap, px, 1);
                                 thread th2(shap, px, 2);
                                 thread th3(shap, px, 3);
                                 thread th4(shap, px, 4);
                                 thread th5(shap, px, 5);
                                 thread th6(shap, px, 6);
                                 thread th7(shap, px, 7);
                                 thread th8(shap, px, 8);
                                 thread th9(shap, px, 9);
                                 thread th10(shap, px, 10);
                                 thread th11(shap, px, 11);
                                 thread th12(shap, px, 12);
                                 thread th13(shap, px, 13);
                                 thread th14(shap, px, 14);
                                 thread th15(shap, px, 15);
                                 thread th16(shap, px, 16);
                                 thread th17(shap, px, 17);
                                 thread th18(shap, px, 18);
                                 
                                 th1.join();
                                 th2.join();
                                 th3.join();
                                 th4.join();
                                 th5.join();
                                 th6.join();
                                 th7.join();
                                 th8.join();
                                 th9.join();
                                 th10.join();
                                 th11.join();
                                 th12.join();
                                 th13.join();
                                 th14.join();
                                 th15.join();
                                 th16.join();
                                 th17.join();
                                 th18.join();

i cant reveal other for the code because its a big stuff.
So, i opted for build several indipendent program and launch with taskset or something similar (&) but you all tell me its not correct.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum