public override void RunHandler(ConfigurationMessageReader request) { Console.WriteLine("Started Run"); int mapped_node; if (ranLoader == false) { Console.WriteLine("Loader not run before"); } else { benchmarkAlgorithm.setMaxNode(loader[Global.MyServerID].getMaxNode()); benchmarkAlgorithm.mapping1 = loader[Global.MyServerID].mapping1; benchmarkAlgorithm.mapping2 = loader[Global.MyServerID].mapping2; //benchmarkAlgorithm.mapping1_array = loader.mapping1_array; benchmarkAlgorithm.graph_name = graph_name; benchmarkAlgorithm.e_log_path = e_log_path; benchmarkAlgorithm.setOutputPath(e_output_path); mapped_node = (int)loader[Global.MyServerID].mapping2[this.source_vertex]; Console.WriteLine("Start at {0}", mapped_node); SimpleGraphNode rootNode = Global.CloudStorage.LoadSimpleGraphNode(mapped_node); benchmarkAlgorithm.all_starts = loader[Global.MyServerID].all_starts; benchmarkAlgorithm.BFSLocal(rootNode); ranLoader = true; /** * //Distributed Try with Message Sorter * for(int i = 0; i < Global.ServerCount; i++){ * FinishCommunicator fc = new FinishCommunicator(); * fc.Finished = false; * fc.LastLoad = false; * long fcid = i; * //Console.WriteLine("CREATE COMMUNICATION CELL:" + fcid); * Global.CloudStorage.SaveFinishCommunicator(Int64.MaxValue-fcid, fc); * } **/ //StartBFS(mapped_node); } /** * Thread.Sleep(1000); * while(msgQueue.Count > 0){ * Thread.Sleep(10); * } * Console.WriteLine("FinishedServer0");**/ }
/// <summary> /// Create graph showing how accounts are related via Transfer transactions. /// </summary> /// <param name="myMoney">The money data to analyze</param> /// <param name="fileName">The file name for the DGML graph output</param> public void ExportDgmlAccountMap(MyMoney myMoney, string fileName) { SimpleGraph sg = new SimpleGraph(); foreach (Transaction t in myMoney.Transactions) { SimpleGraphNode n = sg.AddOrGetNode(t.AccountName); n.Category = t.Account.Type.ToString(); // Look for Transfer FROM transactions if (t.TransferTo != null && t.Amount < 0) { // Create a Link that shows a IncomingAccount To This Account SimpleGraphLink link = sg.GetOrAddLink(t.AccountName, t.TransferTo); SimpleGraphProperty sgp = link.GetProperty("Label"); if (sgp == null) { sgp = link.AddProperty("Label", 0); } sgp.Value = Convert.ToDecimal(sgp.Value) + Math.Abs(t.Amount); } } // // Convert all Label that looks like numeric values into a "Currency" look // foreach (SimpleGraphLink l in sg.Links) { try { SimpleGraphProperty sgp = l.GetProperty("Label"); sgp.Value = Convert.ToDecimal(sgp.Value).ToString("C2"); } catch { } } sg.Save(fileName, styleForGraph_Accounts); }
private void NavigateSaveToBasicXMLTokens(SimpleGraphNode parent, RSTEdu edu, List <SimpleGraphNode> nodes, List <SimpleGraphRelation> relations) { var texto = new StringBuilder(); foreach (var item in edu.tokens) { texto.Append(item.lemma + " "); } var target = new SimpleGraphNode() { Id = nodes.Count + 1, Label = texto.ToString() }; nodes.Add(target); relations.Add(new SimpleGraphRelation() { Start = parent.Id, End = target.Id, Label = "-" }); }
public void dumpLoadCells() { try{ using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"load_dump.dmp", true)) { foreach (KeyValuePair <long, long> entry in mapping2) { try{ SimpleGraphNode simpleGraphNode = Global.CloudStorage.LoadSimpleGraphNode(entry.Key); foreach (long link in simpleGraphNode.Outlinks) { file.WriteLine(entry.Value + " " + mapping1[link]); } } catch (Exception ex) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(ex.Message); } } } } catch (Exception ex) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(ex.Message); } }
public void printGraphNode(SimpleGraphNode node) { Console.WriteLine("Save Node " + node.ID + " OUT: " + String.Join(",", node.Outlinks)); }
public void AddEdge(long cellid1, long cellid2, float weight, bool single_element, int threadid) { //Console.WriteLine("[READ"+threadid+"] AddEdge " + cellid1 + " -> " + cellid2); Interlocked.Increment(ref all_threads_equeued_edges); // Single Element is either undirected inversion or special insert because no outgoing edges of vertex exist if (single_element) { if (cellid2 == -1) { // Insert Empty Node //Console.WriteLine("[READ"+threadid+"] AddEdge (EMPTY) " + cellid1 + " -> " + cellid2); SimpleGraphNode emptyGraphNode = new SimpleGraphNode(); emptyGraphNode.ID = cellid1; emptyGraphNode.Outlinks = new List <long>(); emptyGraphNode.Weights = new List <float>(); thread_cache[threadid].Enqueue(emptyGraphNode); } else { // Insert Inversion if (cellid1 == -1) { return; } int destination_server = findServer(cellid1); //Console.WriteLine("[READ"+threadid+"] AddEdge{"+this_server_id+"} (INVERSION S["+destination_server+"]) " + cellid1 + " -> " + cellid2); if (destination_server == this_server_id) { //Console.WriteLine("[READ"+threadid+"] AddEdge (INVERSION LOCAL) " + cellid1 + " -> " + cellid2); SimpleGraphNode invGraphNode = new SimpleGraphNode(); invGraphNode.ID = cellid1; invGraphNode.Outlinks = new List <long>(); invGraphNode.Weights = new List <float>(); invGraphNode.Outlinks.Add(cellid2); if (hasWeight) { invGraphNode.Weights.Add(weight); } thread_cache[threadid].Enqueue(invGraphNode); } else { //Console.WriteLine("[READ"+threadid+"] AddEdge (to Load) " + cellid2 + " -> " + cellid1); // Add to DistributedLoad Load new_load = new Load(); new_load.cellid1 = cellid1; new_load.cellid2 = cellid2; new_load.weight = weight; new_load.single_element = single_element; Interlocked.Increment(ref all_threads_equeued_load_edges); load_sender_queue[destination_server].Enqueue(new_load); } } } else { if (simpleBufferNode[threadid].ID != cellid1) { if (simpleBufferNode[threadid].ID > 0) { //Console.WriteLine("[READ"+threadid+"] AddEdge (Cache to Queue) for " + simpleBufferNode[threadid].ID + " OUT: " + String.Join(",", simpleBufferNode[threadid].Outlinks)); thread_cache[threadid].Enqueue(simpleBufferNode[threadid]); } //Console.WriteLine("[READ"+threadid+"] AddEdge (to BufferNode) " + cellid1 + " -> " + cellid2); simpleBufferNode[threadid] = new SimpleGraphNode(); simpleBufferNode[threadid].ID = cellid1; simpleBufferNode[threadid].Outlinks = new List <long>(); simpleBufferNode[threadid].Weights = new List <float>(); //copy of else below simpleBufferNode[threadid].Outlinks.Add(cellid2); if (hasWeight) { simpleBufferNode[threadid].Weights.Add(weight); } } else { //Console.WriteLine("[READ"+threadid+"] AddEdge (to BufferNode) " + cellid1 + " -> " + cellid2); simpleBufferNode[threadid].Outlinks.Add(cellid2); if (hasWeight) { simpleBufferNode[threadid].Weights.Add(weight); } } } }
public void BFS(SimpleGraphNode root) { Start_time_Stamp = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; var watch = System.Diagnostics.Stopwatch.StartNew(); //init array with max distances --> requires amount of elements int graph_size = (int)max_node; Console.WriteLine("Size of Array: {0}", graph_size); Console.WriteLine("Try to access: {0}", root.CellId); Int64[] depth = new Int64[graph_size + 1]; for (int i = 1; i <= graph_size; i++) { depth[i] = Int64.MaxValue; } Queue queue = new Queue(); queue.Enqueue(root); depth[root.CellId] = 0; long nodes_visited = 0; while (queue.Count > 0) { SimpleGraphNode current_node = (SimpleGraphNode)queue.Dequeue(); //Console.WriteLine(current_node.CellId); foreach (var out_edge_id in current_node.Outlinks) { //Console.WriteLine("Outgoing: " + out_edge_id); nodes_visited++; if (nodes_visited % 1000000 == 0) { //Console.Write(" Nodes Visited: " + nodes_visited / 1000000 + "M\r"); } if (depth[out_edge_id] == Int64.MaxValue) { depth[out_edge_id] = depth[current_node.CellId] + 1; try { queue.Enqueue(Global.CloudStorage.LoadSimpleGraphNode(out_edge_id)); } catch (Exception ex) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(ex.Message); errorWriter.WriteLine("Cell not found Error: " + out_edge_id); } } } } End_time_Stamp = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; elapsedTime_lastRun = elapsedMs; Console.WriteLine("----------------------------------"); Console.WriteLine("Runtime: {0} (ms)", elapsedTime_lastRun); using (System.IO.StreamWriter file = new System.IO.StreamWriter("benchmark.info")) { file.WriteLine("Algorithm: " + graph_name + " Runtime:" + elapsedTime_lastRun); } /**using (System.IO.StreamWriter file = new System.IO.StreamWriter(@output_path)) * { * file.WriteLine("Algorithm: " + graph_name); * }**/ if (output_path == null || output_path == "") { output_path = "output.txt"; } Console.WriteLine("Write File to " + output_path); try{ using (System.IO.StreamWriter file = new System.IO.StreamWriter(@output_path, true)) { /**if(!silent) * { * if (depth[i] != Int64.MaxValue){ * Console.WriteLine("Depth of " + i + " (from " + root.CellId + ") is " + depth[i] + " Mapped to: " + mapping1[i]); * } * //file.WriteLine("Depth of " + i + " (from " + root.CellId + ") is " + depth[i] + " Mapped to: " + mapping1[i]); * }**/ for (int i = 1; i <= graph_size; i++) { //file.WriteLine(mapping1_array[i] + " " + depth[i]); file.WriteLine(mapping1[i - 1] + " " + depth[i]); // hash alternative } } } catch (Exception ex) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(ex.Message); } if (e_log_path == null || e_log_path == "") { e_log_path = "metrics.txt"; } else { e_log_path = e_log_path + "/metrics.txt"; } Console.WriteLine("Write Log File to " + e_log_path); try{ using (System.IO.StreamWriter file = new System.IO.StreamWriter(@e_log_path, true)) { file.WriteLine("Processing starts at " + Start_time_Stamp); file.WriteLine("Processing ends at " + End_time_Stamp); } } catch (Exception ex) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(ex.Message); } Console.WriteLine("##################################"); Console.WriteLine("####### Finished Run #######"); Console.WriteLine("##################################"); }
public void BFSLocal(SimpleGraphNode root) { num_servers = Global.ServerCount; for (int i = 0; i < num_servers; i++) { Console.WriteLine("SERVER" + i + " at " + all_starts[i]); } Start_time_Stamp = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; var watch = System.Diagnostics.Stopwatch.StartNew(); //init array with max distances --> requires amount of elements int graph_size = (int)max_node; Console.WriteLine("Size of Array: {0}", graph_size); Console.WriteLine("Try to access: {0}", root.CellId); Int64[] depth = new Int64[graph_size + 1]; for (int i = 1; i <= graph_size; i++) { depth[i] = Int64.MaxValue; } bool[] visited = new bool[graph_size + 1]; int this_server_id = Global.MyServerID; Queue <long> queue = new Queue <long>(); Queue <BFSDummy> bfsqueue = new Queue <BFSDummy>(); BFSDummy dummy = new BFSDummy(); dummy.cellid = root.CellId; dummy.depth = 0; bfsqueue.Enqueue(dummy); HashSet <long> remoteSet = new HashSet <long>(); long last_level = 0; queue.Enqueue(root.CellId); depth[root.CellId] = 0; while (bfsqueue.Count > 0 || remoteSet.Count > 0) { /**long current_node = queue.Dequeue(); * if(!visited[current_node]){ * visited[current_node] = true; * //Console.WriteLine("Dequeued " + current_node); * int onServer = findServer(current_node); * //Console.WriteLine("Outgoing From: " + current_node + " on Server" + onServer); * if(onServer == this_server_id){ * //Console.WriteLine("[!] LOCAL " + current_node); * using (var tempCell = Global.LocalStorage.UseSimpleGraphNode(current_node)) { * for(int i = 0; i < tempCell.Outlinks.Count; i++){ * if (depth[tempCell.Outlinks[i]] > depth[current_node] + 1){ * depth[tempCell.Outlinks[i]] = depth[current_node] + 1; * //Console.WriteLine(tempCell.Outlinks[i] + " depth " + depth[tempCell.Outlinks[i]]); * queue.Enqueue(tempCell.Outlinks[i]); * } * } * } * } else { * using (var request = new NodeListWriter(current_node, 0)) * { * using (var response = Global.CloudStorage.NodeCollectionToBenchmarkServer(onServer, request)) * { * //Console.WriteLine("Response contains " + response.num_elements + "elements"); * List<long> array = response.Outlinks; * for(int i = 0; i < response.num_elements; i++){ * int outlink = (int) array[i]; * //Console.WriteLine("Cell " + outlink); * //Console.WriteLine("CNODE " + current_node + " has depth " + depth[current_node]); * if (depth[outlink] > depth[current_node] + 1){ * depth[outlink] = depth[current_node] + 1; * //Console.WriteLine(response.Outlinks[i] + " depth " + depth[response.Outlinks[i]]); * queue.Enqueue(response.Outlinks[i]); * } * } * } * } * } * }**/ ///////////////////////////////////////////// DUMMY IMPLEMENTATION ///////////////////////////////// bool dequed = false; BFSDummy current_dummy = new BFSDummy(); if (bfsqueue.Count > 0) { dequed = true; current_dummy = bfsqueue.Dequeue(); //Console.WriteLine("NODE:" + current_dummy.cellid); } if (!dequed || current_dummy.depth > last_level) { /////////// GATHER REMOTE (currently only one server!) -> HashSet[num_server] -> Check each HashSet.Count > 0 if (remoteSet.Count > 0) { Console.WriteLine("Remote Query"); Queue <long> queueToSend = new Queue <long>(); foreach (long i in remoteSet) { queueToSend.Enqueue(i); } remoteSet = new HashSet <long>(); while (queueToSend.Count > 0) { List <long> listToSend = new List <long>(); for (int i = 0; i < 10000; i++) { if (queueToSend.Count == 0) { break; } listToSend.Add(queueToSend.Dequeue()); } //Console.WriteLine("Send Conains " + listToSend.Count); using (var request = new NodeListWriter(-1, 0, listToSend)) { using (var response = Global.CloudStorage.BatchNodeCollectionToBenchmarkServer(1, request)) { /**List<long> array = response.Outlinks; * for(int i = 0; i < response.num_elements; i++){ * int outlink = (int) array[i]; * //Console.WriteLine("Cell " + outlink); * if (depth[outlink] > last_level + 1){ * depth[outlink] = last_level + 1; * BFSDummy new_node = new BFSDummy(); * new_node.cellid = outlink; * new_node.depth = last_level + 1; * //Console.WriteLine(response.Outlinks[i] + " depth " + depth[response.Outlinks[i]]); * bfsqueue.Enqueue(new_node); * } * }**/ } } while (remote_outlinks.Count > 0) { int outlink = (int)remote_outlinks.Dequeue(); //Console.WriteLine("Cell " + outlink); if (depth[outlink] > last_level + 1) { depth[outlink] = last_level + 1; BFSDummy new_node = new BFSDummy(); new_node.cellid = outlink; new_node.depth = last_level + 1; //Console.WriteLine(response.Outlinks[i] + " depth " + depth[response.Outlinks[i]]); bfsqueue.Enqueue(new_node); } } } } ////// FINISHED GATHERING STEP } if (dequed) { if (!visited[current_dummy.cellid]) { visited[current_dummy.cellid] = true; //Console.WriteLine("Dequeued " + current_node); int onServer = findServer(current_dummy.cellid); //Console.WriteLine("Outgoing From: " + current_node + " on Server" + onServer); if (onServer == this_server_id) { //Console.WriteLine("[!] LOCAL " + current_dummy.cellid); using (var tempCell = Global.LocalStorage.UseSimpleGraphNode(current_dummy.cellid)) { for (int i = 0; i < tempCell.Outlinks.Count; i++) { if (depth[tempCell.Outlinks[i]] > depth[current_dummy.cellid] + 1) { depth[tempCell.Outlinks[i]] = depth[current_dummy.cellid] + 1; //Console.WriteLine(tempCell.Outlinks[i] + " depth " + depth[tempCell.Outlinks[i]]); BFSDummy new_dummy = new BFSDummy(); new_dummy.cellid = tempCell.Outlinks[i]; new_dummy.depth = depth[current_dummy.cellid] + 1; bfsqueue.Enqueue(new_dummy); } } } } else { remoteSet.Add(current_dummy.cellid); } } last_level = current_dummy.depth; } } ////////////////////////// END ////////////////////////////////777 End_time_Stamp = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; elapsedTime_lastRun = elapsedMs; Console.WriteLine("----------------------------------"); Console.WriteLine("Runtime: {0} (ms)", elapsedTime_lastRun); using (System.IO.StreamWriter file = new System.IO.StreamWriter("benchmark.info")) { file.WriteLine("Algorithm: " + graph_name + " Runtime:" + elapsedTime_lastRun); } if (output_path == null || output_path == "") { output_path = "output.txt"; } Console.WriteLine("Write File to " + output_path); try{ using (System.IO.StreamWriter file = new System.IO.StreamWriter(@output_path, true)) { for (int i = 1; i <= graph_size; i++) { file.WriteLine(mapping1[i - 1] + " " + depth[i]); // hash alternative } } } catch (Exception ex) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(ex.Message); } if (e_log_path == null || e_log_path == "") { e_log_path = "metrics.txt"; } else { e_log_path = e_log_path + "/metrics.txt"; } Console.WriteLine("Write Log File to " + e_log_path); try{ using (System.IO.StreamWriter file = new System.IO.StreamWriter(@e_log_path, true)) { file.WriteLine("Processing starts at " + Start_time_Stamp); file.WriteLine("Processing ends at " + End_time_Stamp); } } catch (Exception ex) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(ex.Message); } Console.WriteLine("##################################"); Console.WriteLine("####### Finished Run #######"); Console.WriteLine("##################################"); }