Commits

Kelvin Jin committed abc49e7

Nbody mapper now works. fixed seg fault caused by unmarshaling in nbody.ml

Comments (0)

Files changed (2)

 let (id1, x) = Program.get_input() in
-let (mass1, position1, _) = Util.unmarshal x in
-let bodies = Util.unmarshal (Program.get_shared_data()) in
+let b : Util.body = Util.unmarshal x in
+let (mass1, position1, _) = b in
+let bodies : (string * Util.body) list = Util.unmarshal (Program.get_shared_data()) in
 let helper acc other =
   let (id2, (mass2, position2, _)) = other in
   let dist = Plane.distance position1 position2 in
   let g_force = (Util.cBIG_G *. mass1) /. (dist *. dist) in
   let direction = Plane.unit_vector position2 position1 in
+  let result = Util.marshal (Plane.scale_point g_force direction) in
   if id1 = id2 then acc
-  else (other, Util.marshal (Plane.scale_point g_force direction))::acc in
+  else (other, result)::acc in
 Program.set_output (List.fold_left helper []
                    bodies)
     let kv_pairs = List.map to_string_tuple !bodies_ref in
     let mapped =
       Map_reduce.map kv_pairs (marshal !bodies_ref) "apps/nbody/mapper.ml" in
+    let combined = Map_reduce.combine mapped in
+    let reduced =
+      Map_reduce.reduce combined "" "apps/nbody/reducer.ml" in
     let unwrap (k, v) = 
-      (k, unmarshal v) in
-    List.map unwrap mapped in
+      match v with
+      | [] -> failwith "no body was ever recovered"
+      | h::_ -> (k, unmarshal h) in
+    List.map unwrap reduced in
   str := string_of_bodies bodies;
-    bodies_ref := nbody_map_reduce (); 
-    str := string_of_bodies !bodies_ref;
+  for i = 1 to steps do
+    (bodies_ref := nbody_map_reduce (); 
+    str := string_of_bodies !bodies_ref) done;
   !str
 
 let simulation_of_string = function