private void graph_creator() { IIteratorInstance <IKVPair <IInteger, IIterator <GIF> > > input_instance_gif = (IIteratorInstance <IKVPair <IInteger, IIterator <GIF> > >)Collect_graph.Client; IIteratorInstance <IKVPair <IInteger, GIF> > output_instance_gif = (IIteratorInstance <IKVPair <IInteger, GIF> >)Output_gif.Instance; Feed_graph.Server = output_instance_gif; IActionFuture sync_perform; bool end_iteration = false; while (!end_iteration) // take next chunk ... { Task_gusty.invoke(ITaskPortAdvance.READ_CHUNK); Task_gusty.invoke(ITaskPortAdvance.PERFORM, out sync_perform); IKVPairInstance <IInteger, IIterator <GIF> > kvpair = null; object kvpair_object; object o; if (!input_instance_gif.has_next()) { end_iteration = true; } while (input_instance_gif.fetch_next(out kvpair_object)) { kvpair = (IKVPairInstance <IInteger, IIterator <GIF> >)kvpair_object; Graph_values.Instance = kvpair; Gusty_function.graph_creator(); } sync_perform.wait(); } //IActionFuture gusty_chunk_ready; //Task_gusty.invoke (ITaskPortAdvance.CHUNK_READY, out gusty_chunk_ready); //*** output_instance_gif.finish(); //gusty_chunk_ready.wait (); }
private void readPair_OMK_OMVs() { Console.WriteLine(this.Rank + ": REDUCE 1"); IIteratorInstance <IKVPair <TKey, IIterator <TValue> > > input_instance = (IIteratorInstance <IKVPair <TKey, IIterator <TValue> > >)Collect_pairs.Client; IIteratorInstance <IKVPair <OKey, OValue> > output_instance = (IIteratorInstance <IKVPair <OKey, OValue> >)Output.Instance; Feed_pairs.Server = output_instance; IActionFuture sync_perform; // TODO: Dividir em chunks a saa de pares (OKey,OValue) Console.WriteLine(this.Rank + ": REDUCER 2"); // object gusty_lock = new object (); bool end_computation = false; while (!end_computation) // new iteration { IDictionary <object, object> cont_dict = new Dictionary <object, object> (); Console.WriteLine(this.Rank + ": REDUCER LOOP"); end_computation = true; bool end_iteration = false; while (!end_iteration) // take next chunk ... { Console.WriteLine(this.Rank + ": REDUCER ITERATE 1"); Task_gusty.invoke(ITaskPortAdvance.READ_CHUNK); Task_gusty.invoke(ITaskPortAdvance.PERFORM, out sync_perform); Console.WriteLine(this.Rank + ": REDUCER ITERATE 2"); IKVPairInstance <TKey, IIterator <TValue> > kvpair = null; object kvpair_object; if (!input_instance.has_next()) { end_iteration = true; } else { end_computation = false; } int count = 0; while (input_instance.fetch_next(out kvpair_object)) { Console.WriteLine(this.Rank + ": REDUCER ITERATE INNER LOOP 3 count=" + count); kvpair = (IKVPairInstance <TKey, IIterator <TValue> >)kvpair_object; object acc_value; if (!cont_dict.TryGetValue(kvpair.Key, out acc_value)) { cont_dict[kvpair.Key] = new object(); } else { ((IDataInstance)Continue_value.Instance).ObjValue = acc_value; } Input_values.Instance = kvpair; Gusty_function.go(); cont_dict [kvpair.Key] = ((IDataInstance)((IKVPairInstance <OKey, OValue>)Output_value.Instance).Value).ObjValue; count++; } Console.WriteLine(this.Rank + ": REDUCER ITERATE 4 count=" + count); sync_perform.wait(); Console.WriteLine(this.Rank + ": REDUCER ITERATE 5"); } Console.WriteLine(this.Rank + ": REDUCER ITERATE END ITERATION"); int chunk_counter = 1; IActionFuture gusty_chunk_ready; Task_gusty.invoke(ITaskPortAdvance.CHUNK_READY, out gusty_chunk_ready); //*** foreach (KeyValuePair <object, object> output_pair in cont_dict) { IKVPairInstance <OKey, OValue> new_pair = (IKVPairInstance <OKey, OValue>)Output_value.newInstance(); new_pair.Key = output_pair.Key; new_pair.Value = output_pair.Value; output_instance.put(new_pair); } output_instance.finish(); gusty_chunk_ready.wait(); Console.WriteLine(this.Rank + ": REDUCER ITERATE FINISH"); } Console.WriteLine(this.Rank + ": REDUCER FINISH ... "); }
public override void main() { Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 1"); Task_binding_data.TraceFlag = Task_map.TraceFlag = Task_gusty.TraceFlag = Task_binding_shuffle.TraceFlag = Task_binding_split_first.TraceFlag = Task_binding_split_next.TraceFlag = true; Task_binding_data.TraceFlag = Task_binding_shuffle.TraceFlag = Task_binding_split_first.TraceFlag = Task_binding_split_next.TraceFlag = true; IActionFutureSet future_iteration = null; Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 2-1"); IActionFuture future_split_first_chunk_ready = null; Task_binding_split_first.invoke(ITaskPortAdvance.CHUNK_READY, out future_split_first_chunk_ready); int action_id_split_first_chunk_ready = future_split_first_chunk_ready.GetHashCode(); future_iteration = future_split_first_chunk_ready.createSet(); Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 2-2"); IActionFuture future_split_next_chunk_ready = null; Task_binding_split_next.invoke(ITaskPortAdvance.CHUNK_READY, out future_split_next_chunk_ready); int action_id_split_next_chunk_ready = future_split_next_chunk_ready.GetHashCode(); future_iteration.addAction(future_split_next_chunk_ready); Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 3"); IActionFuture future_map_chunk_ready = null; Task_map.invoke(ITaskPortAdvance.CHUNK_READY, out future_map_chunk_ready); int action_id_map_chunk_ready = future_map_chunk_ready.GetHashCode(); future_iteration.addAction(future_map_chunk_ready); Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 4"); IActionFuture future_shuffle_chunk_ready = null; Task_binding_shuffle.invoke(ITaskPortAdvance.CHUNK_READY, out future_shuffle_chunk_ready); int action_id_shuffle_chunk_ready = future_shuffle_chunk_ready.GetHashCode(); future_iteration.addAction(future_shuffle_chunk_ready); Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 4"); IActionFuture future_gusty_chunk_ready = null; Task_gusty.invoke(ITaskPortAdvance.CHUNK_READY, out future_gusty_chunk_ready); int action_id_gusty_chunk_ready = future_gusty_chunk_ready.GetHashCode(); future_iteration.addAction(future_gusty_chunk_ready); Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 5"); IActionFuture future_data_terminate = null; Task_binding_data.invoke(ITaskPortData.TERMINATE, out future_data_terminate); future_iteration.addAction(future_data_terminate); int action_id_data_terminate = future_data_terminate.GetHashCode(); Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 6-1"); Task_binding_data.invoke(ITaskPortData.READ_SOURCE); Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 6-2"); Task_binding_split_first.invoke(ITaskPortAdvance.READ_CHUNK); Task_binding_split_first.invoke(ITaskPortAdvance.PERFORM); Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 7"); IList <Thread> bag_of_tasks = new List <Thread> (); bool terminate = false; do { Console.WriteLine(this.ThisFacetInstance + "/" + this.Rank + ": WORKFLOW 8 - LOOP"); IActionFuture action = future_iteration.waitAny(); int action_id = action.GetHashCode(); if (action_id == action_id_split_first_chunk_ready) { Thread t1 = new Thread((ThreadStart) delegate() { Console.WriteLine("INVOKE MAPPER READ_CHUNK - BEFORE"); Task_map.invoke(ITaskPortAdvance.READ_CHUNK); Console.WriteLine("INVOKE MAPPER READ_CHUNK - AFTER"); IActionFuture future_map_perform = null; Thread thread_map_perform = Task_map.invoke(ITaskPortAdvance.PERFORM, map_perform, out future_map_perform); Console.WriteLine("END INVOKE SPLITTER CHUNK_READY"); }); bag_of_tasks.Add(t1); t1.Start(); Thread t2 = new Thread((ThreadStart) delegate() { Console.WriteLine("INVOKE SPLITTER READ_CHUNK"); Task_binding_split_first.invoke(ITaskPortAdvance.READ_CHUNK); Console.WriteLine("INVOKE SPLITTER PERFORM"); Task_binding_split_first.invoke(ITaskPortAdvance.PERFORM); Console.WriteLine("INVOKE SPLITTER READ_CHUNK/PERFORM - AFTER"); IActionFuture future_split_chunk_ready_ = null; Task_binding_split_first.invoke(ITaskPortAdvance.CHUNK_READY, out future_split_chunk_ready_); action_id_split_first_chunk_ready = future_split_chunk_ready_.GetHashCode(); future_iteration.addAction(future_split_chunk_ready_); }); Console.WriteLine("THREAD LAUNCHED 1"); bag_of_tasks.Add(t2); t2.Start(); } else if (action_id == action_id_map_chunk_ready) { Task_map.invoke(ITaskPortAdvance.CHUNK_READY, out future_map_chunk_ready); action_id_map_chunk_ready = future_map_chunk_ready.GetHashCode(); future_iteration.addAction(future_map_chunk_ready); Thread t = new Thread((ThreadStart) delegate() { Console.WriteLine("INVOKE SHUFFLER READ_CHUNK - BEFORE"); // 110 executados (o 48 completou nos pares, mas não progrediu aqui (????), motivo do erro. Task_binding_shuffle.invoke(ITaskPortAdvance.READ_CHUNK); // Console.WriteLine("INVOKE SHUFFLER READ_CHUNK - AFTER"); // 47 completados IActionFuture future_shuffle_perform = null; Thread thread_shuffle_perform = Task_binding_shuffle.invoke(ITaskPortAdvance.PERFORM, shuffle_perform, out future_shuffle_perform); Console.WriteLine("END INVOKE MAPPER CHUNK_READY"); }); t.Start(); bag_of_tasks.Add(t); Console.WriteLine("THREAD LAUNCHED 2"); } else if (action_id == action_id_shuffle_chunk_ready) { Task_binding_shuffle.invoke(ITaskPortAdvance.CHUNK_READY, out future_shuffle_chunk_ready); action_id_shuffle_chunk_ready = future_shuffle_chunk_ready.GetHashCode(); future_iteration.addAction(future_shuffle_chunk_ready); Thread t = new Thread((ThreadStart) delegate() { Console.WriteLine("INVOKE REDUCER READ_CHUNK - BEFORE"); Task_gusty.invoke(ITaskPortAdvance.READ_CHUNK); // **** Console.WriteLine("INVOKE REDUCER READ_CHUNK - AFTER"); IActionFuture future_gusty_perform = null; Thread thread_gusty_perform = Task_gusty.invoke(ITaskPortAdvance.PERFORM, gusty_perform, out future_gusty_perform); Console.WriteLine("END INVOKE SHUFFLER CHUNK_READY"); }); t.Start(); bag_of_tasks.Add(t); Console.WriteLine("THREAD LAUNCHED 3"); } else if (action_id == action_id_gusty_chunk_ready) { Task_gusty.invoke(ITaskPortAdvance.CHUNK_READY, out future_gusty_chunk_ready); action_id_gusty_chunk_ready = future_gusty_chunk_ready.GetHashCode(); future_iteration.addAction(future_gusty_chunk_ready); Thread t = new Thread((ThreadStart) delegate() { Console.WriteLine("INVOKE SPLITTER NEXT READ_CHUNK - BEFORE"); Task_binding_split_next.invoke(ITaskPortAdvance.READ_CHUNK); // **** Console.WriteLine("INVOKE SPLITTER NEXT READ_CHUNK - AFTER"); IActionFuture future_split_perform = null; Thread thread_split_perform = Task_binding_split_next.invoke(ITaskPortAdvance.PERFORM, split_perform, out future_split_perform); Console.WriteLine("END INVOKE REDUCER CHUNK_READY"); }); t.Start(); bag_of_tasks.Add(t); Console.WriteLine("THREAD LAUNCHED 4"); } else if (action_id == action_id_split_next_chunk_ready) { Thread t1 = new Thread((ThreadStart) delegate() { Console.WriteLine("INVOKE MAP READ_CHUNK NEXT - BEFORE"); Task_map.invoke(ITaskPortAdvance.READ_CHUNK); // Console.WriteLine("INVOKE MAP READ_CHUNK NEXT - AFTER"); IActionFuture future_map_perform = null; Thread thread_map_perform = Task_map.invoke(ITaskPortAdvance.PERFORM, map_perform, out future_map_perform); Console.WriteLine("END INVOKE SPLIT NEXT CHUNK_READY"); }); bag_of_tasks.Add(t1); t1.Start(); Thread t2 = new Thread((ThreadStart) delegate() { Console.WriteLine("INVOKE SPLITTER NEXT READ_CHUNK"); Task_binding_split_next.invoke(ITaskPortAdvance.READ_CHUNK); Console.WriteLine("INVOKE SPLITTER NEXT PERFORM"); Task_binding_split_next.invoke(ITaskPortAdvance.PERFORM); Console.WriteLine("INVOKE SPLITTER NEXT READ_CHUNK/PERFORM - AFTER"); IActionFuture future_split_next_chunk_ready_ = null; Task_binding_split_next.invoke(ITaskPortAdvance.CHUNK_READY, out future_split_next_chunk_ready_); action_id_split_next_chunk_ready = future_split_next_chunk_ready_.GetHashCode(); future_iteration.addAction(future_split_next_chunk_ready_); }); Console.WriteLine("THREAD LAUNCHED 1"); bag_of_tasks.Add(t2); t2.Start(); Console.WriteLine("THREAD LAUNCHED 5"); } else if (action_id == action_id_data_terminate) { Thread t = new Thread((ThreadStart) delegate() { Console.WriteLine("INVOKE DATA WRITE_SINK - BEFORE"); Task_binding_data.invoke(ITaskPortData.WRITE_SINK); Console.WriteLine("INVOKE DATA WRITE_SINK - AFTER"); terminate = true; }); t.Start(); bag_of_tasks.Add(t); Console.WriteLine("THREAD LAUNCHED 6"); } else { Console.WriteLine("UNEXPECTED ERROR: ACTION FUTURE NOT RECOGNIZED ! "); } } while (!terminate); Console.WriteLine("WORKFLOW FINISHED ! "); foreach (Thread t in bag_of_tasks) { t.Join(); } }