angel
mercurial changeset:
|
00001 // $Id: angel_comm.cpp,v 1.5 2008/02/28 14:57:32 gottschling Exp $ 00002 /* 00003 ############################################################# 00004 # This file is part of angel released under the BSD license # 00005 # The full COPYRIGHT notice can be found in the top # 00006 # level directory of the angel distribution # 00007 ############################################################# 00008 */ 00009 00010 00011 #include "angel/include/angel_comm.hpp" 00012 00013 #ifdef USE_MPI 00014 00015 #include <algorithm> 00016 00017 namespace GMPI { 00018 00019 using namespace std; 00020 using namespace boost; 00021 using namespace angel; 00022 00023 comm_buffer_t& operator<< (comm_buffer_t& buffer, const c_graph_t& cg) { 00024 int x= cg.x(), y= cg.y(), v= cg.v(), e= num_edges (cg); 00025 buffer.reserve (y + v + 2 * e + 5); 00026 buffer << c_graph_id << x << y << v << e; 00027 for (int c= 0; c < y; c++) buffer << cg.dependents[c]; 00028 00029 // for each vertex: #out_edge;, each out_edge: target+weight 00030 c_graph_t::const_ew_t ew= get(edge_weight, cg); 00031 c_graph_t::vi_t vi, v_end; 00032 for (tie (vi, v_end)= vertices (cg); vi != v_end; vi++) { 00033 buffer << out_degree (*vi, cg); 00034 c_graph_t::oei_t oei, oe_end; 00035 for (tie (oei, oe_end)= out_edges (*vi, cg); oei != oe_end; oei++) 00036 buffer << target (*oei, cg) << ew[*oei]; } 00037 return buffer; 00038 } 00039 00040 const comm_buffer_t& operator>> (const comm_buffer_t& buffer, c_graph_t& cg) { 00041 int x, y, v, e, idtmp; 00042 buffer >> idtmp >> x >> y >> v >> e; 00043 // graph_id_t id= (graph_id_t) idtmp; 00044 // if (id != c_graph_id) throw comm_exception ("Buffer contains no c graph"); 00045 vector<c_graph_t::vertex_t> depvec (y); 00046 for (int c= 0; c < y; c++) buffer >> depvec[c]; 00047 c_graph_t gtmp (v, x, depvec); cg= gtmp; 00048 00049 c_graph_t::ew_t ew= get(edge_weight, cg); 00050 for (int cv= 0; cv < v; cv++) { 00051 int out_degree= buffer.read(); 00052 for (int ce= 0; ce < out_degree; ce++) { 00053 int target= buffer.read(), weight= buffer.read(); 00054 pair<c_graph_t::edge_t, bool> newedge= add_edge (cv, target, cg); 00055 ew[newedge.first]= weight; } } 00056 return buffer; 00057 } 00058 00059 comm_buffer_t& operator<< (comm_buffer_t& buffer, const line_graph_t& lg) { 00060 int x= lg.x(), y= lg.y(), v= lg.v(), e= num_edges (lg); 00061 buffer.reserve (y + 4 * v + e + 5); 00062 buffer << line_graph_id << x << y << v << e; 00063 for (int c= 0; c < y; c++) buffer << lg.dependents[c]; 00064 00065 // for each vertex: degree+c_edge_name+#out_edge; each out_edge: target 00066 line_graph_t::const_ed_t ed= get(vertex_degree, lg); 00067 line_graph_t::const_evn_t evn= get(vertex_name, lg); 00068 line_graph_t::ei_t ei, e_end; 00069 for (tie (ei, e_end)= vertices (lg); ei != e_end; ei++) { 00070 buffer << ed[*ei] << evn[*ei].first << evn[*ei].second << out_degree (*ei, lg); 00071 line_graph_t::ofi_t ofi, of_end; 00072 for (tie (ofi, of_end)= out_edges (*ei, lg); ofi != of_end; ofi++) 00073 buffer << target (*ofi, lg); } 00074 return buffer; 00075 } 00076 00077 const comm_buffer_t& operator>> (const comm_buffer_t& buffer, line_graph_t& lg) { 00078 int x, y, v, e, idtmp; 00079 buffer >> idtmp >> x >> y >> v >> e; 00080 // graph_id_t id= (graph_id_t) idtmp; 00081 // if (id != line_graph_id) throw comm_exception ("Buffer contains no line graph"); 00082 vector<line_graph_t::edge_t> depvec (y); 00083 for (int c= 0; c < y; c++) buffer >> depvec[c]; 00084 line_graph_t gtmp (v, x, depvec); lg= gtmp; 00085 00086 line_graph_t::ed_t ed= get(vertex_degree, lg); 00087 line_graph_t::evn_t evn= get(vertex_name, lg); 00088 for (int cv= 0; cv < v; cv++) { 00089 int out_degree; 00090 buffer >> ed[cv] >> evn[cv].first >> evn[cv].second >> out_degree; 00091 for (int ce= 0; ce < out_degree; ce++) { 00092 int target= buffer.read(); 00093 add_edge (cv, target, lg); } } 00094 return buffer; 00095 } 00096 00097 } // namespace GMPI 00098 00099 #endif // USE_MPI