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 "); }
void feedInitialData(string setE, IIteratorInstance <IPathInfo> initial_data_instance) { string[] lines = setE.Split(new char[] { System.Environment.NewLine[0] }); foreach (string line in lines) { if (!line.Trim().Equals("")) { Trace.WriteLine(Rank + ": LINE = " + line); string[] edge_info_items = line.Split(' '); IPathInfoInstance edge = (IPathInfoInstance)Initial_data.createItem(); char item_type = edge_info_items [1] [0]; switch (item_type) { case 'c': DistanceInfo dist_instance_c = new DistanceInfo(); dist_instance_c.info_type = Info.PATH_INFO_TYPE_DISTANCE_TRIAL; dist_instance_c.vertex = int.Parse(edge_info_items [0]); dist_instance_c.distance = int.Parse(edge_info_items [2]); edge.Value = dist_instance_c; Trace.WriteLine(Rank + ": c " + dist_instance_c.info_type + " " + dist_instance_c.vertex + " " + dist_instance_c.distance); break; case 'd': DistanceInfo dist_instance_d = new DistanceInfo(); dist_instance_d.info_type = Info.PATH_INFO_TYPE_DISTANCE_TRIAL; dist_instance_d.vertex = int.Parse(edge_info_items [0]); dist_instance_d.distance = int.Parse(edge_info_items [2]); edge.Value = dist_instance_d; Trace.WriteLine(Rank + ": d " + dist_instance_d.info_type + " " + dist_instance_d.vertex + " " + dist_instance_d.distance); break; default: EdgeInfo edge_info = new EdgeInfo(); edge_info.info_type = Info.PATH_INFO_TYPE_EDGE; edge_info.vertex = int.Parse(edge_info_items[0]); edge_info.vertex_other = int.Parse(edge_info_items[1]); edge_info.weight = int.Parse(edge_info_items[2]); edge.Value = edge_info; Trace.WriteLine(Rank + ": edge " + edge_info.info_type + " " + edge_info.vertex + " " + edge_info.vertex_other + " " + edge_info.weight); break; } initial_data_instance.put(edge); } } initial_data_instance.finish(); }
void outputFinalDistances(IIteratorInstance <IPathInfo> final_distances_instance, IStringInstance output_data_instance) { string output_string = ""; object o; while (final_distances_instance.fetch_next(out o)) { IPathInfoInstance path_info = (IPathInfoInstance)o; DistanceInfo distance_info = (DistanceInfo)path_info.Value; if (distance_info.info_type.Equals(Info.PATH_INFO_TYPE_DISTANCE_PARTIAL)) { Console.WriteLine("OUTPUT : " + path_info.Value); output_string += distance_info.vertex + " d " + distance_info.distance + System.Environment.NewLine; } else { throw new Exception("PathFlowImpl.IMasterImpl.outputFinalDistances: something goes wrong when reading output distances (unexpected result : " + distance_info + ")" + distance_info.info_type + " --- " + Info.PATH_INFO_TYPE_DISTANCE_PARTIAL); } } output_data_instance.Value = output_string; }
public override void main() { int di = int.MaxValue; int dmin = int.MaxValue; int done = 1; Trace.WriteLine(Rank + ": START REDUCE FUNCTION"); IKVPairInstance <IInteger, IIterator <IPathInfo> > input_instance = (IKVPairInstance <IInteger, IIterator <IPathInfo> >)Input_values.Instance; IIntegerInstance k = (IIntegerInstance)input_instance.Key; IIteratorInstance <IPathInfo> v = (IIteratorInstance <IPathInfo>)input_instance.Value; int k_int = k.Value; if (!neighbours.ContainsKey(k_int)) { neighbours [k_int] = new Dictionary <int, int> (); } object o; while (v.fetch_next(out o)) { IPathInfoInstance item = (IPathInfoInstance)o; Info item_info = (Info)item.Value; Trace.WriteLine(Rank + ": REDUCE FUNCTION LOOP " + item_info); switch (item_info.info_type) { case Info.PATH_INFO_TYPE_DISTANCE_TRIAL: DistanceInfo distance_item_info_1 = (DistanceInfo)item_info; int tmp = distance_item_info_1.distance; dmin = (int)min(dmin, tmp); break; case Info.PATH_INFO_TYPE_DISTANCE_PARTIAL: DistanceInfo distance_item_info_2 = (DistanceInfo)item_info; di = distance_item_info_2.distance; break; case Info.PATH_INFO_TYPE_EDGE: EdgeInfo edge_item_info = (EdgeInfo)item_info; IDictionary <int, int> output_neibours = neighbours[k_int]; int n = edge_item_info.vertex_other; int d = 0; if (!output_neibours.TryGetValue(n, out d)) { output_neibours[n] = edge_item_info.weight; } else if (edge_item_info.weight < d) { output_neibours[n] = edge_item_info.weight; } break; } } Trace.WriteLine(Rank + ": REDUCE FUNCTION AFTER LOOP #1 "); IKVPairInstance <IInteger, IIterator <IPathInfo> > orv = (IKVPairInstance <IInteger, IIterator <IPathInfo> >)Output_value.newInstance(); IIteratorInstance <IPathInfo> buffer = (IIteratorInstance <IPathInfo>)orv.Value; Trace.WriteLine(Rank + ": REDUCE FUNCTION OUT LOOP #2 "); //IPathInfo path_info = buffer.createItem(); dmin = (int)min(dmin, di); if (dmin != di) { foreach (KeyValuePair <int, int> kv in neighbours[k_int]) { //IPathInfoInstance path_info_instance = (IPathInfoInstance) path_info.newInstance (); IPathInfoInstance path_info_instance = (IPathInfoInstance)buffer.createItem(); DistanceInfo distance_info = new DistanceInfo(); distance_info.info_type = Info.PATH_INFO_TYPE_DISTANCE_TRIAL; distance_info.vertex = kv.Key; distance_info.distance = kv.Value + dmin; path_info_instance.Value = distance_info; buffer.put(path_info_instance); Trace.WriteLine(Rank + ": REDUCE FUNCTION OTHER LOOP " + distance_info); } done = 0; } ((IIntegerInstance)orv.Key).Value = done; IPathInfoInstance path_info_instance_2 = (IPathInfoInstance)buffer.createItem(); DistanceInfo distance_info_2 = new DistanceInfo(); distance_info_2.info_type = Info.PATH_INFO_TYPE_DISTANCE_PARTIAL; distance_info_2.vertex = k.Value; distance_info_2.distance = dmin; path_info_instance_2.Value = distance_info_2; buffer.put(path_info_instance_2); Trace.WriteLine(Rank + ": REDUCE FUNCTION OTHER LOOP OUT " + distance_info_2); buffer.finish(); Trace.WriteLine(Rank + ": FINISH REDUCE FUNCTION"); }