Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Parallel pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 27 Topic 26196 of 26821
Post > Topic >>

Re: Parallel program to calculate PI

by Spiros Bousbouras <spibou@[EMAIL PROTECTED] > May 13, 2008 at 07:55 AM

On 13 May, 15:20, Prime Mover <eple...@[EMAIL PROTECTED]
> wrote:
> Hello all,
>
> I have got the pseudo-code below that I would like to convert to c
> language. The algorithm calculates Pi value. I am somewhat familiar
> with C language, but I am just starting to learn parallel programming.
> In this specific example, the idea seems to be simple: one must
> subdivide the main loop into pieces that can be executed by
> independent "tasks" (computers??).
>
> Then, each "worker task"  executes a part of the loop a certain number
> of times, independently of the other worker tasks. One specific task
> plays the role of "master task", which will collect and sum the
> results of the worker tasks:
>
> % descriptive algorithm:
> 1. Inscribe a circle inside a square
> 2. Generate random points inside the square
> 3. Determine the number of points that fell inside the circle
> 4. Let r be the number of points inside the circle divided by the
> total number of points
> 5. Pi is approximately equal to 4*r
> 6. The more points are generated, the more is the precision in P value
>
> % pseudo-code (parallel):
> 1. npoints = 10000
> 2. circle_count = 0
> 3. p = number of tasks
> 4. num = npoints/p
> 5. find out if I am MASTER or WORKER
> 6. do j = 1,num
> 7. generate 2 random numbers between 0 and 1
> 8. xcoordinate = random1
> 9. ycoordinate = random2
> 10. if (xcoordinate, ycoordinate) inside circle then
> circle_count = circle_count + 1
> 11. end do
> 12. if I am MASTER
> 13. receive from WORKERS their circle_counts
> 14. compute PI (use MASTER and WORKER calculations)
> 15. else if I am WORKER
> 16. send to MASTER circle_count
> 17. endif


On 13 May, 15:28, Prime Mover <eple...@[EMAIL PROTECTED]
> wrote:
> Let me just be a bit more specific:
>
> My (understading) problem starts in the line 5 of the pseudo-code:
> 5. find out if I am MASTER or WORKER
>
> How would I specificy a "worker"? Would that be another computer?
> If yes, how can I access this remote computer in the calculations, in
> C language?
> If yes, it means that I have to have a LAN or something to perform
> tests?
>
> I have found that there are some libraries such as OMP or MPI that
> could be
> used, but I'd like to know if there is a more "raw" way of doing this
> first.


Standard C has no built-in sup****t for parallel processing so an
answer
to the question "find out if I am MASTER or WORKER" falls outside
standard C which is what's topical here. I have no idea what kind of
hardware set-up and extensions to C can be used to tackle numerically
intensive parallel algorithms. Perhaps others here have the relevant
experience. Searching Google groups for *parallel* I found
comp.parallel.mpi and comp.parallel.pvm where I'm guessing you might
get more useful advice than here.

Out of curiosity for what value of npoints are you aiming for ? In
your example it's only 100000 and you can get that on a modern desktop
in a few seconds.
 




 27 Posts in Topic:
Parallel program to calculate PI
Prime Mover <epleite@[  2008-05-13 07:20:09 
Re: Parallel program to calculate PI
Prime Mover <epleite@[  2008-05-13 07:28:37 
Re: Parallel program to calculate PI
Spiros Bousbouras <spi  2008-05-13 07:55:13 
Re: Parallel program to calculate PI
Spiros Bousbouras <spi  2008-05-13 07:57:53 
Re: Parallel program to calculate PI
Pietro Cerutti <gahr@[  2008-05-13 17:02:08 
Re: Parallel program to calculate PI
Richard Heathfield <rj  2008-05-13 15:28:47 
Re: Parallel program to calculate PI
CBFalconer <cbfalconer  2008-05-13 11:27:51 
Re: Parallel program to calculate PI
Bart <bc@[EMAIL PROTEC  2008-05-13 08:15:17 
Re: Parallel program to calculate PI
Spiros Bousbouras <spi  2008-05-13 08:31:25 
Re: Parallel program to calculate PI
Spiros Bousbouras <spi  2008-05-13 08:32:27 
Re: Parallel program to calculate PI
Richard Heathfield <rj  2008-05-13 16:00:59 
Re: Parallel program to calculate PI
Spiros Bousbouras <spi  2008-05-13 09:07:57 
Re: Parallel program to calculate PI
Richard Heathfield <rj  2008-05-13 16:38:59 
Re: Parallel program to calculate PI
Eric Sosman <Eric.Sosm  2008-05-13 12:43:51 
Re: Parallel program to calculate PI
Richard Heathfield <rj  2008-05-13 16:55:29 
Re: Parallel program to calculate PI
dj3vande@[EMAIL PROTECTED  2008-05-13 16:43:20 
Re: Parallel program to calculate PI
Bart <bc@[EMAIL PROTEC  2008-05-13 09:48:57 
Re: Parallel program to calculate PI
Richard Heathfield <rj  2008-05-13 17:06:03 
Re: Parallel program to calculate PI
CBFalconer <cbfalconer  2008-05-13 16:33:26 
Re: Parallel program to calculate PI
user923005 <dcorbit@[E  2008-05-13 12:08:38 
Re: Parallel program to calculate PI
Richard Heathfield <rj  2008-05-13 21:57:34 
Re: Parallel program to calculate PI
Prime Mover <epleite@[  2008-05-13 12:30:27 
Re: Parallel program to calculate PI
Keith Thompson <kst-u@  2008-05-13 13:02:02 
Re: Parallel program to calculate PI
Prime Mover <epleite@[  2008-05-13 13:00:38 
Re: Parallel program to calculate PI
Eric Sosman <Eric.Sosm  2008-05-13 16:19:35 
Re: Parallel program to calculate PI
user923005 <dcorbit@[E  2008-05-13 17:43:53 
Re: Parallel program to calculate PI
"dSpam@[EMAIL PROTEC  2008-05-15 02:42:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 1:16:08 CDT 2008.