|
|
| Author |
Message |
< Erlang ~ Concurrency Issues? |
| zbrown |
Posted: Fri Aug 03, 2007 11:36 pm |
|
|
|
User
Joined: 03 Aug 2007
Posts: 14
Location: Miami, FL
|
Hi all,
I've been playing with erlang now for a week or two and am really enjoying it. Just curious if anyone can find a problem in this program that I'll attach via link. Its supposed to be a concurrent prime sieve of sorts for solving a http://projecteuler.net problem. Though the problem is as far as I can tell when I invoke erl with "erl -smp", it doesn't really do anything very concurrent looking. It only maxes one of my two CPU's on my linux laptop, and only 1 of the 4 on my Mac OS X desktop at work.
I've compiled both otp's with --enable-smp-support --enable-threads and I'm still not sure whats wrong. From what I can tell it should be concurrent but it doesn't seem that way.
This is the code: http://paste.lisp.org/display/45586
Thanks a lot for any help!
Zac |
|
|
| Back to top |
|
| francesco |
Posted: Mon Aug 06, 2007 1:07 pm |
|
|
|
User
Joined: 07 Jul 2006
Posts: 249
Location: London
|
Hi Zac,
Welcome to the Erlang world, where concurrency is not as trivial as it seems. I had a brief look at the code. You spawn 500 processes which are suspended (idle) in a receive clause. From there, you call test_loop, which sends a message to one process, is suspended in a receive clause until it receives a reply, after which you send a new request to the next process. Not much use of concurrency here, as you only have one process working hard and all the others suspended in a receive clause. Try spawning 500 processes, sending them their tasks (use the make_ref() Bif or the slave pid to get a unique message ID). Once you have sent the 500 {test, Cur, Primes} messages, go in a receive loop and retrieve all the replies, mapping them to the original requests (Use the Pid / Reference here). Your CPU usage should now behave differently.
If you have any other questions, just ask.
Francesco
--
http://www.erlang-consulting.com |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|
|