Commits

Kelvin Jin committed 94e633e

nbody mapper now compiles. added plane.cmo/hashtable.cmo to build.bat.

Comments (0)

Files changed (5)

apps/inverted_index/mapper.ml

 let (key, value) = Program.get_input() in
-let line_number =
-  let at_index =
-    try
-      String.index value '@'
-    with Not_found -> failwith "Incorrect formatting" in
   String.sub value 0 at_index in
-Program.set_output (List.fold_left (fun acc k -> (k, line_number)::acc) []
+Program.set_output (List.fold_left (fun acc k -> (k, key)::acc) []
                    (List.map String.lowercase (Util.split_words value)))

apps/nbody/mapper.ml

-let ((_, (mass1, position1, _)), bodies) = Program.get_input() in
+let (id1, x) = Program.get_input() in
+let (mass1, position1, _) = Util.unmarshal x in
+let bodies = Util.unmarshal (Program.get_shared_data()) in
 let helper acc other =
-  let (_, (mass2, position2, _)) = other in
-  let dist = distance position1 position2 in
-  let g_force = (cBIG_G *. mass1) /. (dist *. dist) in
-  let direction = unit_vector position2 position1 in
-  (other, scale_point g_force direction)::acc in
+  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
+  if id1 = id2 then acc
+  else (other, Util.marshal (Plane.scale_point g_force direction))::acc in
 Program.set_output (List.fold_left helper []
                    bodies)

apps/nbody/nbody.ml

 
 (* Create a transcript of body positions for `steps` time steps *)
 let make_transcript (bodies : (string * body) list) (steps : int) : string = 
-  failwith "I'm interested in this"
+  let bodies_ref = ref bodies in
+  let str = ref "" in
+  let nbody_map_reduce () =
+    let to_string_tuple (id, b) = (id, marshal b) in
+    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 unwrap (k, v) = 
+      (k, unmarshal v) in
+    List.map unwrap mapped in
+  str := string_of_bodies bodies;
+    bodies_ref := nbody_map_reduce (); 
+    str := string_of_bodies !bodies_ref;
+  !str
 
 let simulation_of_string = function
   | "binary_star" -> Simulations.binary_star
   Results will be written to [<outfile>] or stdout."
   else begin
     let (num_bodies_str, bodies) = simulation_of_string args.(2) in
-    let transcript = make_transcript bodies 60 in
+    let transcript = make_transcript bodies 1 in
     let out_channel = 
       if Array.length args > 3 then open_out args.(3) else stdout in
     output_string out_channel (num_bodies_str ^ "\n" ^ transcript);

apps/nbody/reducer.ml

 let (key, values) = Program.get_input() in
 let helper acc v =
-  v_plus acc (unmarshal v) in
+  Plane.v_plus acc (unmarshal v) in
 let acceleration = List.fold_left helper (0., 0.) values in
 let result =
   let (id, (mass, location, velocity)) = key in
   let new_position =
-    v_plus (v_plus location velocity) (scale_point acceleration 0.5) in
-  let new_velocity = v_plus velocity acceleration in
+    Plane.v_plus (Plane.v_plus location velocity) (Plane.scale_point acceleration 0.5) in
+  let new_velocity = Plane.v_plus velocity acceleration in
   (id, (mass, new_position, new_velocity)) in
-Program.set_output [result]
+Program.set_output [result]
 ocamlc -o shared/util.cma -a -I shared shared/hashtable.mli shared/hashtable.ml shared/plane.mli shared/plane.ml shared/util.mli shared/util.ml shared/simulations.mli shared/simulations.ml
-ocamlc -thread -o worker_server.exe -I shared -I worker_server dynlink.cma str.cma unix.cma threads.cma util.cma shared/thread_pool.mli shared/thread_pool.ml shared/connection.mli shared/connection.ml shared/protocol.mli shared/protocol.ml worker_server/program.mli worker_server/program.ml worker_server/worker.mli worker_server/worker.ml worker_server/worker_server.mli worker_server/worker_server.ml
+ocamlc -thread -o worker_server.exe -I shared -I worker_server dynlink.cma str.cma unix.cma threads.cma util.cmo hashtable.cmo plane.cmo shared/thread_pool.mli shared/thread_pool.ml shared/connection.mli shared/connection.ml shared/protocol.mli shared/protocol.ml worker_server/program.mli worker_server/program.ml worker_server/worker.mli worker_server/worker.ml worker_server/worker_server.mli worker_server/worker_server.ml
 ocamlc -thread -o controller.exe -I shared -I controller -I apps/inverted_index -I apps/nbody -I apps/word_count -I apps/page_rank -I apps/apm unix.cma threads.cma str.cma util.cma shared/thread_pool.mli shared/thread_pool.ml shared/connection.mli shared/connection.ml shared/protocol.mli shared/protocol.ml controller/worker_manager.mli controller/worker_manager.ml controller/map_reduce.mli controller/map_reduce.ml apps/inverted_index/inverted_index.mli apps/inverted_index/inverted_index.ml apps/word_count/word_count.mli apps/word_count/word_count.ml apps/nbody/nbody.mli apps/nbody/nbody.ml apps/page_rank/page_rank.mli apps/page_rank/page_rank.ml controller/main.ml