Hi everyone, I've fiddled with making something concurrent and noticed I horribly failed. It gets 2-3 times slower when trying to work using pmap instead of map.
What I want to do: I am working on a game, I have units, and a map fields (x,y coordinates). Now in every game turn each unit is allowed to act (move, update itself's status or interact with another unit). Doing this non parallel isn't a problem and works quite well. The concurrency model I chose is: Each unit is in a ref: (so if a unit updates itself and another unit is interacting with it the transaction fails and is redone - can't happen that a unit interacts with a unit and uses a wrong state of the unit). This seems to be quite OK. The more challenging part is the map. My first attempt was to put the entire map in one big ref and represent it by a hashmap. As this looked quite risky in terms of rerun (if two units move at the same time, there is a rerun if I am not mistaken, even if they are not interacting at all). My second attempt was to put the map in a ref, then put each row in another ref (add them dynamically as needed) and the in there put each field in a ref. So if a unit moves from (0,0) to (0,1) for the first time the map is changed and a new row added to this row a new column is added. If it them moves back from (0,1) (0,0) only this two refs are changed and I hoped that no other units (that don't want to interact with (0,0) or (0,1) have to rerun) - sadly this got even slower. Now I'm slowly getting desperate and would like to ask what I am doing wrong. A few outlines: * I use pmap in to run units in parallel. * pmap is partitioned in 200 unit chunks (of 1k units total) * one turn for al 1k units takes with pmap 30s, without 10s * There can't be two units on the same field (so consistency and order of the moves on the map are important) * The units have their position stored, so if they interact they don't need the map to tell them they moved (redo when a concurrency problem occurs should be caused by the unit ref not the map ref) I'd be very thankful if I could get some advice here, sicne I am running out of ideas. Best regards and thanks an advance, Heinz. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en