Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-12-2005, 09:33 AM   #1
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, 11:57 AM   #2
Senior Member
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Rep: Reputation: 136Reputation: 136
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, 10:20 AM   #3
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, 11:25 AM   #4
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.


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 09:57 AM
need help with pi calculations! daven1 Programming 2 01-06-2005 08:21 PM
Firefox-0.9.1 mathematical fonts goofyheadedpunk Linux - Software 0 08-10-2004 01:02 PM
Date calculations in BASH script Crashman Programming 4 07-03-2004 11:15 AM
Need mathematical software! Bogdan Linux - Software 1 05-18-2002 07:04 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:18 AM.

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