Commits

Kelvin Jin committed 655c669

All reducers now work

Comments (0)

Files changed (8)

apps/inverted_index/reducer.ml

 let (key, values) = Program.get_input() in
-let helper acc v =
+let helper acc str =
+  let v = int_of_string str in
   match acc with
   | [] -> [v]
-  | h::t -> if v = h then acc else v::acc in
-let indices = List.sort (List.fold_left helper [] values) in
-    Program.set_output [string_of_int sum]
+  | _::_ -> if List.mem v acc then acc else v::acc in
+let indices = List.sort (fun a b -> a - b) (List.fold_left helper [] values) in
+let strings = List.map string_of_int indices in
+    Program.set_output strings

apps/nbody/nbody.ml

       let unwrap (k, v) = 
         match v with
         | [] -> failwith "no body was ever recovered"
-        | h::_ -> (k, unmarshal h) in
+        | h::_ -> unmarshal h in
       string_of_bodies bodies ^
         (nbody_map_reduce (List.map unwrap reduced) (steps - 1)) in
   nbody_map_reduce bodies steps
   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 1 in
+    let transcript = make_transcript bodies 60 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 =
-  Plane.v_plus acc (unmarshal v) in
+  Plane.v_plus acc (Util.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 =
-    Plane.v_plus (Plane.v_plus location velocity) (Plane.scale_point acceleration 0.5) in
+    Plane.v_plus (Plane.v_plus location velocity) (Plane.scale_point 0.5 acceleration) in
   let new_velocity = Plane.v_plus velocity acceleration in
   (id, (mass, new_position, new_velocity)) in
-Program.set_output [result]
+Program.set_output [Util.marshal result]

apps/page_rank/mapper.ml

 let num_links = float_of_int (List.length website.Util.links) in
 let rank = float_of_string value in
 let weight = if num_links = 0. then 0. else rank /. num_links in
-Program.set_output (List.fold_left (fun acc k -> (Hashtbl.find ht k, string_of_float weight)::acc) [] website.Util.links)
+Program.set_output (List.fold_left (fun acc k -> (Util.marshal (Hashtbl.find ht k), string_of_float weight)::acc) [] website.Util.links)

apps/page_rank/page_rank.ml

   List.map (fun (k, v) -> ((unmarshal k).pagetitle, [v])) (loop init_kv_pairs iterations)
 
 let main (args : string array) : unit = 
-  if Array.length args < 3 then
+  if Array.length args < 4 then
     Printf.printf "Usage: page_rank <num_iterations> <filename>"
   else begin
     let filename = args.(3) in

apps/page_rank/reducer.ml

-let (key, values) = Program.get_input() in
+let (_, values) = Program.get_input() in
 let sum = List.fold_left (fun acc v -> acc +. (float_of_string v)) 0. values in
     Program.set_output [string_of_float sum]

controller/map_reduce.ml

   List.iter add kv_pairs;
   (* Fold over to create and print the combine list *)
   let results = Hashtbl.fold (fun k v acc -> (k, v) :: acc) htbl [] in
-  print_combine_results results;
   results
   
 (* Still not working - more or less same as map though *)

controller/worker_manager.ml

     else InitReducer(source) in
   let worker_response_wrapper (_, connection) =
     match (Connection.input connection, worker_type) with
-    | (Some(Mapper(Some(id), _)), Map) | (Some(Reducer(Some(id), _)), Reduce) -> begin
+    | (Some(Mapper(Some(id), _)), _) | (Some(Reducer(Some(id), _)), _) -> begin
         push_worker manager (id, connection);
         workers := (id, connection) :: !workers
         end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.