LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-12-2005, 08:33 AM   #1
skywalker27182
Member
 
Registered: Nov 2003
Posts: 35

Rep: Reputation: 15
threads for mathematical calculations?


hello friends,
i am working on a project that does a LOT of mathematical calculations. the programs have been in C and takes about 4 to 5 hours to complete. will the use of threads make it any better?
 
Old 02-12-2005, 10:57 AM   #2
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,142
Blog Entries: 4

Rep: Reputation: 121Reputation: 121
Yes. Probably. But you must realise that writing too many threads for several functions at the same time will probably not work out to be more economical than using few (maybe three or four) threads at one time, especially if all the threads work on some common data. This will keep locking up resources alternatively and could slow down the progress. On the other hand, threads which do totally different things (like GUI threads vs. worker threads) could be more effective.

Restrict the total number of threads running at one time. It all depends on the calculations being used and how the data is being accessed through your program.

Threads are nice. But depending on the situation, it might or might not work out. You'll need to experiment a bit.

My suggestion is that you should not use more than three or four threads running at the same time.

Effectiveness of threads also depend on your OS because at the base level, the OS controls the tasking and generally the effectiveness is determined by how the multitasking is handled at the OS level.

In the end, it all comes down to experimentation with your program and tweaking it. Sometimes it might work out that slightly optimizing the program in other ways than threading might help.
 
Old 02-13-2005, 09:20 AM   #3
skywalker27182
Member
 
Registered: Nov 2003
Posts: 35

Original Poster
Rep: Reputation: 15
Thanks Harishankar.
many of the functions work independently (i mean, the data for the calculations are, more often, not dependent on the output of other functions). that is why i thought of threads. i will do some experimenting. thanks once again.
 
Old 02-13-2005, 10:25 AM   #4
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
if you have more than one CPU on the machine, you might see some performance improvement. But on a single CPU I don't see how adding threads will help, in fact it might slow your program down since you are adding the overhead of threads.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 08:57 AM
need help with pi calculations! daven1 Programming 2 01-06-2005 07:21 PM
Firefox-0.9.1 mathematical fonts goofyheadedpunk Linux - Software 0 08-10-2004 12:02 PM
Date calculations in BASH script Crashman Programming 4 07-03-2004 10:15 AM
Need mathematical software! Bogdan Linux - Software 1 05-18-2002 06:04 AM


All times are GMT -5. The time now is 03:21 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration