private void graph_creator_aux(IInputFormatInstance gif) { bool weighted = gif.Weight.Length == gif.Source.Length; float f = 1.0f; for (int i = 0; i < gif.ESIZE; i++) { int s = gif.Source [i]; int t = gif.Target [i]; if (weighted) { f = gif.Weight [i]; } g.addVertex(s); g.addVertex(t); g.noSafeAdd(s, t, f); if (s == 0 || t == 0) { throw new ArgumentNullException("WARNING: Vertex id is 0! "); } } IIteratorInstance <IKVPair <IInteger, IInputFormat> > output_gifs_instance = (IIteratorInstance <IKVPair <IInteger, IInputFormat> >)Output_gif.Instance; IKVPairInstance <IInteger, IInputFormat> item = (IKVPairInstance <IInteger, IInputFormat>)Output_gif.createItem(); ((IIntegerInstance)item.Key).Value = gif.PARTID; item.Value = gif; output_gifs_instance.put(item); }
public override void main() { string[] string_iteracoes = readInput("/home/hpe/iteracoes").Split(new char[] { System.Environment.NewLine[0] }); int iteracoes = int.Parse(string_iteracoes [0]); IStringInstance input_data_instance = (IStringInstance)Input_data.Instance; IIteratorInstance <IKVPair <IString, IDouble> > output_data_instance = (IIteratorInstance <IKVPair <IString, IDouble> >)Output_data.Instance; int count = 0; while (count++ < iteracoes) { double X = 0.0; this.Page_rank.go(); object o; string saida = ""; while (output_data_instance.fetch_next(out o)) { IKVPairInstance <IString, IDouble> kvp = (IKVPairInstance <IString, IDouble>)o; IStringInstance k = (IStringInstance)kvp.Key; IDoubleInstance v = (IDoubleInstance)kvp.Value; if (!k.Value.Equals("X")) { saida = saida + k.Value + " " + v.Value + System.Environment.NewLine; } else { X = v.Value; } } input_data_instance.Value = "X " + X + System.Environment.NewLine + saida; System.Console.WriteLine("PAGERANK ITERATION: " + count + " X:" + X); } }
public override void main() { IIteratorInstance <IKVPair <IMK, IMV> > input_instance = (IIteratorInstance <IKVPair <IMK, IMV> >)Input.Instance; IIteratorInstance <IKVPair <OMK, OMV> > output_instance = (IIteratorInstance <IKVPair <OMK, OMV> >)Output.Instance; object bin_object = null; int count = 0; while (input_instance.fetch_next(out bin_object)) { Trace.WriteLine(Rank + ": LOOP MAPPER !!!" + (count++)); IKVPairInstance <IMK, IMV> bin = (IKVPairInstance <IMK, IMV>)bin_object; Trace.WriteLine(Rank + ": " + (Map_value.Instance == null) + " $$$$ " + bin.Value.GetType()); Map_key.Instance = bin.Key; Map_value.Instance = bin.Value; Map_function.go(); } Trace.WriteLine(Rank + ": FINISH MAPPER !!!"); output_instance.finish(); }
public void graph_creator() { IKVPairInstance <IInteger, IIterator <IInputFormat> > input_gifs_instance = (IKVPairInstance <IInteger, IIterator <IInputFormat> >)Graph_values.Instance; IIteratorInstance <IInputFormat> vgifs = (IIteratorInstance <IInputFormat>)input_gifs_instance.Value; object o; if (partition_own == null) { if (vgifs.fetch_next(out o)) { IInputFormatInstance gif = (IInputFormatInstance)o; partition = gif.PartitionTABLE; partid = gif.PARTID; partition_size = gif.PARTITION_SIZE; g = Graph.newInstance(gif.VSIZE); // pega-se uma instancia do graph, com vertices do tipo inteiro, com tamanho previsto VSIZE g.DataContainer.AllowingLoops = false; // não serão premitidos laços g.DataContainer.AllowingMultipleEdges = false; // não serão permitidas múltiplas arestas graph_creator_aux(gif); // inserem-se dados no grafo partition_own = new bool[partition_size]; partition_own [partid] = true; } } while (vgifs.fetch_next(out o)) { graph_creator_aux((IInputFormatInstance)o); partition_own [((IInputFormatInstance)o).PARTID] = true; } }
public void emite() { string saida = ((IStringInstance)Input_data.Instance).Value; IIteratorInstance <IKVPair <IInteger, IPageNode> > output = (IIteratorInstance <IKVPair <IInteger, IPageNode> >)Output_data.Instance; double X = 0.0; string[] lines = saida.Split(new char[] { System.Environment.NewLine[0] }); string[] pr = lines[0].Split(' '); if (pr [0].Equals("X")) { X = double.Parse(pr [1]) / dic.Count; } else { System.Console.WriteLine("Error of index to X"); } lines [0] = ""; foreach (string line in lines) { if (!line.Trim().Equals("")) { string[] prank = line.Split(' '); //if (b && !prank [0].Equals ("X")) { IKVPairInstance <IInteger, IPageNode> kvpair = dic [int.Parse(prank [0])]; IPageNodeInstance no = (IPageNodeInstance)kvpair.Value; no.PgrankInstance = double.Parse(prank [1]) + X; output.put(kvpair); //} } } output.finish(); }
public override void main() { count = 0; IKVPairInstance <IString, IIterator <ICliqueNode> > input = (IKVPairInstance <IString, IIterator <ICliqueNode> >)Input_values.Instance; IStringInstance pivot = (IStringInstance)input.Key; IIteratorInstance <ICliqueNode> input_value = (IIteratorInstance <ICliqueNode>)input.Value; bigCliques = new List <IList <int> > (); bigger = 0; HashSet <int> upper = new HashSet <int>(); HashSet <int> lower = new HashSet <int>(); IDictionary <int, IList <int> > dicValues = splitting_In_Left_Pivot_Right(input_value, pivot.Value, upper, lower); IList <int> R = new List <int>(); R.Add(int.Parse(pivot.Value)); bronKerboschAlgorithm(1, dicValues, upper, R, lower); //if (count > 0) { IKVPairInstance <IString, ICliqueNode> kvpair = (IKVPairInstance <IString, ICliqueNode>)Output_value.newInstance(); ((IStringInstance)kvpair.Key).Value = pivot.Value; ((ICliqueNodeInstance)kvpair.Value).IdInstance = count; //bigCliques [0].Count; //((ICliqueNodeInstance)kvpair.Value).NeighborsInstance = bigCliques [0]; //} else { // IKVPairInstance<IString,ICliqueNode> kvpair = (IKVPairInstance<IString,ICliqueNode>)Output_value.newInstance (); // ((IStringInstance)kvpair.Key).Value = pivot.Value; // ((ICliqueNodeInstance)kvpair.Value).IdInstance = 0; //} }
public override void main() { IIntegerInstance input_key = (IIntegerInstance)Input_key.Instance; IPageNodeInstance input_value = (IPageNodeInstance)Input_value.Instance; IIteratorInstance <IKVPair <IString, IDouble> > output = (IIteratorInstance <IKVPair <IString, IDouble> >)Output_data.Instance; double slice = input_value.PgrankInstance; int size = input_value.NeighborsInstance.Count; IEnumerator <int> iterator = input_value.NeighborsInstance.GetEnumerator(); while (iterator.MoveNext()) { string n = iterator.Current.ToString(); IKVPairInstance <IString, IDouble> kvpair = (IKVPairInstance <IString, IDouble>)Output_data.createItem(); ((IStringInstance)kvpair.Key).Value = n; ((IDoubleInstance)kvpair.Value).Value = slice / size; output.put(kvpair); } if (size == 0) { IKVPairInstance <IString, IDouble> kvpair = (IKVPairInstance <IString, IDouble>)Output_data.createItem(); ((IStringInstance)kvpair.Key).Value = "X"; ((IDoubleInstance)kvpair.Value).Value = slice; output.put(kvpair); } IKVPairInstance <IString, IDouble> KV = (IKVPairInstance <IString, IDouble>)Output_data.createItem(); ((IStringInstance)KV.Key).Value = input_key.Value.ToString(); ((IDoubleInstance)KV.Value).Value = 0.0; output.put(KV); }
public void pull() { IKVPairInstance <IVertex, IIterator <IDataTriangle> > input_values_instance = (IKVPairInstance <IVertex, IIterator <IDataTriangle> >)Input_values.Instance; IVertexInstance ikey = (IVertexInstance)input_values_instance.Key; IIteratorInstance <IDataTriangle> ivalues = (IIteratorInstance <IDataTriangle>)input_values_instance.Value; IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance; object o; int v = ikey.Id; ICollection <int> vneighbors = g.neighborsOf(v); while (ivalues.fetch_next(out o)) { int w = ((IDataTriangleInstance)o).V; int z = ((IDataTriangleInstance)o).W; if (vneighbors.Contains(z) && v < z) { IList <KeyValuePair <int, int> > l; if (!triangles.TryGetValue(v, out l)) { l = new List <KeyValuePair <int, int> > (); triangles[v] = l; } l.Add(new KeyValuePair <int, int> (w, z)); count++; //emite (v, w, z, output_value); } } }
public void pull() { IKVPairInstance <IVertex, IIterator <IDataTriangle> > input_values_instance = (IKVPairInstance <IVertex, IIterator <IDataTriangle> >)Input_values.Instance; IVertexInstance ikey = (IVertexInstance)input_values_instance.Key; IIteratorInstance <IDataTriangle> ivalues = (IIteratorInstance <IDataTriangle>)input_values_instance.Value; IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance; object o; int w = ikey.Id; while (ivalues.fetch_next(out o)) { IEnumerator <int> wneighbors = g.iteratorNeighborsOf(w); while (wneighbors.MoveNext()) { int z = wneighbors.Current; if (w < z) { IKVPairInstance <IVertex, IDataTriangle> item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem(); ((IVertexInstance)item.Key).Id = ((IDataTriangleInstance)o).V; ((IDataTriangleInstance)item.Value).V = w; ((IDataTriangleInstance)item.Value).W = z; output_value.put(item); } } } }
public override void main() { Trace.WriteLine(WorldComm.Rank + ": STARTING BREAK IN LINE (SPLIT FUNCTION)"); IStringInstance input_data_instance = (IStringInstance)Input_data.Instance; IIteratorInstance <IKVPair <IInteger, IString> > output_data_instance = (IIteratorInstance <IKVPair <IInteger, IString> >)Output_data.Instance; string s = input_data_instance.Value; string[] lines = s.Split(new char[] { System.Environment.NewLine[0] }); int line_counter = 0; foreach (string line in lines) { if (!line.Trim().Equals("")) { Trace.WriteLine(WorldComm.Rank + ": LINE = " + line); IKVPairInstance <IInteger, IString> line_pair = (IKVPairInstance <IInteger, IString>)Output_data.createItem(); ((IIntegerInstance)line_pair.Key).Value = line_counter++; ((IStringInstance)line_pair.Value).Value = line; output_data_instance.put(line_pair); } } Trace.WriteLine(WorldComm.Rank + ": FINISH BREAK IN LINES #1 !!! " + output_data_instance.GetHashCode()); output_data_instance.finish(); Trace.WriteLine(WorldComm.Rank + ": FINISH BREAK IN LINES #2 !!!"); }
public override void main() { IIteratorInstance <IKVPair <IString, ICliqueNode> > output = (IIteratorInstance <IKVPair <IString, ICliqueNode> >)Output_data.Instance; IIntegerInstance input_key = (IIntegerInstance)Input_key.Instance; ICliqueNodeInstance input_value = (ICliqueNodeInstance)Input_value.Instance; //Debug Start // string saida = ""; // IIntegerInstance I = input_key; // ICliqueNodeInstance N = input_value; // saida = "TaskRank="+this.Rank+" <" + I.Value + ", ["; // IEnumerator<int> neighbor = N.NeighborsInstance.GetEnumerator (); // while (neighbor.MoveNext ()) { // saida = saida + neighbor.Current + " "; // } // saida = saida + "]>"; // using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"./logCliqueMap"+Rank, true)){ // file.WriteLine(saida); // } //Debug End IEnumerator <int> iterator = input_value.NeighborsInstance.GetEnumerator(); while (iterator.MoveNext()) { IKVPairInstance <IString, ICliqueNode> KV = (IKVPairInstance <IString, ICliqueNode>)Output_data.createItem(); ((IStringInstance)KV.Key).Value = iterator.Current.ToString(); ((ICliqueNodeInstance)KV.Value).IdInstance = input_value.IdInstance; ((ICliqueNodeInstance)KV.Value).NeighborsInstance = input_value.NeighborsInstance; output.put(KV); } }
public void graph_creator() { IKVPairInstance <IInteger, IIterator <IInputFormat> > input_gifs_instance = (IKVPairInstance <IInteger, IIterator <IInputFormat> >)Graph_values.Instance; IIteratorInstance <IInputFormat> vgifs = (IIteratorInstance <IInputFormat>)input_gifs_instance.Value; object o; if (partition_own == null) { if (vgifs.fetch_next(out o)) { IInputFormatInstance gif = (IInputFormatInstance)o; partition = gif.PartitionTABLE; partition_size = gif.PARTITION_SIZE; g = Graph.newInstance(gif.VSIZE); g.DataContainer.AllowingLoops = false; g.DataContainer.AllowingMultipleEdges = false; graph_creator_aux(gif); partition_own = new bool[partition_size]; partition_own [gif.PARTID] = true; this.partid = gif.PARTID; } } while (vgifs.fetch_next(out o)) { graph_creator_aux((IInputFormatInstance)o); partition_own [((IInputFormatInstance)o).PARTID] = true; } }
public void gust0() { IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value_instance = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance; IEnumerator <int> V = g.vertexSet().GetEnumerator(); while (V.MoveNext()) { int v = V.Current; if (!isGhost(v)) { ICollection <int> vneighbors = g.neighborsOf(v); foreach (int w in vneighbors) { if (v < w) //buscam-se os vérices maiores que v e com partições distintas { if (partition[v - 1] != partition[w - 1]) { IKVPairInstance <IVertex, IDataTriangle> item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem(); ((IVertexInstance)item.Key).Id = w; ((IDataTriangleInstance)item.Value).V = v; output_value_instance.put(item); } } } } } }
private void file_reader() { string fileName = System.Environment.GetEnvironmentVariable("PATH_GRAPH_FILE"); IInputFormatInstance extractor_input_format = (IInputFormatInstance)server.fetchFileContentObject(); extractor_input_format.PARTITION_SIZE = partition_size; IDictionary <int, IInputFormatInstance> sub_formats = extractor_input_format.extractBins(fileName); this.PartitionTABLE = extractor_input_format.PartitionTABLE; foreach (IInputFormatInstance shard in sub_formats.Values) { IKVPairInstance <IInteger, IInputFormat> item = (IKVPairInstance <IInteger, IInputFormat>)client.createItem(); int first_vertex_id_from_partition = shard.firstVertex(shard.PARTID); ((IIntegerInstance)item.Key).Value = first_vertex_id_from_partition; //counter_write_global; item.Value = shard; client.put(item); counter_write_chunk++; //counter_write_global++; if (counter_write_chunk >= CHUNK_SIZE) { Console.WriteLine("NEW CHUNK size=" + counter_write_chunk); counter_write_chunk = 0; client.finish(); } } client.finish(); client.finish(); Console.WriteLine("FINISHING READING DATA SOURCE"); }
public override void main() { Trace.WriteLine(Rank + ": START COMBINE FUNCTION #1"); IIteratorInstance <ORV> input_data_instance = (IIteratorInstance <ORV>)Input_data.Instance; IKVPairInstance <IInteger, IIterator <IPathInfo> > output_data_instance = (IKVPairInstance <IInteger, IIterator <IPathInfo> >)Output_data.Instance; Trace.WriteLine(Rank + ": START COMBINE FUNCTION #2"); IIntegerInstance done_flag = (IIntegerInstance)output_data_instance.Key; IIteratorInstance <IPathInfo> output_distances = (IIteratorInstance <IPathInfo>)output_data_instance.Value; Trace.WriteLine(Rank + ": START COMBINE FUNCTION #3"); bool done = true; object o; while (input_data_instance.fetch_next(out o)) { IKVPairInstance <IInteger, IIterator <IPathInfo> > kv = (IKVPairInstance <IInteger, IIterator <IPathInfo> >)o; IIntegerInstance k = (IIntegerInstance)kv.Key; Trace.WriteLine(Rank + ": LOOP #1 COMBINE FUNCTION " + k.Value); output_distances.putAll((IIteratorInstance <IPathInfo>)kv.Value); done = done && k.Value == 1; } output_distances.finish(); done_flag.Value = done ? 1 : 0; Trace.WriteLine(Rank + ": END COMBINE FUNCTION " + done); }
public object newInstance() { IKVPairInstance <V, V> kv = (IKVPairInstance <V, V>)Vertices.newInstance(); this.instance = new IEdgeBasicInstanceImpl <V, int> (((IVertexInstance)kv.Key).Id, ((IVertexInstance)kv.Value).Id); return(this.instance); }
public override void main() { Trace.WriteLine(Rank + ": START SPLIT PATH INFO 1"); IIteratorInstance <IPathInfo> input_data_instance = (IIteratorInstance <IPathInfo>)Input_data.Instance; IIteratorInstance <IKVPair <IInteger, IPathInfo> > output_data_instance = (IIteratorInstance <IKVPair <IInteger, IPathInfo> >)Output_data.Instance; Trace.WriteLine(Rank + ": START SPLIT PATH INFO 2"); object path_info; while (input_data_instance.fetch_next(out path_info)) { Trace.WriteLine(Rank + ": LOOP SPLIT PATH INFO " + path_info.GetType()); IPathInfoInstance path_info_instance = (IPathInfoInstance)path_info; IKVPairInstance <IInteger, IPathInfo> path_info_output = (IKVPairInstance <IInteger, IPathInfo>)Output_data.createItem(); ((IIntegerInstance)path_info_output.Key).Value = ((Info)path_info_instance.Value).vertex; path_info_output.Value = path_info_instance; Trace.WriteLine(Rank + ": vertex = " + path_info_output.Key); output_data_instance.put(path_info_output); } output_data_instance.finish(); Trace.Write(Rank + ": STOP SPLIT PATH INFO "); }
private void emite(int a, int b, int c, IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value) { IKVPairInstance <IVertex, IDataTriangle> item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem(); ((IVertexInstance)item.Key).Id = a; //a menor que b ((IDataTriangleInstance)item.Value).V = b; //b menor que c ((IDataTriangleInstance)item.Value).W = c; output_value.put(item); }
public override void main() { int done = 0; IStringInstance input_data_instance = (IStringInstance)Input_data.Instance; IStringInstance output_data_instance = (IStringInstance)Output_data.Instance; IIteratorInstance <IPathInfo> initial_data_instance = (IIteratorInstance <IPathInfo>)Initial_data.Instance; IKVPairInstance <IInteger, IIterator <IPathInfo> > final_distances_instance = (IKVPairInstance <IInteger, IIterator <IPathInfo> >)Final_distances.Instance; IIntegerInstance termination_flag = (IIntegerInstance)Termination_flag.Instance; string setE = input_data_instance.Value; string setV = "1 c 0" + System.Environment.NewLine; IDictionary <int, int> vertices = new Dictionary <int, int>(); foreach (string edge in setE.Split(System.Environment.NewLine.ToCharArray())) { if (edge.Length > 0) { int vertex = edge [0]; if (!vertices.ContainsKey(vertex)) { setV += edge [0] + " d " + int.MaxValue + System.Environment.NewLine; vertices.Add(vertex, vertex); } } } feedInitialData(setV + System.Environment.NewLine + setE, initial_data_instance); int count = 0; while (done == 0) { Console.WriteLine(Rank + ": ITERATION PATH_FLOW FAST GO ! - " + (++count)); this.Path_flow.go(); done = ((IIntegerInstance)final_distances_instance.Key).Value; termination_flag.Value = done; Set_termination_flag.go(); if (done == 0) { Trace.WriteLine(Rank + ": Exchange #1"); initial_data_instance.putAll((IIteratorInstance <IPathInfo>)final_distances_instance.Value); initial_data_instance.finish(); Trace.WriteLine(Rank + ": Exchange #2"); } } outputFinalDistances((IIteratorInstance <IPathInfo>)final_distances_instance.Value, output_data_instance); Trace.WriteLine(Rank + ": --- FINISH PATH_FLOW.GO !"); }
public void pull() { IKVPairInstance <IVertex, IIterator <IDataTriangle> > input_values_instance = (IKVPairInstance <IVertex, IIterator <IDataTriangle> >)Input_values.Instance; IIteratorInstance <IDataTriangle> ivalues = (IIteratorInstance <IDataTriangle>)input_values_instance.Value; object o; //Sendo a etapa 1, o algoritmo começa no gust0()! //Porém, descarta-se mensagens de sinalização, emitidas no startup_push da etapa 3 (TC3Impl), o que confirma que InputFormat chegou com sucesso naquela etapa while (ivalues.fetch_next(out o)) { } }
public void read_send_graph(int gusty_size, IDictionary <int, Tuple <int, int> > unit_ref) { IIteratorInstance <IKVPair <IInteger, GIF> > input_instance_graph = (IIteratorInstance <IKVPair <IInteger, GIF> >)Collect_graph.Client; object bin_object = null; IActionFuture sync_perform; Partition_function_gif.NumberOfPartitions = gusty_size; bool end_iteration_gif = false; bool set_table = true; while (!end_iteration_gif) { Task_binding_shuffle.invoke(ITaskPortAdvance.READ_CHUNK); Task_binding_shuffle.invoke(ITaskPortAdvance.PERFORM, out sync_perform); IList <IKVPairInstance <IInteger, GIF> >[] buffer_gif = new IList <IKVPairInstance <IInteger, GIF> > [gusty_size]; for (int i = 0; i < gusty_size; i++) { buffer_gif [i] = new List <IKVPairInstance <IInteger, GIF> > (); } IKVPairInstance <IInteger, GIF> item = null; if (!input_instance_graph.has_next()) { end_iteration_gif = true; } int count = 0; while (input_instance_graph.fetch_next(out bin_object)) { item = (IKVPairInstance <IInteger, GIF>)bin_object; this.Input_key_gif.Instance = item.Value; //item.Key; Partition_function_gif.go(); int index = ((IIntegerInstance)this.Output_key_gif.Instance).Value; buffer_gif [index].Add(item); Console.WriteLine(this.GlobalRank + ": SHUFFLER MAP Collector Graph count=" + (count++)); } // PERFORM for (int i = 0; i < gusty_size; i++) { Step_channel.Send(buffer_gif [i], unit_ref [i], end_iteration_gif ? TAG_SHUFFLE_OMV_END_CHUNK : TAG_SHUFFLE_OMV_NEW_CHUNK); } sync_perform.wait(); Task_binding_shuffle.invoke(ITaskPortAdvance.CHUNK_READY); } Partition_function.PartitionTABLE = Partition_function_gif.PartitionTABLE; }
public override void main() { IStringInstance input = (IStringInstance)Input_value.Instance; IIteratorInstance <IKVPair <IString, IString> > output = (IIteratorInstance <IKVPair <IString, IString> >)Output_data.Instance; if (!input.Value.Equals("")) { string[] words = input.Value.Split(' '); IKVPairInstance <IString, IString> kvpair = (IKVPairInstance <IString, IString>)Output_data.createItem(); ((IStringInstance)kvpair.Key).Value = words [0]; ((IStringInstance)kvpair.Value).Value = words [1] + " " + words [2]; output.put(kvpair); } }
public void apply() { string buffer = ""; foreach (KeyValuePair <int, double> kv in Di) { buffer = buffer + kv.Key + " d " + kv.Value + System.Environment.NewLine; } IKVPairInstance <IString, IString> orv = (IKVPairInstance <IString, IString>)Output_value.newInstance(); ((IStringInstance)orv.Key).Value = "1"; ((IStringInstance)orv.Value).Value = buffer; }
} // Isso é necessário no caso de IKey ser do tipo IVertex. #endregion #region Algorithm implementation public void startup_push() { IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value_instance = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance; IEnumerator <int> V = g.vertexSet().GetEnumerator(); while (V.MoveNext()) { int v = V.Current; if (!isGhost(v)) { ICollection <int> vneighbors = g.neighborsOf(v); foreach (int w in vneighbors) { if (v < w) //buscam-se os vérices maiores { if (isGhost(w)) { IKVPairInstance <IVertex, IDataTriangle> item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem(); IVertexInstance ok = (IVertexInstance)item.Key; IDataTriangleInstance ov = (IDataTriangleInstance)item.Value; ok.Id = w; ov.V = v; output_value_instance.put(item); } else { IList <KeyValuePair <int, int> > l; if (!triangles.TryGetValue(v, out l)) { l = new List <KeyValuePair <int, int> > (); triangles[v] = l; } IEnumerator <int> wneighbors = g.iteratorNeighborsOf(w); while (wneighbors.MoveNext()) { int z = wneighbors.Current; if (w < z && vneighbors.Contains(z)) { l.Add(new KeyValuePair <int, int> (w, z)); count++; } } } } } } } }
public void gust0() { IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value_instance = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance; ConcurrentDictionary <int, IList <KeyValuePair <int, int> > > buffer_tmp = new ConcurrentDictionary <int, IList <KeyValuePair <int, int> > >(); IEnumerator <int> next = messages.Keys.GetEnumerator(); while (next.MoveNext()) { int w = next.Current; IList <KeyValuePair <int, int> > l; messages.TryRemove(w, out l); IEnumerator <int> wneighbors = g.iteratorNeighborsOf(w); while (wneighbors.MoveNext()) { int z = wneighbors.Current; if (w < z) { foreach (KeyValuePair <int, int> kvw in l) { int v = kvw.Key; if (isGhost(v)) { IKVPairInstance <IVertex, IDataTriangle> item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem(); IVertexInstance ok = (IVertexInstance)item.Key; IDataTriangleInstance ov = (IDataTriangleInstance)item.Value; ok.Id = v; ov.V = z; ov.W = w; output_value_instance.put(item); } else { IList <KeyValuePair <int, int> > lz; if (!buffer_tmp.TryGetValue(v, out lz)) { lz = new List <KeyValuePair <int, int> > (); buffer_tmp[v] = lz; } lz.Add(new KeyValuePair <int, int>(z, w)); } } } } } messages = buffer_tmp; }
public void pull() { IKVPairInstance <IVertex, IIterator <IDataTriangle> > input_values_instance = (IKVPairInstance <IVertex, IIterator <IDataTriangle> >)Input_values.Instance; IVertexInstance ikey = (IVertexInstance)input_values_instance.Key; IIteratorInstance <IDataTriangle> ivalues = (IIteratorInstance <IDataTriangle>)input_values_instance.Value; IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance; object o; int w = ikey.Id; while (ivalues.fetch_next(out o)) { int v = ((IDataTriangleInstance)o).V; int z = ((IDataTriangleInstance)o).W; IEnumerator <int> wneighbors = g.iteratorNeighborsOf(w); while (wneighbors.MoveNext()) { int zw = wneighbors.Current; if (w < zw) { if (z == 0) { IKVPairInstance <IVertex, IDataTriangle> item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem(); IVertexInstance ok = (IVertexInstance)item.Key; IDataTriangleInstance ov = (IDataTriangleInstance)item.Value; ok.Id = v; ov.V = w; ov.W = zw; output_value.put(item); } else { IList <KeyValuePair <int, int> > l; if (!triangles.TryGetValue(w, out l)) { l = new List <KeyValuePair <int, int> > (); triangles [w] = l; } if (z == zw) { l.Add(new KeyValuePair <int, int>(v, zw)); count++; } } } } } }
public override void main() { Console.WriteLine("################################*IAplicacaoImpl Start ###############################"); IDoubleInstance tDouble = (IDoubleInstance)T_double.Instance; IKVPairInstance <IString, IDouble> tKVPair = (IKVPairInstance <IString, IDouble>)T_kvpair.Instance; //.newInstance (); IIntegerInstance tInteger = (IIntegerInstance)T_integer.Instance; IIteratorInstance <IInteger> tIterator = (IIteratorInstance <IInteger>)T_iterator.Instance; //.newInstance (); IStringInstance tString = (IStringInstance)T_string.Instance; tDouble.Value = 0.8; tInteger.Value = 8; tString.Value = "Tipo String"; ((IStringInstance)tKVPair.Key).Value = tString.Value; ((IDoubleInstance)tKVPair.Value).Value = tDouble.Value; tIterator.put(tInteger); tIterator.finish(); object o; int count = 0; while (tIterator.fetch_next(out o)) { IIntegerInstance oI = (IIntegerInstance)o; Console.WriteLine("Item Iterator " + (count++) + ": " + oI.Value); } Console.WriteLine("tDouble.Value=" + tDouble.Value + " : " + "tInteger.Value=" + tInteger.Value + " : " + "tString.Value=" + tString.Value); Console.WriteLine("tKVPair.Key=" + ((IStringInstance)tKVPair.Key).Value + " : " + "tKVPair.Value=" + ((IDoubleInstance)tKVPair.Value).Value); IPageNodeInstance instance = (IPageNodeInstance)T_aplicacao_node.Instance; ((IIntegerInstance)instance.IdInstance).Value = 8; IIntegerInstance item = (IIntegerInstance)T_aplicacao_node.Edge_node.createItem(); item.Value = 7; instance.NeighborsInstance.put(item); instance.NeighborsInstance.put(((IIntegerInstance)instance.IdInstance)); instance.NeighborsInstance.finish(); while (instance.NeighborsInstance.fetch_next(out o)) { IIntegerInstance II = (IIntegerInstance)o; Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%% Valor no Iterator=" + II.Value); } Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%% Resultado Id_node=" + ((IIntegerInstance)instance.IdInstance).Value + " PGRank=" + instance.PgrankInstance.Value); Console.WriteLine("################################ IAplicacaoImpl End ###############################"); }
public override void main() { /* 1. Ler pares chave (OMK) e valores (OMV) de Input. * 2. Para cada par, atribuir a Key e Values e chamar Reduce_function.go(); * 3. Pegar o resultado de Reduction_function.go() de Output_reduce (ORV) * e colocar no iterator Output. */ IIteratorInstance <IKVPair <OMK, IIterator <OMV> > > input_instance = (IIteratorInstance <IKVPair <OMK, IIterator <OMV> > >)Input.Instance; IIteratorInstance <ORV> output_instance = (IIteratorInstance <ORV>)Output.Instance; //long t0 = (long)(DateTime.UtcNow - (new DateTime (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))).TotalMilliseconds; object kvpair_object; while (input_instance.fetch_next(out kvpair_object)) { IKVPairInstance <OMK, IIterator <OMV> > kvpair = (IKVPairInstance <OMK, IIterator <OMV> >)kvpair_object; Input_reduce.Instance = kvpair; Reduce_function.go(); active++; active = active - Reduce_function.Active; } string candidates_buffer = sincronize(); while (active > 0) { active = 0; string[] lines = candidates_buffer.Split(new char[] { System.Environment.NewLine[0] }); foreach (string line in lines) { if (!line.Trim().Equals("")) { string[] values = line.Split(' '); Reduce_function.step(int.Parse(values[0]), double.Parse(values[1])); active++; active = active - Reduce_function.Active; } } candidates_buffer = sincronize(); } Reduce_function.apply(); output_instance.put(Output_reduce.Instance); output_instance.finish(); //long t1 = (long)(DateTime.UtcNow - (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))).TotalMilliseconds; //writeFile ("./logTIME-REDUCE", "TIME: " + (t1 - t0) + " ms."+System.Environment.NewLine+"BSP"); }
private void clear_gif_set_PartitionTABLE() { //Task_binding_split_next.invoke (ITaskPortAdvance.READ_CHUNK); Task_binding_split_next.invoke (ITaskPortAdvance.PERFORM, out sync_perform); object bin_object = null; IIteratorInstance <IKVPair <IInteger, GIF> > input_graph_instance = (IIteratorInstance <IKVPair <IInteger, GIF> >)Collect_graph.Client; while (input_graph_instance.fetch_next(out bin_object)) { IKVPairInstance <IInteger, GIF> item = (IKVPairInstance <IInteger, GIF>)bin_object; this.Input_key_iterate_gif.Instance = item.Value; Bin_function_iterate_gif.go(); ((IInputFormatInstance)item.Value).Clear(); //int index = ((IIntegerInstance)this.Output_key_iterate_gif.Instance).Value; } Bin_function_iterate.PartitionTABLE = Bin_function_iterate_gif.PartitionTABLE; //sync_perform.wait (); }
public override void main() { Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES SOURCE) - START "); /* 1. Ler os elementos de Source_data, um a um, e copiar a chave (OMK) em Data_key. * 2. A cada chave de Source_data, chamar Partition_function.go(); * 3. Enviar o resultado de Partition_function.go(), via MPI, para o gerente (unidade target). */ int[] reducer_ranks = this.UnitRanks["reducer"]; int nr = this.UnitSize["reducer"]; Partition_function.NumberOfPartitions = nr; IIteratorInstance <IKVPair <OMK, OMV> > map_result_instance = (IIteratorInstance <IKVPair <OMK, OMV> >)Map_result.Instance; int count = 0; IKVPairInstance <OMK, OMV> last_item = null; object item_object; // 1. Ler os elementos de Source_data, um a um, e copiar a chave (OMK) em Data_key. while (map_result_instance.fetch_next(out item_object)) { IKVPairInstance <OMK, OMV> item = (IKVPairInstance <OMK, OMV>)item_object; last_item = item; Data_key.Instance = item.Key; // 2. A cada chave de Source_data, chamar Partition_function.go(); Partition_function.go(); int i = (int)((IIntegerInstance)Partition_key.Instance).Value; Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES SOURCE) LOOP - SEND TO " + reducer_ranks[i] + ", source rank is " + comm.Rank + ", count=" + (count++) + "i=" + i); comm.Send <IKVPairInstance <OMK, OMV> >(item, reducer_ranks[i], TAG_FETCHVALUES_OMV); } for (int i = 0; i < nr; i++) { comm.Send <IKVPairInstance <OMK, OMV> >(last_item, reducer_ranks[i], TAG_FETCHVALUES_OMV_FINISH); } Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES SOURCE) - FINISH "); }