adjacency_list.hpp 146 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993
  1. // Copyright (C) 2004-2006 The Trustees of Indiana University.
  2. // Copyright (C) 2007 Douglas Gregor
  3. // Use, modification and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // Authors: Douglas Gregor
  7. // Andrew Lumsdaine
  8. #ifndef BOOST_GRAPH_DISTRIBUTED_ADJACENCY_LIST_HPP
  9. #define BOOST_GRAPH_DISTRIBUTED_ADJACENCY_LIST_HPP
  10. #ifndef BOOST_GRAPH_USE_MPI
  11. #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
  12. #endif
  13. #include <boost/core/uncaught_exceptions.hpp>
  14. #include <boost/graph/adjacency_list.hpp>
  15. #include <boost/graph/properties.hpp>
  16. #include <boost/graph/graph_traits.hpp>
  17. #include <boost/graph/iteration_macros.hpp>
  18. #include <boost/graph/distributed/concepts.hpp>
  19. #include <boost/iterator/transform_iterator.hpp>
  20. #include <boost/property_map/property_map.hpp>
  21. #include <boost/property_map/parallel/parallel_property_maps.hpp>
  22. #include <boost/graph/adjacency_iterator.hpp>
  23. #include <boost/property_map/parallel/distributed_property_map.hpp>
  24. #include <boost/property_map/parallel/local_property_map.hpp>
  25. #include <boost/graph/parallel/detail/property_holders.hpp>
  26. #include <boost/mpl/if.hpp>
  27. #include <boost/type_traits/is_same.hpp>
  28. #include <boost/assert.hpp>
  29. #include <list>
  30. #include <iterator>
  31. #include <algorithm>
  32. #include <boost/limits.hpp>
  33. #include <boost/graph/parallel/properties.hpp>
  34. #include <boost/graph/parallel/distribution.hpp>
  35. #include <boost/graph/parallel/algorithm.hpp>
  36. #include <boost/graph/distributed/selector.hpp>
  37. #include <boost/graph/parallel/process_group.hpp>
  38. #include <boost/pending/container_traits.hpp>
  39. // Callbacks
  40. #include <boost/function/function2.hpp>
  41. // Serialization
  42. #include <boost/serialization/base_object.hpp>
  43. #include <boost/mpi/datatype.hpp>
  44. #include <boost/pending/property_serialize.hpp>
  45. #include <boost/graph/distributed/unsafe_serialize.hpp>
  46. // Named vertices
  47. #include <boost/graph/distributed/named_graph.hpp>
  48. #include <boost/graph/distributed/shuffled_distribution.hpp>
  49. namespace boost {
  50. /// The type used to store an identifier that uniquely names a processor.
  51. // NGE: I doubt we'll be running on more than 32768 procs for the time being
  52. typedef /*int*/ short processor_id_type;
  53. // Tell which processor the target of an edge resides on (for
  54. // directed graphs) or which processor the other end point of the
  55. // edge resides on (for undirected graphs).
  56. enum edge_target_processor_id_t { edge_target_processor_id };
  57. BOOST_INSTALL_PROPERTY(edge, target_processor_id);
  58. // For undirected graphs, tells whether the edge is locally owned.
  59. enum edge_locally_owned_t { edge_locally_owned };
  60. BOOST_INSTALL_PROPERTY(edge, locally_owned);
  61. // For bidirectional graphs, stores the incoming edges.
  62. enum vertex_in_edges_t { vertex_in_edges };
  63. BOOST_INSTALL_PROPERTY(vertex, in_edges);
  64. /// Tag class for directed, distributed adjacency list
  65. struct directed_distributed_adj_list_tag
  66. : public virtual distributed_graph_tag,
  67. public virtual distributed_vertex_list_graph_tag,
  68. public virtual distributed_edge_list_graph_tag,
  69. public virtual incidence_graph_tag,
  70. public virtual adjacency_graph_tag {};
  71. /// Tag class for bidirectional, distributed adjacency list
  72. struct bidirectional_distributed_adj_list_tag
  73. : public virtual distributed_graph_tag,
  74. public virtual distributed_vertex_list_graph_tag,
  75. public virtual distributed_edge_list_graph_tag,
  76. public virtual incidence_graph_tag,
  77. public virtual adjacency_graph_tag,
  78. public virtual bidirectional_graph_tag {};
  79. /// Tag class for undirected, distributed adjacency list
  80. struct undirected_distributed_adj_list_tag
  81. : public virtual distributed_graph_tag,
  82. public virtual distributed_vertex_list_graph_tag,
  83. public virtual distributed_edge_list_graph_tag,
  84. public virtual incidence_graph_tag,
  85. public virtual adjacency_graph_tag,
  86. public virtual bidirectional_graph_tag {};
  87. namespace detail {
  88. template<typename Archiver, typename Directed, typename Vertex>
  89. void
  90. serialize(Archiver& ar, edge_base<Directed, Vertex>& e,
  91. const unsigned int /*version*/)
  92. {
  93. ar & unsafe_serialize(e.m_source)
  94. & unsafe_serialize(e.m_target);
  95. }
  96. template<typename Archiver, typename Directed, typename Vertex>
  97. void
  98. serialize(Archiver& ar, edge_desc_impl<Directed, Vertex>& e,
  99. const unsigned int /*version*/)
  100. {
  101. ar & boost::serialization::base_object<edge_base<Directed, Vertex> >(e)
  102. & unsafe_serialize(e.m_eproperty);
  103. }
  104. }
  105. namespace detail { namespace parallel {
  106. /**
  107. * A distributed vertex descriptor. These descriptors contain both
  108. * the ID of the processor that owns the vertex and a local vertex
  109. * descriptor that identifies the particular vertex for that
  110. * processor.
  111. */
  112. template<typename LocalDescriptor>
  113. struct global_descriptor
  114. {
  115. typedef LocalDescriptor local_descriptor_type;
  116. global_descriptor() : owner(), local() { }
  117. global_descriptor(processor_id_type owner, LocalDescriptor local)
  118. : owner(owner), local(local) { }
  119. processor_id_type owner;
  120. LocalDescriptor local;
  121. /**
  122. * A function object that, given a processor ID, generates
  123. * distributed vertex descriptors from local vertex
  124. * descriptors. This function object is used by the
  125. * vertex_iterator of the distributed adjacency list.
  126. */
  127. struct generator
  128. {
  129. typedef global_descriptor<LocalDescriptor> result_type;
  130. typedef LocalDescriptor argument_type;
  131. generator() {}
  132. generator(processor_id_type owner) : owner(owner) {}
  133. result_type operator()(argument_type v) const
  134. { return result_type(owner, v); }
  135. private:
  136. processor_id_type owner;
  137. };
  138. template<typename Archiver>
  139. void serialize(Archiver& ar, const unsigned int /*version*/)
  140. {
  141. ar & owner & unsafe_serialize(local);
  142. }
  143. };
  144. /// Determine the process that owns the given descriptor
  145. template<typename LocalDescriptor>
  146. inline processor_id_type owner(const global_descriptor<LocalDescriptor>& v)
  147. { return v.owner; }
  148. /// Determine the local portion of the given descriptor
  149. template<typename LocalDescriptor>
  150. inline LocalDescriptor local(const global_descriptor<LocalDescriptor>& v)
  151. { return v.local; }
  152. /// Compare distributed vertex descriptors for equality
  153. template<typename LocalDescriptor>
  154. inline bool
  155. operator==(const global_descriptor<LocalDescriptor>& u,
  156. const global_descriptor<LocalDescriptor>& v)
  157. {
  158. return u.owner == v.owner && u.local == v.local;
  159. }
  160. /// Compare distributed vertex descriptors for inequality
  161. template<typename LocalDescriptor>
  162. inline bool
  163. operator!=(const global_descriptor<LocalDescriptor>& u,
  164. const global_descriptor<LocalDescriptor>& v)
  165. { return !(u == v); }
  166. template<typename LocalDescriptor>
  167. inline bool
  168. operator<(const global_descriptor<LocalDescriptor>& u,
  169. const global_descriptor<LocalDescriptor>& v)
  170. {
  171. return (u.owner) < v.owner || (u.owner == v.owner && (u.local) < v.local);
  172. }
  173. template<typename LocalDescriptor>
  174. inline bool
  175. operator<=(const global_descriptor<LocalDescriptor>& u,
  176. const global_descriptor<LocalDescriptor>& v)
  177. {
  178. return u.owner <= v.owner || (u.owner == v.owner && u.local <= v.local);
  179. }
  180. template<typename LocalDescriptor>
  181. inline bool
  182. operator>(const global_descriptor<LocalDescriptor>& u,
  183. const global_descriptor<LocalDescriptor>& v)
  184. {
  185. return v < u;
  186. }
  187. template<typename LocalDescriptor>
  188. inline bool
  189. operator>=(const global_descriptor<LocalDescriptor>& u,
  190. const global_descriptor<LocalDescriptor>& v)
  191. {
  192. return v <= u;
  193. }
  194. // DPG TBD: Add <, <=, >=, > for global descriptors
  195. /**
  196. * A Readable Property Map that extracts a global descriptor pair
  197. * from a global_descriptor.
  198. */
  199. template<typename LocalDescriptor>
  200. struct global_descriptor_property_map
  201. {
  202. typedef std::pair<processor_id_type, LocalDescriptor> value_type;
  203. typedef value_type reference;
  204. typedef global_descriptor<LocalDescriptor> key_type;
  205. typedef readable_property_map_tag category;
  206. };
  207. template<typename LocalDescriptor>
  208. inline std::pair<processor_id_type, LocalDescriptor>
  209. get(global_descriptor_property_map<LocalDescriptor>,
  210. global_descriptor<LocalDescriptor> x)
  211. {
  212. return std::pair<processor_id_type, LocalDescriptor>(x.owner, x.local);
  213. }
  214. /**
  215. * A Readable Property Map that extracts the owner of a global
  216. * descriptor.
  217. */
  218. template<typename LocalDescriptor>
  219. struct owner_property_map
  220. {
  221. typedef processor_id_type value_type;
  222. typedef value_type reference;
  223. typedef global_descriptor<LocalDescriptor> key_type;
  224. typedef readable_property_map_tag category;
  225. };
  226. template<typename LocalDescriptor>
  227. inline processor_id_type
  228. get(owner_property_map<LocalDescriptor>,
  229. global_descriptor<LocalDescriptor> x)
  230. {
  231. return x.owner;
  232. }
  233. /**
  234. * A Readable Property Map that extracts the local descriptor from
  235. * a global descriptor.
  236. */
  237. template<typename LocalDescriptor>
  238. struct local_descriptor_property_map
  239. {
  240. typedef LocalDescriptor value_type;
  241. typedef value_type reference;
  242. typedef global_descriptor<LocalDescriptor> key_type;
  243. typedef readable_property_map_tag category;
  244. };
  245. template<typename LocalDescriptor>
  246. inline LocalDescriptor
  247. get(local_descriptor_property_map<LocalDescriptor>,
  248. global_descriptor<LocalDescriptor> x)
  249. {
  250. return x.local;
  251. }
  252. /**
  253. * Stores an incoming edge for a bidirectional distributed
  254. * adjacency list. The user does not see this type directly,
  255. * because it is just an implementation detail.
  256. */
  257. template<typename Edge>
  258. struct stored_in_edge
  259. {
  260. stored_in_edge(processor_id_type sp, Edge e)
  261. : source_processor(sp), e(e) {}
  262. processor_id_type source_processor;
  263. Edge e;
  264. };
  265. /**
  266. * A distributed edge descriptor. These descriptors contain the
  267. * underlying edge descriptor, the processor IDs for both the
  268. * source and the target of the edge, and a boolean flag that
  269. * indicates which of the processors actually owns the edge.
  270. */
  271. template<typename Edge>
  272. struct edge_descriptor
  273. {
  274. edge_descriptor(processor_id_type sp = processor_id_type(),
  275. processor_id_type tp = processor_id_type(),
  276. bool owns = false, Edge ld = Edge())
  277. : source_processor(sp), target_processor(tp),
  278. source_owns_edge(owns), local(ld) {}
  279. processor_id_type owner() const
  280. {
  281. return source_owns_edge? source_processor : target_processor;
  282. }
  283. /// The processor that the source vertex resides on
  284. processor_id_type source_processor;
  285. /// The processor that the target vertex resides on
  286. processor_id_type target_processor;
  287. /// True when the source processor owns the edge, false when the
  288. /// target processor owns the edge.
  289. bool source_owns_edge;
  290. /// The local edge descriptor.
  291. Edge local;
  292. /**
  293. * Function object that generates edge descriptors for the
  294. * out_edge_iterator of the given distributed adjacency list
  295. * from the edge descriptors of the underlying adjacency list.
  296. */
  297. template<typename Graph>
  298. class out_generator
  299. {
  300. typedef typename Graph::directed_selector directed_selector;
  301. public:
  302. typedef edge_descriptor<Edge> result_type;
  303. typedef Edge argument_type;
  304. out_generator() : g(0) {}
  305. explicit out_generator(const Graph& g) : g(&g) {}
  306. result_type operator()(argument_type e) const
  307. { return map(e, directed_selector()); }
  308. private:
  309. result_type map(argument_type e, directedS) const
  310. {
  311. return result_type(g->processor(),
  312. get(edge_target_processor_id, g->base(), e),
  313. true, e);
  314. }
  315. result_type map(argument_type e, bidirectionalS) const
  316. {
  317. return result_type(g->processor(),
  318. get(edge_target_processor_id, g->base(), e),
  319. true, e);
  320. }
  321. result_type map(argument_type e, undirectedS) const
  322. {
  323. return result_type(g->processor(),
  324. get(edge_target_processor_id, g->base(), e),
  325. get(edge_locally_owned, g->base(), e),
  326. e);
  327. }
  328. const Graph* g;
  329. };
  330. /**
  331. * Function object that generates edge descriptors for the
  332. * in_edge_iterator of the given distributed adjacency list
  333. * from the edge descriptors of the underlying adjacency list.
  334. */
  335. template<typename Graph>
  336. class in_generator
  337. {
  338. typedef typename Graph::directed_selector DirectedS;
  339. public:
  340. typedef typename boost::mpl::if_<is_same<DirectedS, bidirectionalS>,
  341. stored_in_edge<Edge>,
  342. Edge>::type argument_type;
  343. typedef edge_descriptor<Edge> result_type;
  344. in_generator() : g(0) {}
  345. explicit in_generator(const Graph& g) : g(&g) {}
  346. result_type operator()(argument_type e) const
  347. { return map(e, DirectedS()); }
  348. private:
  349. /**
  350. * For a bidirectional graph, we just generate the appropriate
  351. * edge. No tricks.
  352. */
  353. result_type map(argument_type e, bidirectionalS) const
  354. {
  355. return result_type(e.source_processor,
  356. g->processor(),
  357. true,
  358. e.e);
  359. }
  360. /**
  361. * For an undirected graph, we generate descriptors for the
  362. * incoming edges by swapping the source/target of the
  363. * underlying edge descriptor (a hack). The target processor
  364. * ID on the edge is actually the source processor for this
  365. * edge, and our processor is the target processor. If the
  366. * edge is locally owned, then it is owned by the target (us);
  367. * otherwise it is owned by the source.
  368. */
  369. result_type map(argument_type e, undirectedS) const
  370. {
  371. typename Graph::local_edge_descriptor local_edge(e);
  372. // TBD: This is a very, VERY lame hack that takes advantage
  373. // of our knowledge of the internals of the BGL
  374. // adjacency_list. There should be a cleaner way to handle
  375. // this...
  376. using std::swap;
  377. swap(local_edge.m_source, local_edge.m_target);
  378. return result_type(get(edge_target_processor_id, g->base(), e),
  379. g->processor(),
  380. !get(edge_locally_owned, g->base(), e),
  381. local_edge);
  382. }
  383. const Graph* g;
  384. };
  385. private:
  386. friend class boost::serialization::access;
  387. template<typename Archiver>
  388. void serialize(Archiver& ar, const unsigned int /*version*/)
  389. {
  390. ar
  391. & source_processor
  392. & target_processor
  393. & source_owns_edge
  394. & local;
  395. }
  396. };
  397. /// Determine the process that owns this edge
  398. template<typename Edge>
  399. inline processor_id_type
  400. owner(const edge_descriptor<Edge>& e)
  401. { return e.source_owns_edge? e.source_processor : e.target_processor; }
  402. /// Determine the local descriptor for this edge.
  403. template<typename Edge>
  404. inline Edge
  405. local(const edge_descriptor<Edge>& e)
  406. { return e.local; }
  407. /**
  408. * A Readable Property Map that extracts the owner and local
  409. * descriptor of an edge descriptor.
  410. */
  411. template<typename Edge>
  412. struct edge_global_property_map
  413. {
  414. typedef std::pair<processor_id_type, Edge> value_type;
  415. typedef value_type reference;
  416. typedef edge_descriptor<Edge> key_type;
  417. typedef readable_property_map_tag category;
  418. };
  419. template<typename Edge>
  420. inline std::pair<processor_id_type, Edge>
  421. get(edge_global_property_map<Edge>, const edge_descriptor<Edge>& e)
  422. {
  423. typedef std::pair<processor_id_type, Edge> result_type;
  424. return result_type(e.source_owns_edge? e.source_processor
  425. /* target owns edge*/: e.target_processor,
  426. e.local);
  427. }
  428. /**
  429. * A Readable Property Map that extracts the owner of an edge
  430. * descriptor.
  431. */
  432. template<typename Edge>
  433. struct edge_owner_property_map
  434. {
  435. typedef processor_id_type value_type;
  436. typedef value_type reference;
  437. typedef edge_descriptor<Edge> key_type;
  438. typedef readable_property_map_tag category;
  439. };
  440. template<typename Edge>
  441. inline processor_id_type
  442. get(edge_owner_property_map<Edge>, const edge_descriptor<Edge>& e)
  443. {
  444. return e.source_owns_edge? e.source_processor : e.target_processor;
  445. }
  446. /**
  447. * A Readable Property Map that extracts the local descriptor from
  448. * an edge descriptor.
  449. */
  450. template<typename Edge>
  451. struct edge_local_property_map
  452. {
  453. typedef Edge value_type;
  454. typedef value_type reference;
  455. typedef edge_descriptor<Edge> key_type;
  456. typedef readable_property_map_tag category;
  457. };
  458. template<typename Edge>
  459. inline Edge
  460. get(edge_local_property_map<Edge>,
  461. const edge_descriptor<Edge>& e)
  462. {
  463. return e.local;
  464. }
  465. /** Compare distributed edge descriptors for equality.
  466. *
  467. * \todo need edge_descriptor to know if it is undirected so we
  468. * can compare both ways.
  469. */
  470. template<typename Edge>
  471. inline bool
  472. operator==(const edge_descriptor<Edge>& e1,
  473. const edge_descriptor<Edge>& e2)
  474. {
  475. return (e1.source_processor == e2.source_processor
  476. && e1.target_processor == e2.target_processor
  477. && e1.local == e2.local);
  478. }
  479. /// Compare distributed edge descriptors for inequality.
  480. template<typename Edge>
  481. inline bool
  482. operator!=(const edge_descriptor<Edge>& e1,
  483. const edge_descriptor<Edge>& e2)
  484. { return !(e1 == e2); }
  485. /**
  486. * Configuration for the distributed adjacency list. We use this
  487. * parameter to store all of the configuration details for the
  488. * implementation of the distributed adjacency list, which allows us to
  489. * get at the distribution type in the maybe_named_graph.
  490. */
  491. template<typename OutEdgeListS, typename ProcessGroup,
  492. typename InVertexListS, typename InDistribution,
  493. typename DirectedS, typename VertexProperty,
  494. typename EdgeProperty, typename GraphProperty,
  495. typename EdgeListS>
  496. struct adjacency_list_config
  497. {
  498. typedef typename mpl::if_<is_same<InVertexListS, defaultS>,
  499. vecS, InVertexListS>::type
  500. VertexListS;
  501. /// Introduce the target processor ID property for each edge
  502. typedef property<edge_target_processor_id_t, processor_id_type,
  503. EdgeProperty> edge_property_with_id;
  504. /// For undirected graphs, introduce the locally-owned property for edges
  505. typedef typename boost::mpl::if_<is_same<DirectedS, undirectedS>,
  506. property<edge_locally_owned_t, bool,
  507. edge_property_with_id>,
  508. edge_property_with_id>::type
  509. base_edge_property_type;
  510. /// The edge descriptor type for the local subgraph
  511. typedef typename adjacency_list_traits<OutEdgeListS,
  512. VertexListS,
  513. directedS>::edge_descriptor
  514. local_edge_descriptor;
  515. /// For bidirectional graphs, the type of an incoming stored edge
  516. typedef stored_in_edge<local_edge_descriptor> bidir_stored_edge;
  517. /// The container type that will store incoming edges for a
  518. /// bidirectional graph.
  519. typedef typename container_gen<EdgeListS, bidir_stored_edge>::type
  520. in_edge_list_type;
  521. // Bidirectional graphs have an extra vertex property to store
  522. // the incoming edges.
  523. typedef typename boost::mpl::if_<is_same<DirectedS, bidirectionalS>,
  524. property<vertex_in_edges_t, in_edge_list_type,
  525. VertexProperty>,
  526. VertexProperty>::type
  527. base_vertex_property_type;
  528. // The type of the distributed adjacency list
  529. typedef adjacency_list<OutEdgeListS,
  530. distributedS<ProcessGroup,
  531. VertexListS,
  532. InDistribution>,
  533. DirectedS, VertexProperty, EdgeProperty,
  534. GraphProperty, EdgeListS>
  535. graph_type;
  536. // The type of the underlying adjacency list implementation
  537. typedef adjacency_list<OutEdgeListS, VertexListS, directedS,
  538. base_vertex_property_type,
  539. base_edge_property_type,
  540. GraphProperty,
  541. EdgeListS>
  542. inherited;
  543. typedef InDistribution in_distribution_type;
  544. typedef typename inherited::vertices_size_type vertices_size_type;
  545. typedef typename ::boost::graph::distributed::select_distribution<
  546. in_distribution_type, VertexProperty, vertices_size_type,
  547. ProcessGroup>::type
  548. base_distribution_type;
  549. typedef ::boost::graph::distributed::shuffled_distribution<
  550. base_distribution_type> distribution_type;
  551. typedef VertexProperty vertex_property_type;
  552. typedef EdgeProperty edge_property_type;
  553. typedef ProcessGroup process_group_type;
  554. typedef VertexListS vertex_list_selector;
  555. typedef OutEdgeListS out_edge_list_selector;
  556. typedef DirectedS directed_selector;
  557. typedef GraphProperty graph_property_type;
  558. typedef EdgeListS edge_list_selector;
  559. };
  560. // Maybe initialize the indices of each vertex
  561. template<typename IteratorPair, typename VertexIndexMap>
  562. void
  563. maybe_initialize_vertex_indices(IteratorPair p, VertexIndexMap to_index,
  564. read_write_property_map_tag)
  565. {
  566. typedef typename property_traits<VertexIndexMap>::value_type index_t;
  567. index_t next_index = 0;
  568. while (p.first != p.second)
  569. put(to_index, *p.first++, next_index++);
  570. }
  571. template<typename IteratorPair, typename VertexIndexMap>
  572. inline void
  573. maybe_initialize_vertex_indices(IteratorPair p, VertexIndexMap to_index,
  574. readable_property_map_tag)
  575. {
  576. // Do nothing
  577. }
  578. template<typename IteratorPair, typename VertexIndexMap>
  579. inline void
  580. maybe_initialize_vertex_indices(IteratorPair p, VertexIndexMap to_index)
  581. {
  582. typedef typename property_traits<VertexIndexMap>::category category;
  583. maybe_initialize_vertex_indices(p, to_index, category());
  584. }
  585. template<typename IteratorPair>
  586. inline void
  587. maybe_initialize_vertex_indices(IteratorPair p,
  588. ::boost::detail::error_property_not_found)
  589. { }
  590. /***********************************************************************
  591. * Message Payloads *
  592. ***********************************************************************/
  593. /**
  594. * Data stored with a msg_add_edge message, which requests the
  595. * remote addition of an edge.
  596. */
  597. template<typename Vertex, typename LocalVertex>
  598. struct msg_add_edge_data
  599. {
  600. msg_add_edge_data() { }
  601. msg_add_edge_data(Vertex source, Vertex target)
  602. : source(source.local), target(target) { }
  603. /// The source of the edge; the processor will be the
  604. /// receiving processor.
  605. LocalVertex source;
  606. /// The target of the edge.
  607. Vertex target;
  608. template<typename Archiver>
  609. void serialize(Archiver& ar, const unsigned int /*version*/)
  610. {
  611. ar & unsafe_serialize(source) & target;
  612. }
  613. };
  614. /**
  615. * Like @c msg_add_edge_data, but also includes a user-specified
  616. * property value to be attached to the edge.
  617. */
  618. template<typename Vertex, typename LocalVertex, typename EdgeProperty>
  619. struct msg_add_edge_with_property_data
  620. : msg_add_edge_data<Vertex, LocalVertex>,
  621. maybe_store_property<EdgeProperty>
  622. {
  623. private:
  624. typedef msg_add_edge_data<Vertex, LocalVertex> inherited_data;
  625. typedef maybe_store_property<EdgeProperty> inherited_property;
  626. public:
  627. msg_add_edge_with_property_data() { }
  628. msg_add_edge_with_property_data(Vertex source,
  629. Vertex target,
  630. const EdgeProperty& property)
  631. : inherited_data(source, target),
  632. inherited_property(property) { }
  633. template<typename Archiver>
  634. void serialize(Archiver& ar, const unsigned int /*version*/)
  635. {
  636. ar & boost::serialization::base_object<inherited_data>(*this)
  637. & boost::serialization::base_object<inherited_property>(*this);
  638. }
  639. };
  640. //------------------------------------------------------------------------
  641. // Distributed adjacency list property map details
  642. /**
  643. * Metafunction that extracts the given property from the given
  644. * distributed adjacency list type. This could be implemented much
  645. * more cleanly, but even newer versions of GCC (e.g., 3.2.3)
  646. * cannot properly handle partial specializations involving
  647. * enumerator types.
  648. */
  649. template<typename Property>
  650. struct get_adj_list_pmap
  651. {
  652. template<typename Graph>
  653. struct apply
  654. {
  655. typedef Graph graph_type;
  656. typedef typename graph_type::process_group_type process_group_type;
  657. typedef typename graph_type::inherited base_graph_type;
  658. typedef typename property_map<base_graph_type, Property>::type
  659. local_pmap;
  660. typedef typename property_map<base_graph_type, Property>::const_type
  661. local_const_pmap;
  662. typedef graph_traits<graph_type> traits;
  663. typedef typename graph_type::local_vertex_descriptor local_vertex;
  664. typedef typename property_traits<local_pmap>::key_type local_key_type;
  665. typedef typename property_traits<local_pmap>::value_type value_type;
  666. typedef typename property_map<Graph, vertex_global_t>::const_type
  667. vertex_global_map;
  668. typedef typename property_map<Graph, edge_global_t>::const_type
  669. edge_global_map;
  670. typedef typename mpl::if_c<(is_same<local_key_type,
  671. local_vertex>::value),
  672. vertex_global_map, edge_global_map>::type
  673. global_map;
  674. public:
  675. typedef ::boost::parallel::distributed_property_map<
  676. process_group_type, global_map, local_pmap> type;
  677. typedef ::boost::parallel::distributed_property_map<
  678. process_group_type, global_map, local_const_pmap> const_type;
  679. };
  680. };
  681. /**
  682. * The local vertex index property map is actually a mapping from
  683. * the local vertex descriptors to vertex indices.
  684. */
  685. template<>
  686. struct get_adj_list_pmap<vertex_local_index_t>
  687. {
  688. template<typename Graph>
  689. struct apply
  690. : ::boost::property_map<typename Graph::inherited, vertex_index_t>
  691. { };
  692. };
  693. /**
  694. * The vertex index property map maps from global descriptors
  695. * (e.g., the vertex descriptor of a distributed adjacency list)
  696. * to the underlying local index. It is not valid to use this
  697. * property map with nonlocal descriptors.
  698. */
  699. template<>
  700. struct get_adj_list_pmap<vertex_index_t>
  701. {
  702. template<typename Graph>
  703. struct apply
  704. {
  705. private:
  706. typedef typename property_map<Graph, vertex_global_t>::const_type
  707. global_map;
  708. typedef property_map<typename Graph::inherited, vertex_index_t> local;
  709. public:
  710. typedef local_property_map<typename Graph::process_group_type,
  711. global_map,
  712. typename local::type> type;
  713. typedef local_property_map<typename Graph::process_group_type,
  714. global_map,
  715. typename local::const_type> const_type;
  716. };
  717. };
  718. /**
  719. * The vertex owner property map maps from vertex descriptors to
  720. * the processor that owns the vertex.
  721. */
  722. template<>
  723. struct get_adj_list_pmap<vertex_global_t>
  724. {
  725. template<typename Graph>
  726. struct apply
  727. {
  728. private:
  729. typedef typename Graph::local_vertex_descriptor
  730. local_vertex_descriptor;
  731. public:
  732. typedef global_descriptor_property_map<local_vertex_descriptor> type;
  733. typedef type const_type;
  734. };
  735. };
  736. /**
  737. * The vertex owner property map maps from vertex descriptors to
  738. * the processor that owns the vertex.
  739. */
  740. template<>
  741. struct get_adj_list_pmap<vertex_owner_t>
  742. {
  743. template<typename Graph>
  744. struct apply
  745. {
  746. private:
  747. typedef typename Graph::local_vertex_descriptor
  748. local_vertex_descriptor;
  749. public:
  750. typedef owner_property_map<local_vertex_descriptor> type;
  751. typedef type const_type;
  752. };
  753. };
  754. /**
  755. * The vertex local property map maps from vertex descriptors to
  756. * the local descriptor for that vertex.
  757. */
  758. template<>
  759. struct get_adj_list_pmap<vertex_local_t>
  760. {
  761. template<typename Graph>
  762. struct apply
  763. {
  764. private:
  765. typedef typename Graph::local_vertex_descriptor
  766. local_vertex_descriptor;
  767. public:
  768. typedef local_descriptor_property_map<local_vertex_descriptor> type;
  769. typedef type const_type;
  770. };
  771. };
  772. /**
  773. * The edge global property map maps from edge descriptors to
  774. * a pair of the owning processor and local descriptor.
  775. */
  776. template<>
  777. struct get_adj_list_pmap<edge_global_t>
  778. {
  779. template<typename Graph>
  780. struct apply
  781. {
  782. private:
  783. typedef typename Graph::local_edge_descriptor
  784. local_edge_descriptor;
  785. public:
  786. typedef edge_global_property_map<local_edge_descriptor> type;
  787. typedef type const_type;
  788. };
  789. };
  790. /**
  791. * The edge owner property map maps from edge descriptors to
  792. * the processor that owns the edge.
  793. */
  794. template<>
  795. struct get_adj_list_pmap<edge_owner_t>
  796. {
  797. template<typename Graph>
  798. struct apply
  799. {
  800. private:
  801. typedef typename Graph::local_edge_descriptor
  802. local_edge_descriptor;
  803. public:
  804. typedef edge_owner_property_map<local_edge_descriptor> type;
  805. typedef type const_type;
  806. };
  807. };
  808. /**
  809. * The edge local property map maps from edge descriptors to
  810. * the local descriptor for that edge.
  811. */
  812. template<>
  813. struct get_adj_list_pmap<edge_local_t>
  814. {
  815. template<typename Graph>
  816. struct apply
  817. {
  818. private:
  819. typedef typename Graph::local_edge_descriptor
  820. local_edge_descriptor;
  821. public:
  822. typedef edge_local_property_map<local_edge_descriptor> type;
  823. typedef type const_type;
  824. };
  825. };
  826. //------------------------------------------------------------------------
  827. // Directed graphs do not have in edges, so this is a no-op
  828. template<typename Graph>
  829. inline void
  830. remove_in_edge(typename Graph::edge_descriptor, Graph&, directedS)
  831. { }
  832. // Bidirectional graphs have in edges stored in the
  833. // vertex_in_edges property.
  834. template<typename Graph>
  835. inline void
  836. remove_in_edge(typename Graph::edge_descriptor e, Graph& g, bidirectionalS)
  837. {
  838. typedef typename Graph::in_edge_list_type in_edge_list_type;
  839. in_edge_list_type& in_edges =
  840. get(vertex_in_edges, g.base())[target(e, g).local];
  841. typename in_edge_list_type::iterator i = in_edges.begin();
  842. while (i != in_edges.end()
  843. && !(i->source_processor == source(e, g).owner)
  844. && i->e == e.local)
  845. ++i;
  846. BOOST_ASSERT(i != in_edges.end());
  847. in_edges.erase(i);
  848. }
  849. // Undirected graphs have in edges stored as normal edges.
  850. template<typename Graph>
  851. inline void
  852. remove_in_edge(typename Graph::edge_descriptor e, Graph& g, undirectedS)
  853. {
  854. typedef typename Graph::inherited base_type;
  855. typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
  856. // TBD: can we make this more efficient?
  857. // Removing edge (v, u). v is local
  858. base_type& bg = g.base();
  859. vertex_descriptor u = source(e, g);
  860. vertex_descriptor v = target(e, g);
  861. if (v.owner != process_id(g.process_group())) {
  862. using std::swap;
  863. swap(u, v);
  864. }
  865. typename graph_traits<base_type>::out_edge_iterator ei, ei_end;
  866. for (boost::tie(ei, ei_end) = out_edges(v.local, bg); ei != ei_end; ++ei)
  867. {
  868. if (target(*ei, g.base()) == u.local
  869. // TBD: deal with parallel edges properly && *ei == e
  870. && get(edge_target_processor_id, bg, *ei) == u.owner) {
  871. remove_edge(ei, bg);
  872. return;
  873. }
  874. }
  875. if (v.owner == process_id(g.process_group())) {
  876. }
  877. }
  878. //------------------------------------------------------------------------
  879. // Lazy addition of edges
  880. // Work around the fact that an adjacency_list with vecS vertex
  881. // storage automatically adds edges when the descriptor is
  882. // out-of-range.
  883. template <class Graph, class Config, class Base>
  884. inline std::pair<typename Config::edge_descriptor, bool>
  885. add_local_edge(typename Config::vertex_descriptor u,
  886. typename Config::vertex_descriptor v,
  887. const typename Config::edge_property_type& p,
  888. vec_adj_list_impl<Graph, Config, Base>& g_)
  889. {
  890. adj_list_helper<Config, Base>& g = g_;
  891. return add_edge(u, v, p, g);
  892. }
  893. template <class Graph, class Config, class Base>
  894. inline std::pair<typename Config::edge_descriptor, bool>
  895. add_local_edge(typename Config::vertex_descriptor u,
  896. typename Config::vertex_descriptor v,
  897. const typename Config::edge_property_type& p,
  898. boost::adj_list_impl<Graph, Config, Base>& g)
  899. {
  900. return add_edge(u, v, p, g);
  901. }
  902. template <class EdgeProperty,class EdgeDescriptor>
  903. struct msg_nonlocal_edge_data
  904. : public detail::parallel::maybe_store_property<EdgeProperty>
  905. {
  906. typedef EdgeProperty edge_property_type;
  907. typedef EdgeDescriptor local_edge_descriptor;
  908. typedef detail::parallel::maybe_store_property<edge_property_type>
  909. inherited;
  910. msg_nonlocal_edge_data() {}
  911. msg_nonlocal_edge_data(local_edge_descriptor e,
  912. const edge_property_type& p)
  913. : inherited(p), e(e) { }
  914. local_edge_descriptor e;
  915. template<typename Archiver>
  916. void serialize(Archiver& ar, const unsigned int /*version*/)
  917. {
  918. ar & boost::serialization::base_object<inherited>(*this) & e;
  919. }
  920. };
  921. template <class EdgeDescriptor>
  922. struct msg_remove_edge_data
  923. {
  924. typedef EdgeDescriptor edge_descriptor;
  925. msg_remove_edge_data() {}
  926. explicit msg_remove_edge_data(edge_descriptor e) : e(e) {}
  927. edge_descriptor e;
  928. template<typename Archiver>
  929. void serialize(Archiver& ar, const unsigned int /*version*/)
  930. {
  931. ar & e;
  932. }
  933. };
  934. } } // end namespace detail::parallel
  935. /**
  936. * Adjacency list traits for a distributed adjacency list. Contains
  937. * the vertex and edge descriptors, the directed-ness, and the
  938. * parallel edges typedefs.
  939. */
  940. template<typename OutEdgeListS, typename ProcessGroup,
  941. typename InVertexListS, typename InDistribution, typename DirectedS>
  942. struct adjacency_list_traits<OutEdgeListS,
  943. distributedS<ProcessGroup,
  944. InVertexListS,
  945. InDistribution>,
  946. DirectedS>
  947. {
  948. private:
  949. typedef typename mpl::if_<is_same<InVertexListS, defaultS>,
  950. vecS,
  951. InVertexListS>::type VertexListS;
  952. typedef adjacency_list_traits<OutEdgeListS, VertexListS, directedS>
  953. base_type;
  954. public:
  955. typedef typename base_type::vertex_descriptor local_vertex_descriptor;
  956. typedef typename base_type::edge_descriptor local_edge_descriptor;
  957. typedef typename boost::mpl::if_<typename DirectedS::is_bidir_t,
  958. bidirectional_tag,
  959. typename boost::mpl::if_<typename DirectedS::is_directed_t,
  960. directed_tag, undirected_tag
  961. >::type
  962. >::type directed_category;
  963. typedef typename parallel_edge_traits<OutEdgeListS>::type
  964. edge_parallel_category;
  965. typedef detail::parallel::global_descriptor<local_vertex_descriptor>
  966. vertex_descriptor;
  967. typedef detail::parallel::edge_descriptor<local_edge_descriptor>
  968. edge_descriptor;
  969. };
  970. #define PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS \
  971. typename OutEdgeListS, typename ProcessGroup, typename InVertexListS, \
  972. typename InDistribution, typename DirectedS, typename VertexProperty, \
  973. typename EdgeProperty, typename GraphProperty, typename EdgeListS
  974. #define PBGL_DISTRIB_ADJLIST_TYPE \
  975. adjacency_list<OutEdgeListS, \
  976. distributedS<ProcessGroup, InVertexListS, InDistribution>, \
  977. DirectedS, VertexProperty, EdgeProperty, GraphProperty, \
  978. EdgeListS>
  979. #define PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG \
  980. typename OutEdgeListS, typename ProcessGroup, typename InVertexListS, \
  981. typename InDistribution, typename VertexProperty, \
  982. typename EdgeProperty, typename GraphProperty, typename EdgeListS
  983. #define PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directed) \
  984. adjacency_list<OutEdgeListS, \
  985. distributedS<ProcessGroup, InVertexListS, InDistribution>, \
  986. directed, VertexProperty, EdgeProperty, GraphProperty, \
  987. EdgeListS>
  988. /** A distributed adjacency list.
  989. *
  990. * This class template partial specialization defines a distributed
  991. * (or "partitioned") adjacency list graph. The distributed
  992. * adjacency list is similar to the standard Boost Graph Library
  993. * adjacency list, which stores a list of vertices and for each
  994. * verted the list of edges outgoing from the vertex (and, in some
  995. * cases, also the edges incoming to the vertex). The distributed
  996. * adjacency list differs in that it partitions the graph into
  997. * several subgraphs that are then divided among different
  998. * processors (or nodes within a cluster). The distributed adjacency
  999. * list attempts to maintain a high degree of compatibility with the
  1000. * standard, non-distributed adjacency list.
  1001. *
  1002. * The graph is partitioned by vertex, with each processor storing
  1003. * all of the required information for a particular subset of the
  1004. * vertices, including vertex properties, outgoing edges, and (for
  1005. * bidirectional graphs) incoming edges. This information is
  1006. * accessible only on the processor that owns the vertex: for
  1007. * instance, if processor 0 owns vertex @c v, no other processor can
  1008. * directly access the properties of @c v or enumerate its outgoing
  1009. * edges.
  1010. *
  1011. * Edges in a graph may be entirely local (connecting two local
  1012. * vertices), but more often it is the case that edges are
  1013. * non-local, meaning that the two vertices they connect reside in
  1014. * different processes. Edge properties are stored with the
  1015. * originating vertex for directed and bidirectional graphs, and are
  1016. * therefore only accessible from the processor that owns the
  1017. * originating vertex. Other processors may query the source and
  1018. * target of the edge, but cannot access its properties. This is
  1019. * particularly interesting when accessing the incoming edges of a
  1020. * bidirectional graph, which are not guaranteed to be stored on the
  1021. * processor that is able to perform the iteration. For undirected
  1022. * graphs the situation is more complicated, since no vertex clearly
  1023. * owns the edges: the list of edges incident to a vertex may
  1024. * contain a mix of local and non-local edges.
  1025. *
  1026. * The distributed adjacency list is able to model several of the
  1027. * existing Graph concepts. It models the Graph concept because it
  1028. * exposes vertex and edge descriptors in the normal way; these
  1029. * descriptors model the GlobalDescriptor concept (because they have
  1030. * an owner and a local descriptor), and as such the distributed
  1031. * adjacency list models the DistributedGraph concept. The adjacency
  1032. * list also models the IncidenceGraph and AdjacencyGraph concepts,
  1033. * although this is only true so long as the domain of the valid
  1034. * expression arguments are restricted to vertices and edges stored
  1035. * locally. Likewise, bidirectional and undirected distributed
  1036. * adjacency lists model the BidirectionalGraph concept (vertex and
  1037. * edge domains must be respectived) and the distributed adjacency
  1038. * list models the MutableGraph concept (vertices and edges can only
  1039. * be added or removed locally). T he distributed adjacency list
  1040. * does not, however, model the VertexListGraph or EdgeListGraph
  1041. * concepts, because we can not efficiently enumerate all vertices
  1042. * or edges in the graph. Instead, the local subsets of vertices and
  1043. * edges can be enumerated (with the same syntax): the distributed
  1044. * adjacency list therefore models the DistributedVertexListGraph
  1045. * and DistributedEdgeListGraph concepts, because concurrent
  1046. * iteration over all of the vertices or edges stored on each
  1047. * processor will visit each vertex or edge.
  1048. *
  1049. * The distributed adjacency list is distinguished from the
  1050. * non-distributed version by the vertex list descriptor, which will
  1051. * be @c distributedS<ProcessGroup,VertexListS>. Here,
  1052. * the VertexListS type plays the same role as the VertexListS type
  1053. * in the non-distributed adjacency list: it allows one to select
  1054. * the data structure that will be used to store the local
  1055. * vertices. The ProcessGroup type, on the other hand, is unique to
  1056. * distributed data structures: it is the type that abstracts a
  1057. * group of cooperating processes, and it used for process
  1058. * identification, communication, and synchronization, among other
  1059. * things. Different process group types represent different
  1060. * communication mediums (e.g., MPI, PVM, TCP) or different models
  1061. * of communication (LogP, CGM, BSP, synchronous, etc.). This
  1062. * distributed adjacency list assumes a model based on non-blocking
  1063. * sends.
  1064. *
  1065. * Distribution of vertices across different processors is
  1066. * accomplished in two different ways. When initially constructing
  1067. * the graph, the user may provide a distribution object (that
  1068. * models the Distribution concept), which will determine the
  1069. * distribution of vertices to each process. Additionally, the @c
  1070. * add_vertex and @c add_edge operations add vertices or edges
  1071. * stored on the local processor. For @c add_edge, this is
  1072. * accomplished by requiring that the source vertex of the new edge
  1073. * be local to the process executing @c add_edge.
  1074. *
  1075. * Internal properties of a distributed adjacency list are
  1076. * accessible in the same manner as internal properties for a
  1077. * non-distributed adjacency list for local vertices or
  1078. * edges. Access to properties for remote vertices or edges occurs
  1079. * with the same syntax, but involve communication with the owner of
  1080. * the information: for more information, refer to class template
  1081. * @ref distributed_property_map, which manages distributed
  1082. * property maps. Note that the distributed property maps created
  1083. * for internal properties determine their reduction operation via
  1084. * the metafunction @ref property_reduce, which for the vast
  1085. * majority of uses is correct behavior.
  1086. *
  1087. * Communication among the processes coordinating on a particular
  1088. * distributed graph relies on non-blocking message passing along
  1089. * with synchronization. Local portions of the distributed graph may
  1090. * be modified concurrently, including the introduction of non-local
  1091. * edges, but prior to accessing the graph it is recommended that
  1092. * the @c synchronize free function be invoked on the graph to clear
  1093. * up any pending interprocess communication and modifications. All
  1094. * processes will then be released from the synchronization barrier
  1095. * concurrently.
  1096. *
  1097. * \todo Determine precisely what we should do with nonlocal edges
  1098. * in undirected graphs. Our parallelization of certain algorithms
  1099. * relies on the ability to access edge property maps immediately
  1100. * (e.g., edge_weight_t), so it may be necessary to duplicate the
  1101. * edge properties in both processes (but then we need some form of
  1102. * coherence protocol).
  1103. *
  1104. * \todo What does the user do if @c property_reduce doesn't do the
  1105. * right thing?
  1106. */
  1107. template<typename OutEdgeListS, typename ProcessGroup,
  1108. typename InVertexListS, typename InDistribution, typename DirectedS,
  1109. typename VertexProperty, typename EdgeProperty,
  1110. typename GraphProperty, typename EdgeListS>
  1111. class adjacency_list<OutEdgeListS,
  1112. distributedS<ProcessGroup,
  1113. InVertexListS,
  1114. InDistribution>,
  1115. DirectedS, VertexProperty,
  1116. EdgeProperty, GraphProperty, EdgeListS>
  1117. : // Support for named vertices
  1118. public graph::distributed::maybe_named_graph<
  1119. adjacency_list<OutEdgeListS,
  1120. distributedS<ProcessGroup,
  1121. InVertexListS,
  1122. InDistribution>,
  1123. DirectedS, VertexProperty,
  1124. EdgeProperty, GraphProperty, EdgeListS>,
  1125. typename adjacency_list_traits<OutEdgeListS,
  1126. distributedS<ProcessGroup,
  1127. InVertexListS,
  1128. InDistribution>,
  1129. DirectedS>::vertex_descriptor,
  1130. typename adjacency_list_traits<OutEdgeListS,
  1131. distributedS<ProcessGroup,
  1132. InVertexListS,
  1133. InDistribution>,
  1134. DirectedS>::edge_descriptor,
  1135. detail::parallel::adjacency_list_config<OutEdgeListS, ProcessGroup,
  1136. InVertexListS, InDistribution,
  1137. DirectedS, VertexProperty,
  1138. EdgeProperty, GraphProperty,
  1139. EdgeListS> >
  1140. {
  1141. typedef detail::parallel::adjacency_list_config<OutEdgeListS, ProcessGroup,
  1142. InVertexListS, InDistribution,
  1143. DirectedS, VertexProperty,
  1144. EdgeProperty, GraphProperty,
  1145. EdgeListS>
  1146. config_type;
  1147. typedef adjacency_list_traits<OutEdgeListS,
  1148. distributedS<ProcessGroup,
  1149. InVertexListS,
  1150. InDistribution>,
  1151. DirectedS>
  1152. traits_type;
  1153. typedef typename DirectedS::is_directed_t is_directed;
  1154. typedef EdgeListS edge_list_selector;
  1155. public:
  1156. /// The container type that will store incoming edges for a
  1157. /// bidirectional graph.
  1158. typedef typename config_type::in_edge_list_type in_edge_list_type;
  1159. // typedef typename inherited::edge_descriptor edge_descriptor;
  1160. /// The type of the underlying adjacency list implementation
  1161. typedef typename config_type::inherited inherited;
  1162. /// The type of properties stored in the local subgraph
  1163. /// Bidirectional graphs have an extra vertex property to store
  1164. /// the incoming edges.
  1165. typedef typename inherited::vertex_property_type
  1166. base_vertex_property_type;
  1167. /// The type of the distributed adjacency list (this type)
  1168. typedef typename config_type::graph_type graph_type;
  1169. /// Expose graph components and graph category
  1170. typedef typename traits_type::local_vertex_descriptor
  1171. local_vertex_descriptor;
  1172. typedef typename traits_type::local_edge_descriptor
  1173. local_edge_descriptor;
  1174. typedef typename traits_type::vertex_descriptor vertex_descriptor;
  1175. typedef typename traits_type::edge_descriptor edge_descriptor;
  1176. typedef typename traits_type::directed_category directed_category;
  1177. typedef typename inherited::edge_parallel_category
  1178. edge_parallel_category;
  1179. typedef typename inherited::graph_tag graph_tag;
  1180. // Current implementation requires the ability to have parallel
  1181. // edges in the underlying adjacency_list. Which processor each
  1182. // edge refers to is attached as an internal property. TBD:
  1183. // remove this restriction, which may require some rewriting.
  1184. BOOST_STATIC_ASSERT((is_same<edge_parallel_category,
  1185. allow_parallel_edge_tag>::value));
  1186. /** Determine the graph traversal category.
  1187. *
  1188. * A directed distributed adjacency list models the Distributed
  1189. * Graph, Incidence Graph, and Adjacency Graph
  1190. * concepts. Bidirectional and undirected graphs also model the
  1191. * Bidirectional Graph concept. Note that when modeling these
  1192. * concepts the domains of certain operations (e.g., in_edges)
  1193. * are restricted; see the distributed adjacency_list
  1194. * documentation.
  1195. */
  1196. typedef typename boost::mpl::if_<
  1197. is_same<DirectedS, directedS>,
  1198. directed_distributed_adj_list_tag,
  1199. typename boost::mpl::if_<is_same<DirectedS, bidirectionalS>,
  1200. bidirectional_distributed_adj_list_tag,
  1201. undirected_distributed_adj_list_tag>::type>
  1202. ::type traversal_category;
  1203. typedef typename inherited::degree_size_type degree_size_type;
  1204. typedef typename inherited::vertices_size_type vertices_size_type;
  1205. typedef typename inherited::edges_size_type edges_size_type;
  1206. typedef VertexProperty vertex_property_type;
  1207. typedef EdgeProperty edge_property_type;
  1208. typedef typename inherited::graph_property_type graph_property_type;
  1209. typedef typename inherited::vertex_bundled vertex_bundled;
  1210. typedef typename inherited::edge_bundled edge_bundled;
  1211. typedef typename inherited::graph_bundled graph_bundled;
  1212. typedef typename container_gen<edge_list_selector, edge_descriptor>::type
  1213. local_edge_list_type;
  1214. private:
  1215. typedef typename boost::mpl::if_<is_same<DirectedS, bidirectionalS>,
  1216. typename in_edge_list_type::const_iterator,
  1217. typename inherited::out_edge_iterator>::type
  1218. base_in_edge_iterator;
  1219. typedef typename inherited::out_edge_iterator base_out_edge_iterator;
  1220. typedef typename graph_traits<inherited>::edge_iterator
  1221. base_edge_iterator;
  1222. typedef typename inherited::edge_property_type base_edge_property_type;
  1223. typedef typename local_edge_list_type::const_iterator
  1224. undirected_edge_iterator;
  1225. typedef InDistribution in_distribution_type;
  1226. typedef parallel::trigger_receive_context trigger_receive_context;
  1227. public:
  1228. /// Iterator over the (local) vertices of the graph
  1229. typedef transform_iterator<typename vertex_descriptor::generator,
  1230. typename inherited::vertex_iterator>
  1231. vertex_iterator;
  1232. /// Helper for out_edge_iterator
  1233. typedef typename edge_descriptor::template out_generator<adjacency_list>
  1234. out_edge_generator;
  1235. /// Iterator over the outgoing edges of a vertex
  1236. typedef transform_iterator<out_edge_generator,
  1237. typename inherited::out_edge_iterator>
  1238. out_edge_iterator;
  1239. /// Helper for in_edge_iterator
  1240. typedef typename edge_descriptor::template in_generator<adjacency_list>
  1241. in_edge_generator;
  1242. /// Iterator over the incoming edges of a vertex
  1243. typedef transform_iterator<in_edge_generator, base_in_edge_iterator>
  1244. in_edge_iterator;
  1245. /// Iterator over the neighbors of a vertex
  1246. typedef boost::adjacency_iterator<
  1247. adjacency_list, vertex_descriptor, out_edge_iterator,
  1248. typename std::iterator_traits<base_out_edge_iterator>
  1249. ::difference_type>
  1250. adjacency_iterator;
  1251. /// Iterator over the (local) edges in a graph
  1252. typedef typename boost::mpl::if_<is_same<DirectedS, undirectedS>,
  1253. undirected_edge_iterator,
  1254. transform_iterator<out_edge_generator,
  1255. base_edge_iterator>
  1256. >::type
  1257. edge_iterator;
  1258. public:
  1259. /// The type of the mixin for named vertices
  1260. typedef graph::distributed::maybe_named_graph<graph_type,
  1261. vertex_descriptor,
  1262. edge_descriptor,
  1263. config_type>
  1264. named_graph_mixin;
  1265. /// Process group used for communication
  1266. typedef ProcessGroup process_group_type;
  1267. /// How to refer to a process
  1268. typedef typename process_group_type::process_id_type process_id_type;
  1269. /// Whether this graph is directed, undirected, or bidirectional
  1270. typedef DirectedS directed_selector;
  1271. // Structure used for the lazy addition of vertices
  1272. struct lazy_add_vertex_with_property;
  1273. friend struct lazy_add_vertex_with_property;
  1274. // Structure used for the lazy addition of edges
  1275. struct lazy_add_edge;
  1276. friend struct lazy_add_edge;
  1277. // Structure used for the lazy addition of edges with properties
  1278. struct lazy_add_edge_with_property;
  1279. friend struct lazy_add_edge_with_property;
  1280. /// default_distribution_type is the type of the distribution used if the
  1281. /// user didn't specify an explicit one
  1282. typedef typename graph::distributed::select_distribution<
  1283. InDistribution, VertexProperty, vertices_size_type,
  1284. ProcessGroup>::default_type
  1285. default_distribution_type;
  1286. /// distribution_type is the type of the distribution instance stored in
  1287. /// the maybe_named_graph base class
  1288. typedef typename graph::distributed::select_distribution<
  1289. InDistribution, VertexProperty, vertices_size_type,
  1290. ProcessGroup>::type
  1291. base_distribution_type;
  1292. typedef graph::distributed::shuffled_distribution<
  1293. base_distribution_type> distribution_type;
  1294. private:
  1295. // FIXME: the original adjacency_list contained this comment:
  1296. // Default copy constructor and copy assignment operators OK??? TBD
  1297. // but the adj_list_impl contained these declarations:
  1298. adjacency_list(const adjacency_list& other);
  1299. adjacency_list& operator=(const adjacency_list& other);
  1300. public:
  1301. adjacency_list(const ProcessGroup& pg = ProcessGroup())
  1302. : named_graph_mixin(pg, default_distribution_type(pg, 0)),
  1303. m_local_graph(GraphProperty()),
  1304. process_group_(pg, boost::parallel::attach_distributed_object())
  1305. {
  1306. setup_triggers();
  1307. }
  1308. adjacency_list(const ProcessGroup& pg,
  1309. const base_distribution_type& distribution)
  1310. : named_graph_mixin(pg, distribution),
  1311. m_local_graph(GraphProperty()),
  1312. process_group_(pg, boost::parallel::attach_distributed_object())
  1313. {
  1314. setup_triggers();
  1315. }
  1316. adjacency_list(const GraphProperty& g,
  1317. const ProcessGroup& pg = ProcessGroup())
  1318. : named_graph_mixin(pg, default_distribution_type(pg, 0)),
  1319. m_local_graph(g),
  1320. process_group_(pg, boost::parallel::attach_distributed_object())
  1321. {
  1322. setup_triggers();
  1323. }
  1324. adjacency_list(vertices_size_type n,
  1325. const GraphProperty& p,
  1326. const ProcessGroup& pg,
  1327. const base_distribution_type& distribution)
  1328. : named_graph_mixin(pg, distribution),
  1329. m_local_graph(distribution.block_size(process_id(pg), n), p),
  1330. process_group_(pg, boost::parallel::attach_distributed_object())
  1331. {
  1332. setup_triggers();
  1333. detail::parallel::maybe_initialize_vertex_indices(vertices(base()),
  1334. get(vertex_index, base()));
  1335. }
  1336. adjacency_list(vertices_size_type n,
  1337. const ProcessGroup& pg,
  1338. const base_distribution_type& distribution)
  1339. : named_graph_mixin(pg, distribution),
  1340. m_local_graph(distribution.block_size(process_id(pg), n), GraphProperty()),
  1341. process_group_(pg, boost::parallel::attach_distributed_object())
  1342. {
  1343. setup_triggers();
  1344. detail::parallel::maybe_initialize_vertex_indices(vertices(base()),
  1345. get(vertex_index, base()));
  1346. }
  1347. adjacency_list(vertices_size_type n,
  1348. const GraphProperty& p,
  1349. const ProcessGroup& pg = ProcessGroup())
  1350. : named_graph_mixin(pg, default_distribution_type(pg, n)),
  1351. m_local_graph(this->distribution().block_size(process_id(pg), n), p),
  1352. process_group_(pg, boost::parallel::attach_distributed_object())
  1353. {
  1354. setup_triggers();
  1355. detail::parallel::maybe_initialize_vertex_indices(vertices(base()),
  1356. get(vertex_index, base()));
  1357. }
  1358. adjacency_list(vertices_size_type n,
  1359. const ProcessGroup& pg = ProcessGroup())
  1360. : named_graph_mixin(pg, default_distribution_type(pg, n)),
  1361. m_local_graph(this->distribution().block_size(process_id(pg), n),
  1362. GraphProperty()),
  1363. process_group_(pg, boost::parallel::attach_distributed_object())
  1364. {
  1365. setup_triggers();
  1366. detail::parallel::maybe_initialize_vertex_indices(vertices(base()),
  1367. get(vertex_index, base()));
  1368. }
  1369. /*
  1370. * We assume that every processor sees the same list of edges, so
  1371. * they skip over any that don't originate from themselves. This
  1372. * means that programs switching between a local and a distributed
  1373. * graph will keep the same semantics.
  1374. */
  1375. template <class EdgeIterator>
  1376. adjacency_list(EdgeIterator first, EdgeIterator last,
  1377. vertices_size_type n,
  1378. const ProcessGroup& pg = ProcessGroup(),
  1379. const GraphProperty& p = GraphProperty())
  1380. : named_graph_mixin(pg, default_distribution_type(pg, n)),
  1381. m_local_graph(this->distribution().block_size(process_id(pg), n), p),
  1382. process_group_(pg, boost::parallel::attach_distributed_object())
  1383. {
  1384. setup_triggers();
  1385. typedef typename config_type::VertexListS vertex_list_selector;
  1386. initialize(first, last, n, this->distribution(), vertex_list_selector());
  1387. detail::parallel::maybe_initialize_vertex_indices(vertices(base()),
  1388. get(vertex_index, base()));
  1389. }
  1390. template <class EdgeIterator, class EdgePropertyIterator>
  1391. adjacency_list(EdgeIterator first, EdgeIterator last,
  1392. EdgePropertyIterator ep_iter,
  1393. vertices_size_type n,
  1394. const ProcessGroup& pg = ProcessGroup(),
  1395. const GraphProperty& p = GraphProperty())
  1396. : named_graph_mixin(pg, default_distribution_type(pg, n)),
  1397. m_local_graph(this->distribution().block_size(process_id(pg), n), p),
  1398. process_group_(pg, boost::parallel::attach_distributed_object())
  1399. {
  1400. setup_triggers();
  1401. typedef typename config_type::VertexListS vertex_list_selector;
  1402. initialize(first, last, ep_iter, n, this->distribution(),
  1403. vertex_list_selector());
  1404. detail::parallel::maybe_initialize_vertex_indices(vertices(base()),
  1405. get(vertex_index, base()));
  1406. }
  1407. template <class EdgeIterator>
  1408. adjacency_list(EdgeIterator first, EdgeIterator last,
  1409. vertices_size_type n,
  1410. const ProcessGroup& pg,
  1411. const base_distribution_type& distribution,
  1412. const GraphProperty& p = GraphProperty())
  1413. : named_graph_mixin(pg, distribution),
  1414. m_local_graph(distribution.block_size(process_id(pg), n), p),
  1415. process_group_(pg, boost::parallel::attach_distributed_object())
  1416. {
  1417. setup_triggers();
  1418. typedef typename config_type::VertexListS vertex_list_selector;
  1419. initialize(first, last, n, this->distribution(), vertex_list_selector());
  1420. detail::parallel::maybe_initialize_vertex_indices(vertices(base()),
  1421. get(vertex_index, base()));
  1422. }
  1423. template <class EdgeIterator, class EdgePropertyIterator>
  1424. adjacency_list(EdgeIterator first, EdgeIterator last,
  1425. EdgePropertyIterator ep_iter,
  1426. vertices_size_type n,
  1427. const ProcessGroup& pg,
  1428. const base_distribution_type& distribution,
  1429. const GraphProperty& p = GraphProperty())
  1430. : named_graph_mixin(pg, distribution),
  1431. m_local_graph(this->distribution().block_size(process_id(pg), n), p),
  1432. process_group_(pg, boost::parallel::attach_distributed_object())
  1433. {
  1434. setup_triggers();
  1435. typedef typename config_type::VertexListS vertex_list_selector;
  1436. initialize(first, last, ep_iter, n, distribution,
  1437. vertex_list_selector());
  1438. detail::parallel::maybe_initialize_vertex_indices(vertices(base()),
  1439. get(vertex_index, base()));
  1440. }
  1441. ~adjacency_list()
  1442. {
  1443. synchronize(process_group_);
  1444. }
  1445. void clear()
  1446. {
  1447. base().clear();
  1448. local_edges_.clear();
  1449. named_graph_mixin::clearing_graph();
  1450. }
  1451. void swap(adjacency_list& other)
  1452. {
  1453. using std::swap;
  1454. base().swap(other);
  1455. swap(process_group_, other.process_group_);
  1456. }
  1457. static vertex_descriptor null_vertex()
  1458. {
  1459. return vertex_descriptor(processor_id_type(0),
  1460. inherited::null_vertex());
  1461. }
  1462. inherited& base() { return m_local_graph; }
  1463. const inherited& base() const { return m_local_graph; }
  1464. processor_id_type processor() const { return process_id(process_group_); }
  1465. process_group_type process_group() const { return process_group_.base(); }
  1466. local_edge_list_type& local_edges() { return local_edges_; }
  1467. const local_edge_list_type& local_edges() const { return local_edges_; }
  1468. // Redistribute the vertices of the graph by placing each vertex
  1469. // v on the processor get(vertex_to_processor, v).
  1470. template<typename VertexProcessorMap>
  1471. void redistribute(VertexProcessorMap vertex_to_processor);
  1472. // Directly access a vertex or edge bundle
  1473. vertex_bundled& operator[](vertex_descriptor v)
  1474. {
  1475. BOOST_ASSERT(v.owner == processor());
  1476. return base()[v.local];
  1477. }
  1478. const vertex_bundled& operator[](vertex_descriptor v) const
  1479. {
  1480. BOOST_ASSERT(v.owner == processor());
  1481. return base()[v.local];
  1482. }
  1483. edge_bundled& operator[](edge_descriptor e)
  1484. {
  1485. BOOST_ASSERT(e.owner() == processor());
  1486. return base()[e.local];
  1487. }
  1488. const edge_bundled& operator[](edge_descriptor e) const
  1489. {
  1490. BOOST_ASSERT(e.owner() == processor());
  1491. return base()[e.local];
  1492. }
  1493. graph_bundled& operator[](graph_bundle_t)
  1494. { return get_property(*this); }
  1495. graph_bundled const& operator[](graph_bundle_t) const
  1496. { return get_property(*this); }
  1497. template<typename OStreamConstructibleArchive>
  1498. void save(std::string const& filename) const;
  1499. template<typename IStreamConstructibleArchive>
  1500. void load(std::string const& filename);
  1501. // Callback that will be invoked whenever a new vertex is added locally
  1502. boost::function<void(vertex_descriptor, adjacency_list&)> on_add_vertex;
  1503. // Callback that will be invoked whenever a new edge is added locally
  1504. boost::function<void(edge_descriptor, adjacency_list&)> on_add_edge;
  1505. private:
  1506. // Request vertex->processor mapping for neighbors <does nothing>
  1507. template<typename VertexProcessorMap>
  1508. void
  1509. request_in_neighbors(vertex_descriptor,
  1510. VertexProcessorMap,
  1511. directedS) { }
  1512. // Request vertex->processor mapping for neighbors <does nothing>
  1513. template<typename VertexProcessorMap>
  1514. void
  1515. request_in_neighbors(vertex_descriptor,
  1516. VertexProcessorMap,
  1517. undirectedS) { }
  1518. // Request vertex->processor mapping for neighbors
  1519. template<typename VertexProcessorMap>
  1520. void
  1521. request_in_neighbors(vertex_descriptor v,
  1522. VertexProcessorMap vertex_to_processor,
  1523. bidirectionalS);
  1524. // Clear the list of in-edges, but don't tell the remote processor
  1525. void clear_in_edges_local(vertex_descriptor v, directedS) {}
  1526. void clear_in_edges_local(vertex_descriptor v, undirectedS) {}
  1527. void clear_in_edges_local(vertex_descriptor v, bidirectionalS)
  1528. { get(vertex_in_edges, base())[v.local].clear(); }
  1529. // Remove in-edges that have migrated <does nothing>
  1530. template<typename VertexProcessorMap>
  1531. void
  1532. remove_migrated_in_edges(vertex_descriptor,
  1533. VertexProcessorMap,
  1534. directedS) { }
  1535. // Remove in-edges that have migrated <does nothing>
  1536. template<typename VertexProcessorMap>
  1537. void
  1538. remove_migrated_in_edges(vertex_descriptor,
  1539. VertexProcessorMap,
  1540. undirectedS) { }
  1541. // Remove in-edges that have migrated
  1542. template<typename VertexProcessorMap>
  1543. void
  1544. remove_migrated_in_edges(vertex_descriptor v,
  1545. VertexProcessorMap vertex_to_processor,
  1546. bidirectionalS);
  1547. // Initialize the graph with the given edge list and vertex
  1548. // distribution. This variation works only when
  1549. // VertexListS=vecS, and we know how to create remote vertex
  1550. // descriptors based solely on the distribution.
  1551. template<typename EdgeIterator>
  1552. void
  1553. initialize(EdgeIterator first, EdgeIterator last,
  1554. vertices_size_type, const base_distribution_type& distribution,
  1555. vecS);
  1556. // Initialize the graph with the given edge list, edge
  1557. // properties, and vertex distribution. This variation works
  1558. // only when VertexListS=vecS, and we know how to create remote
  1559. // vertex descriptors based solely on the distribution.
  1560. template<typename EdgeIterator, typename EdgePropertyIterator>
  1561. void
  1562. initialize(EdgeIterator first, EdgeIterator last,
  1563. EdgePropertyIterator ep_iter,
  1564. vertices_size_type, const base_distribution_type& distribution,
  1565. vecS);
  1566. // Initialize the graph with the given edge list, edge
  1567. // properties, and vertex distribution.
  1568. template<typename EdgeIterator, typename EdgePropertyIterator,
  1569. typename VertexListS>
  1570. void
  1571. initialize(EdgeIterator first, EdgeIterator last,
  1572. EdgePropertyIterator ep_iter,
  1573. vertices_size_type n,
  1574. const base_distribution_type& distribution,
  1575. VertexListS);
  1576. // Initialize the graph with the given edge list and vertex
  1577. // distribution. This is nearly identical to the one below it,
  1578. // for which I should be flogged. However, this version does use
  1579. // slightly less memory than the version that accepts an edge
  1580. // property iterator.
  1581. template<typename EdgeIterator, typename VertexListS>
  1582. void
  1583. initialize(EdgeIterator first, EdgeIterator last,
  1584. vertices_size_type n,
  1585. const base_distribution_type& distribution,
  1586. VertexListS);
  1587. public:
  1588. //---------------------------------------------------------------------
  1589. // Build a vertex property instance for the underlying adjacency
  1590. // list from the given property instance of the type exposed to
  1591. // the user.
  1592. base_vertex_property_type
  1593. build_vertex_property(const vertex_property_type& p)
  1594. { return build_vertex_property(p, directed_selector()); }
  1595. base_vertex_property_type
  1596. build_vertex_property(const vertex_property_type& p, directedS)
  1597. {
  1598. return base_vertex_property_type(p);
  1599. }
  1600. base_vertex_property_type
  1601. build_vertex_property(const vertex_property_type& p, bidirectionalS)
  1602. {
  1603. return base_vertex_property_type(in_edge_list_type(), p);
  1604. }
  1605. base_vertex_property_type
  1606. build_vertex_property(const vertex_property_type& p, undirectedS)
  1607. {
  1608. return base_vertex_property_type(p);
  1609. }
  1610. //---------------------------------------------------------------------
  1611. //---------------------------------------------------------------------
  1612. // Build an edge property instance for the underlying adjacency
  1613. // list from the given property instance of the type exposed to
  1614. // the user.
  1615. base_edge_property_type build_edge_property(const edge_property_type& p)
  1616. { return build_edge_property(p, directed_selector()); }
  1617. base_edge_property_type
  1618. build_edge_property(const edge_property_type& p, directedS)
  1619. {
  1620. return base_edge_property_type(0, p);
  1621. }
  1622. base_edge_property_type
  1623. build_edge_property(const edge_property_type& p, bidirectionalS)
  1624. {
  1625. return base_edge_property_type(0, p);
  1626. }
  1627. base_edge_property_type
  1628. build_edge_property(const edge_property_type& p, undirectedS)
  1629. {
  1630. typedef typename base_edge_property_type::next_type
  1631. edge_property_with_id;
  1632. return base_edge_property_type(true, edge_property_with_id(0, p));
  1633. }
  1634. //---------------------------------------------------------------------
  1635. //---------------------------------------------------------------------
  1636. // Opposite of above.
  1637. edge_property_type split_edge_property(const base_edge_property_type& p)
  1638. { return split_edge_property(p, directed_selector()); }
  1639. edge_property_type
  1640. split_edge_property(const base_edge_property_type& p, directedS)
  1641. {
  1642. return p.m_base;
  1643. }
  1644. edge_property_type
  1645. split_edge_property(const base_edge_property_type& p, bidirectionalS)
  1646. {
  1647. return p.m_base;
  1648. }
  1649. edge_property_type
  1650. split_edge_property(const base_edge_property_type& p, undirectedS)
  1651. {
  1652. return p.m_base.m_base;
  1653. }
  1654. //---------------------------------------------------------------------
  1655. /** The set of messages that can be transmitted and received by
  1656. * a distributed adjacency list. This list will eventually be
  1657. * exhaustive, but is currently quite limited.
  1658. */
  1659. enum {
  1660. /**
  1661. * Request to add or find a vertex with the given vertex
  1662. * property. The data will be a vertex_property_type
  1663. * structure.
  1664. */
  1665. msg_add_vertex_with_property = 0,
  1666. /**
  1667. * Request to add or find a vertex with the given vertex
  1668. * property, and request that the remote processor return the
  1669. * descriptor for the added/found edge. The data will be a
  1670. * vertex_property_type structure.
  1671. */
  1672. msg_add_vertex_with_property_and_reply,
  1673. /**
  1674. * Reply to a msg_add_vertex_* message, containing the local
  1675. * vertex descriptor that was added or found.
  1676. */
  1677. msg_add_vertex_reply,
  1678. /**
  1679. * Request to add an edge remotely. The data will be a
  1680. * msg_add_edge_data structure.
  1681. */
  1682. msg_add_edge,
  1683. /**
  1684. * Request to add an edge remotely. The data will be a
  1685. * msg_add_edge_with_property_data structure.
  1686. */
  1687. msg_add_edge_with_property,
  1688. /**
  1689. * Request to add an edge remotely and reply back with the
  1690. * edge descriptor. The data will be a
  1691. * msg_add_edge_data structure.
  1692. */
  1693. msg_add_edge_with_reply,
  1694. /**
  1695. * Request to add an edge remotely and reply back with the
  1696. * edge descriptor. The data will be a
  1697. * msg_add_edge_with_property_data structure.
  1698. */
  1699. msg_add_edge_with_property_and_reply,
  1700. /**
  1701. * Reply message responding to an @c msg_add_edge_with_reply
  1702. * or @c msg_add_edge_with_property_and_reply messages. The
  1703. * data will be a std::pair<edge_descriptor, bool>.
  1704. */
  1705. msg_add_edge_reply,
  1706. /**
  1707. * Indicates that a nonlocal edge has been created that should
  1708. * be added locally. Only valid for bidirectional and
  1709. * undirected graphs. The message carries a
  1710. * msg_nonlocal_edge_data structure.
  1711. */
  1712. msg_nonlocal_edge,
  1713. /**
  1714. * Indicates that a remote edge should be removed. This
  1715. * message does not exist for directedS graphs but may refer
  1716. * to either in-edges or out-edges for undirectedS graphs.
  1717. */
  1718. msg_remove_edge,
  1719. /**
  1720. * Indicates the number of vertices and edges that will be
  1721. * relocated from the source processor to the target
  1722. * processor. The data will be a pair<vertices_size_type,
  1723. * edges_size_type>.
  1724. */
  1725. msg_num_relocated
  1726. };
  1727. typedef detail::parallel::msg_add_edge_data<vertex_descriptor,
  1728. local_vertex_descriptor>
  1729. msg_add_edge_data;
  1730. typedef detail::parallel::msg_add_edge_with_property_data
  1731. <vertex_descriptor, local_vertex_descriptor,
  1732. edge_property_type> msg_add_edge_with_property_data;
  1733. typedef boost::detail::parallel::msg_nonlocal_edge_data<
  1734. edge_property_type,local_edge_descriptor> msg_nonlocal_edge_data;
  1735. typedef boost::detail::parallel::msg_remove_edge_data<edge_descriptor>
  1736. msg_remove_edge_data;
  1737. void send_remove_edge_request(edge_descriptor e)
  1738. {
  1739. process_id_type dest = e.target_processor;
  1740. if (e.target_processor == process_id(process_group_))
  1741. dest = e.source_processor;
  1742. send(process_group_, dest, msg_remove_edge, msg_remove_edge_data(e));
  1743. }
  1744. /// Process incoming messages.
  1745. void setup_triggers();
  1746. void
  1747. handle_add_vertex_with_property(int source, int tag,
  1748. const vertex_property_type&,
  1749. trigger_receive_context);
  1750. local_vertex_descriptor
  1751. handle_add_vertex_with_property_and_reply(int source, int tag,
  1752. const vertex_property_type&,
  1753. trigger_receive_context);
  1754. void
  1755. handle_add_edge(int source, int tag, const msg_add_edge_data& data,
  1756. trigger_receive_context);
  1757. boost::parallel::detail::untracked_pair<edge_descriptor, bool>
  1758. handle_add_edge_with_reply(int source, int tag,
  1759. const msg_add_edge_data& data,
  1760. trigger_receive_context);
  1761. void
  1762. handle_add_edge_with_property(int source, int tag,
  1763. const msg_add_edge_with_property_data&,
  1764. trigger_receive_context);
  1765. boost::parallel::detail::untracked_pair<edge_descriptor, bool>
  1766. handle_add_edge_with_property_and_reply
  1767. (int source, int tag, const msg_add_edge_with_property_data&,
  1768. trigger_receive_context);
  1769. void
  1770. handle_nonlocal_edge(int source, int tag,
  1771. const msg_nonlocal_edge_data& data,
  1772. trigger_receive_context);
  1773. void
  1774. handle_remove_edge(int source, int tag,
  1775. const msg_remove_edge_data& data,
  1776. trigger_receive_context);
  1777. protected:
  1778. /** Add an edge (locally) that was received from another
  1779. * processor. This operation is a no-op for directed graphs,
  1780. * because all edges reside on the local processor. For
  1781. * bidirectional graphs, this routine places the edge onto the
  1782. * list of incoming edges for the target vertex. For undirected
  1783. * graphs, the edge is placed along with all of the other edges
  1784. * for the target vertex, but it is marked as a non-local edge
  1785. * descriptor.
  1786. *
  1787. * \todo There is a potential problem here, where we could
  1788. * unintentionally allow duplicate edges in undirected graphs
  1789. * because the same edge is added on two different processors
  1790. * simultaneously. It's not an issue now, because we require
  1791. * that the graph allow parallel edges. Once we do support
  1792. * containers such as setS or hash_setS that disallow parallel
  1793. * edges we will need to deal with this.
  1794. */
  1795. void
  1796. add_remote_edge(const msg_nonlocal_edge_data&,
  1797. processor_id_type, directedS)
  1798. { }
  1799. /**
  1800. * \overload
  1801. */
  1802. void
  1803. add_remote_edge(const msg_nonlocal_edge_data& data,
  1804. processor_id_type other_proc, bidirectionalS)
  1805. {
  1806. typedef detail::parallel::stored_in_edge<local_edge_descriptor> stored_edge;
  1807. stored_edge edge(other_proc, data.e);
  1808. local_vertex_descriptor v = target(data.e, base());
  1809. boost::graph_detail::push(get(vertex_in_edges, base())[v], edge);
  1810. }
  1811. /**
  1812. * \overload
  1813. */
  1814. void
  1815. add_remote_edge(const msg_nonlocal_edge_data& data,
  1816. processor_id_type other_proc, undirectedS)
  1817. {
  1818. std::pair<local_edge_descriptor, bool> edge =
  1819. detail::parallel::add_local_edge(target(data.e, base()),
  1820. source(data.e, base()),
  1821. build_edge_property(data.get_property()), base());
  1822. BOOST_ASSERT(edge.second);
  1823. put(edge_target_processor_id, base(), edge.first, other_proc);
  1824. if (edge.second && on_add_edge)
  1825. on_add_edge(edge_descriptor(processor(), other_proc, false,
  1826. edge.first),
  1827. *this);
  1828. }
  1829. void
  1830. remove_local_edge(const msg_remove_edge_data&, processor_id_type,
  1831. directedS)
  1832. { }
  1833. void
  1834. remove_local_edge(const msg_remove_edge_data& data,
  1835. processor_id_type other_proc, bidirectionalS)
  1836. {
  1837. /* When the source is local, we first check if the edge still
  1838. * exists (it may have been deleted locally) and, if so,
  1839. * remove it locally.
  1840. */
  1841. vertex_descriptor src = source(data.e, *this);
  1842. vertex_descriptor tgt = target(data.e, *this);
  1843. if (src.owner == process_id(process_group_)) {
  1844. base_out_edge_iterator ei, ei_end;
  1845. for (boost::tie(ei, ei_end) = out_edges(src.local, base());
  1846. ei != ei_end; ++ei) {
  1847. // TBD: can't check the descriptor here, because it could
  1848. // have changed if we're allowing the removal of
  1849. // edges. Egads!
  1850. if (tgt.local == target(*ei, base())
  1851. && get(edge_target_processor_id, base(), *ei) == other_proc)
  1852. break;
  1853. }
  1854. if (ei != ei_end) boost::remove_edge(ei, base());
  1855. remove_local_edge_from_list(src, tgt, undirectedS());
  1856. } else {
  1857. BOOST_ASSERT(tgt.owner == process_id(process_group_));
  1858. in_edge_list_type& in_edges =
  1859. get(vertex_in_edges, base())[tgt.local];
  1860. typename in_edge_list_type::iterator ei;
  1861. for (ei = in_edges.begin(); ei != in_edges.end(); ++ei) {
  1862. if (src.local == source(ei->e, base())
  1863. && src.owner == ei->source_processor)
  1864. break;
  1865. }
  1866. if (ei != in_edges.end()) in_edges.erase(ei);
  1867. }
  1868. }
  1869. void
  1870. remove_local_edge(const msg_remove_edge_data& data,
  1871. processor_id_type other_proc, undirectedS)
  1872. {
  1873. vertex_descriptor local_vertex = source(data.e, *this);
  1874. vertex_descriptor remote_vertex = target(data.e, *this);
  1875. if (remote_vertex.owner == process_id(process_group_)) {
  1876. using std::swap;
  1877. swap(local_vertex, remote_vertex);
  1878. }
  1879. // Remove the edge from the out-edge list, if it is there
  1880. {
  1881. base_out_edge_iterator ei, ei_end;
  1882. for (boost::tie(ei, ei_end) = out_edges(local_vertex.local, base());
  1883. ei != ei_end; ++ei) {
  1884. // TBD: can't check the descriptor here, because it could
  1885. // have changed if we're allowing the removal of
  1886. // edges. Egads!
  1887. if (remote_vertex.local == target(*ei, base())
  1888. && get(edge_target_processor_id, base(), *ei) == other_proc)
  1889. break;
  1890. }
  1891. if (ei != ei_end) boost::remove_edge(ei, base());
  1892. }
  1893. remove_local_edge_from_list(local_vertex, remote_vertex, undirectedS());
  1894. }
  1895. public:
  1896. void
  1897. remove_local_edge_from_list(vertex_descriptor, vertex_descriptor,
  1898. directedS)
  1899. {
  1900. }
  1901. void
  1902. remove_local_edge_from_list(vertex_descriptor, vertex_descriptor,
  1903. bidirectionalS)
  1904. {
  1905. }
  1906. void
  1907. remove_local_edge_from_list(vertex_descriptor src, vertex_descriptor tgt,
  1908. undirectedS)
  1909. {
  1910. // TBD: At some point we'll be able to improve the speed here
  1911. // because we'll know when the edge can't be in the local
  1912. // list.
  1913. {
  1914. typename local_edge_list_type::iterator ei;
  1915. for (ei = local_edges_.begin(); ei != local_edges_.end(); ++ei) {
  1916. if ((source(*ei, *this) == src
  1917. && target(*ei, *this) == tgt)
  1918. || (source(*ei, *this) == tgt
  1919. && target(*ei, *this) == src))
  1920. break;
  1921. }
  1922. if (ei != local_edges_.end()) local_edges_.erase(ei);
  1923. }
  1924. }
  1925. private:
  1926. /// The local subgraph
  1927. inherited m_local_graph;
  1928. /// The process group through which this distributed graph
  1929. /// communicates.
  1930. process_group_type process_group_;
  1931. // TBD: should only be available for undirected graphs, but for
  1932. // now it'll just be empty for directed and bidirectional
  1933. // graphs.
  1934. local_edge_list_type local_edges_;
  1935. };
  1936. //------------------------------------------------------------------------
  1937. // Lazy addition of vertices
  1938. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  1939. struct PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_vertex_with_property
  1940. {
  1941. /// Construct a lazy request to add a vertex
  1942. lazy_add_vertex_with_property(adjacency_list& self,
  1943. const vertex_property_type& property)
  1944. : self(self), property(property), committed(false) { }
  1945. /// Copying a lazy_add_vertex_with_property transfers the
  1946. /// responsibility for adding the vertex to the newly-constructed
  1947. /// object.
  1948. lazy_add_vertex_with_property(const lazy_add_vertex_with_property& other)
  1949. : self(other.self), property(other.property),
  1950. committed(other.committed)
  1951. {
  1952. other.committed = true;
  1953. }
  1954. /// If the vertex has not yet been added, add the vertex but don't
  1955. /// wait for a reply.
  1956. ~lazy_add_vertex_with_property();
  1957. /// Returns commit().
  1958. operator vertex_descriptor() const { return commit(); }
  1959. // Add the vertex. This operation will block if the vertex is
  1960. // being added remotely.
  1961. vertex_descriptor commit() const;
  1962. protected:
  1963. adjacency_list& self;
  1964. vertex_property_type property;
  1965. mutable bool committed;
  1966. private:
  1967. // No copy-assignment semantics
  1968. void operator=(lazy_add_vertex_with_property&);
  1969. };
  1970. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  1971. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_vertex_with_property::
  1972. ~lazy_add_vertex_with_property()
  1973. {
  1974. /// If this vertex has already been created or will be created by
  1975. /// someone else, or if someone threw an exception, we will not
  1976. /// create the vertex now.
  1977. if (committed || boost::core::uncaught_exceptions() > 0)
  1978. return;
  1979. committed = true;
  1980. process_id_type owner
  1981. = static_cast<graph_type&>(self).owner_by_property(property);
  1982. if (owner == self.processor()) {
  1983. /// Add the vertex locally.
  1984. vertex_descriptor v(owner,
  1985. add_vertex(self.build_vertex_property(property),
  1986. self.base()));
  1987. if (self.on_add_vertex)
  1988. self.on_add_vertex(v, self);
  1989. }
  1990. else
  1991. /// Ask the owner of this new vertex to add the vertex. We
  1992. /// don't need a reply.
  1993. send(self.process_group_, owner, msg_add_vertex_with_property,
  1994. property);
  1995. }
  1996. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  1997. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor
  1998. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_vertex_with_property::
  1999. commit() const
  2000. {
  2001. BOOST_ASSERT(!this->committed);
  2002. this->committed = true;
  2003. process_id_type owner
  2004. = static_cast<graph_type&>(self).owner_by_property(property);
  2005. local_vertex_descriptor local_v;
  2006. if (owner == self.processor())
  2007. /// Add the vertex locally.
  2008. local_v = add_vertex(self.build_vertex_property(property),
  2009. self.base());
  2010. else {
  2011. // Request that the remote process add the vertex immediately
  2012. send_oob_with_reply(self.process_group_, owner,
  2013. msg_add_vertex_with_property_and_reply, property,
  2014. local_v);
  2015. }
  2016. vertex_descriptor v(owner, local_v);
  2017. if (self.on_add_vertex)
  2018. self.on_add_vertex(v, self);
  2019. // Build the full vertex descriptor to return
  2020. return v;
  2021. }
  2022. /**
  2023. * Data structure returned from add_edge that will "lazily" add
  2024. * the edge, either when it is converted to a
  2025. * @c pair<edge_descriptor, bool> or when the most recent copy has
  2026. * been destroyed.
  2027. */
  2028. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2029. struct PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge
  2030. {
  2031. /// Construct a lazy request to add an edge
  2032. lazy_add_edge(adjacency_list& self,
  2033. vertex_descriptor source, vertex_descriptor target)
  2034. : self(self), source(source), target(target), committed(false) { }
  2035. /// Copying a lazy_add_edge transfers the responsibility for
  2036. /// adding the edge to the newly-constructed object.
  2037. lazy_add_edge(const lazy_add_edge& other)
  2038. : self(other.self), source(other.source), target(other.target),
  2039. committed(other.committed)
  2040. {
  2041. other.committed = true;
  2042. }
  2043. /// If the edge has not yet been added, add the edge but don't
  2044. /// wait for a reply.
  2045. ~lazy_add_edge();
  2046. /// Returns commit().
  2047. operator std::pair<edge_descriptor, bool>() const { return commit(); }
  2048. // Add the edge. This operation will block if a remote edge is
  2049. // being added.
  2050. std::pair<edge_descriptor, bool> commit() const;
  2051. protected:
  2052. std::pair<edge_descriptor, bool>
  2053. add_local_edge(const edge_property_type& property, directedS) const;
  2054. std::pair<edge_descriptor, bool>
  2055. add_local_edge(const edge_property_type& property, bidirectionalS) const;
  2056. std::pair<edge_descriptor, bool>
  2057. add_local_edge(const edge_property_type& property, undirectedS) const;
  2058. adjacency_list& self;
  2059. vertex_descriptor source;
  2060. vertex_descriptor target;
  2061. mutable bool committed;
  2062. private:
  2063. // No copy-assignment semantics
  2064. void operator=(lazy_add_edge&);
  2065. };
  2066. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2067. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge::~lazy_add_edge()
  2068. {
  2069. /// If this edge has already been created or will be created by
  2070. /// someone else, or if someone threw an exception, we will not
  2071. /// create the edge now.
  2072. if (committed || boost::core::uncaught_exceptions() > 0)
  2073. return;
  2074. committed = true;
  2075. if (source.owner == self.processor())
  2076. this->add_local_edge(edge_property_type(), DirectedS());
  2077. else
  2078. // Request that the remote processor add an edge and, but
  2079. // don't wait for a reply.
  2080. send(self.process_group_, source.owner, msg_add_edge,
  2081. msg_add_edge_data(source, target));
  2082. }
  2083. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2084. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool>
  2085. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge::commit() const
  2086. {
  2087. BOOST_ASSERT(!committed);
  2088. committed = true;
  2089. if (source.owner == self.processor())
  2090. return this->add_local_edge(edge_property_type(), DirectedS());
  2091. else {
  2092. // Request that the remote processor add an edge
  2093. boost::parallel::detail::untracked_pair<edge_descriptor, bool> result;
  2094. send_oob_with_reply(self.process_group_, source.owner,
  2095. msg_add_edge_with_reply,
  2096. msg_add_edge_data(source, target), result);
  2097. return result;
  2098. }
  2099. }
  2100. // Add a local edge into a directed graph
  2101. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2102. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool>
  2103. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge::
  2104. add_local_edge(const edge_property_type& property, directedS) const
  2105. {
  2106. // Add the edge to the local part of the graph
  2107. std::pair<local_edge_descriptor, bool> inserted =
  2108. detail::parallel::add_local_edge(source.local, target.local,
  2109. self.build_edge_property(property),
  2110. self.base());
  2111. if (inserted.second)
  2112. // Keep track of the owner of the target
  2113. put(edge_target_processor_id, self.base(), inserted.first,
  2114. target.owner);
  2115. // Compose the edge descriptor and return the result
  2116. edge_descriptor e(source.owner, target.owner, true, inserted.first);
  2117. // Trigger the on_add_edge event
  2118. if (inserted.second && self.on_add_edge)
  2119. self.on_add_edge(e, self);
  2120. return std::pair<edge_descriptor, bool>(e, inserted.second);
  2121. }
  2122. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2123. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool>
  2124. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge::
  2125. add_local_edge(const edge_property_type& property, bidirectionalS) const
  2126. {
  2127. // Add the directed edge.
  2128. std::pair<edge_descriptor, bool> result
  2129. = this->add_local_edge(property, directedS());
  2130. if (result.second) {
  2131. if (target.owner == self.processor()) {
  2132. // Edge is local, so add the stored edge to the in_edges list
  2133. typedef detail::parallel::stored_in_edge<local_edge_descriptor>
  2134. stored_edge;
  2135. stored_edge e(self.processor(), result.first.local);
  2136. boost::graph_detail::push(get(vertex_in_edges,
  2137. self.base())[target.local], e);
  2138. }
  2139. else {
  2140. // Edge is remote, so notify the target's owner that an edge
  2141. // has been added.
  2142. if (self.process_group_.trigger_context() == boost::parallel::trc_out_of_band)
  2143. send_oob(self.process_group_, target.owner, msg_nonlocal_edge,
  2144. msg_nonlocal_edge_data(result.first.local, property));
  2145. else
  2146. send(self.process_group_, target.owner, msg_nonlocal_edge,
  2147. msg_nonlocal_edge_data(result.first.local, property));
  2148. }
  2149. }
  2150. return result;
  2151. }
  2152. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2153. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool>
  2154. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge::
  2155. add_local_edge(const edge_property_type& property, undirectedS) const
  2156. {
  2157. // Add the directed edge
  2158. std::pair<edge_descriptor, bool> result
  2159. = this->add_local_edge(property, directedS());
  2160. if (result.second) {
  2161. if (target.owner == self.processor()) {
  2162. // Edge is local, so add the new edge to the list
  2163. // TODO: This is not what we want to do for an undirected
  2164. // edge, because we haven't linked the source and target's
  2165. // representations of those edges.
  2166. local_edge_descriptor return_edge =
  2167. detail::parallel::add_local_edge(target.local, source.local,
  2168. self.build_edge_property(property),
  2169. self.base()).first;
  2170. put(edge_target_processor_id, self.base(), return_edge,
  2171. source.owner);
  2172. }
  2173. else {
  2174. // Edge is remote, so notify the target's owner that an edge
  2175. // has been added.
  2176. if (self.process_group_.trigger_context() == boost::parallel::trc_out_of_band)
  2177. send_oob(self.process_group_, target.owner, msg_nonlocal_edge,
  2178. msg_nonlocal_edge_data(result.first.local, property));
  2179. else
  2180. send(self.process_group_, target.owner, msg_nonlocal_edge,
  2181. msg_nonlocal_edge_data(result.first.local, property));
  2182. }
  2183. // Add this edge to the list of local edges
  2184. graph_detail::push(self.local_edges(), result.first);
  2185. }
  2186. return result;
  2187. }
  2188. /**
  2189. * Data structure returned from add_edge that will "lazily" add
  2190. * the edge with its property, either when it is converted to a
  2191. * pair<edge_descriptor, bool> or when the most recent copy has
  2192. * been destroyed.
  2193. */
  2194. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2195. struct PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge_with_property
  2196. : lazy_add_edge
  2197. {
  2198. /// Construct a lazy request to add an edge
  2199. lazy_add_edge_with_property(adjacency_list& self,
  2200. vertex_descriptor source,
  2201. vertex_descriptor target,
  2202. const edge_property_type& property)
  2203. : lazy_add_edge(self, source, target), property(property) { }
  2204. /// Copying a lazy_add_edge transfers the responsibility for
  2205. /// adding the edge to the newly-constructed object.
  2206. lazy_add_edge_with_property(const lazy_add_edge& other)
  2207. : lazy_add_edge(other), property(other.property) { }
  2208. /// If the edge has not yet been added, add the edge but don't
  2209. /// wait for a reply.
  2210. ~lazy_add_edge_with_property();
  2211. /// Returns commit().
  2212. operator std::pair<edge_descriptor, bool>() const { return commit(); }
  2213. // Add the edge. This operation will block if a remote edge is
  2214. // being added.
  2215. std::pair<edge_descriptor, bool> commit() const;
  2216. private:
  2217. // No copy-assignment semantics
  2218. void operator=(lazy_add_edge_with_property&);
  2219. edge_property_type property;
  2220. };
  2221. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2222. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge_with_property::
  2223. ~lazy_add_edge_with_property()
  2224. {
  2225. /// If this edge has already been created or will be created by
  2226. /// someone else, or if someone threw an exception, we will not
  2227. /// create the edge now.
  2228. if (this->committed || boost::core::uncaught_exceptions() > 0)
  2229. return;
  2230. this->committed = true;
  2231. if (this->source.owner == this->self.processor())
  2232. // Add a local edge
  2233. this->add_local_edge(property, DirectedS());
  2234. else
  2235. // Request that the remote processor add an edge and, but
  2236. // don't wait for a reply.
  2237. send(this->self.process_group_, this->source.owner,
  2238. msg_add_edge_with_property,
  2239. msg_add_edge_with_property_data(this->source, this->target,
  2240. property));
  2241. }
  2242. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2243. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool>
  2244. PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge_with_property::
  2245. commit() const
  2246. {
  2247. BOOST_ASSERT(!this->committed);
  2248. this->committed = true;
  2249. if (this->source.owner == this->self.processor())
  2250. // Add a local edge
  2251. return this->add_local_edge(property, DirectedS());
  2252. else {
  2253. // Request that the remote processor add an edge
  2254. boost::parallel::detail::untracked_pair<edge_descriptor, bool> result;
  2255. send_oob_with_reply(this->self.process_group_, this->source.owner,
  2256. msg_add_edge_with_property_and_reply,
  2257. msg_add_edge_with_property_data(this->source,
  2258. this->target,
  2259. property),
  2260. result);
  2261. return result;
  2262. }
  2263. }
  2264. /**
  2265. * Returns the set of vertices local to this processor. Note that
  2266. * although this routine matches a valid expression of a
  2267. * VertexListGraph, it does not meet the semantic requirements of
  2268. * VertexListGraph because it returns only local vertices (not all
  2269. * vertices).
  2270. */
  2271. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2272. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE
  2273. ::vertex_iterator,
  2274. typename PBGL_DISTRIB_ADJLIST_TYPE
  2275. ::vertex_iterator>
  2276. vertices(const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2277. {
  2278. typedef typename PBGL_DISTRIB_ADJLIST_TYPE
  2279. ::vertex_descriptor Vertex;
  2280. typedef typename Vertex::generator generator;
  2281. return std::make_pair(make_transform_iterator(vertices(g.base()).first,
  2282. generator(g.processor())),
  2283. make_transform_iterator(vertices(g.base()).second,
  2284. generator(g.processor())));
  2285. }
  2286. /**
  2287. * Returns the number of vertices local to this processor. Note that
  2288. * although this routine matches a valid expression of a
  2289. * VertexListGraph, it does not meet the semantic requirements of
  2290. * VertexListGraph because it returns only a count of local vertices
  2291. * (not all vertices).
  2292. */
  2293. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2294. typename PBGL_DISTRIB_ADJLIST_TYPE
  2295. ::vertices_size_type
  2296. num_vertices(const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2297. {
  2298. return num_vertices(g.base());
  2299. }
  2300. /***************************************************************************
  2301. * Implementation of Incidence Graph concept
  2302. ***************************************************************************/
  2303. /**
  2304. * Returns the source of edge @param e in @param g.
  2305. */
  2306. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename Edge>
  2307. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor
  2308. source(const detail::parallel::edge_descriptor<Edge>& e,
  2309. const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2310. {
  2311. typedef typename PBGL_DISTRIB_ADJLIST_TYPE
  2312. ::vertex_descriptor Vertex;
  2313. return Vertex(e.source_processor, source(e.local, g.base()));
  2314. }
  2315. /**
  2316. * Returns the target of edge @param e in @param g.
  2317. */
  2318. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename Edge>
  2319. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor
  2320. target(const detail::parallel::edge_descriptor<Edge>& e,
  2321. const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2322. {
  2323. typedef typename PBGL_DISTRIB_ADJLIST_TYPE
  2324. ::vertex_descriptor Vertex;
  2325. return Vertex(e.target_processor, target(e.local, g.base()));
  2326. }
  2327. /**
  2328. * Return the set of edges outgoing from a particular vertex. The
  2329. * vertex @param v must be local to the processor executing this
  2330. * routine.
  2331. */
  2332. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2333. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::out_edge_iterator,
  2334. typename PBGL_DISTRIB_ADJLIST_TYPE::out_edge_iterator>
  2335. out_edges(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v,
  2336. const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2337. {
  2338. BOOST_ASSERT(v.owner == g.processor());
  2339. typedef PBGL_DISTRIB_ADJLIST_TYPE impl;
  2340. typedef typename impl::out_edge_generator generator;
  2341. return std::make_pair(
  2342. make_transform_iterator(out_edges(v.local, g.base()).first,
  2343. generator(g)),
  2344. make_transform_iterator(out_edges(v.local, g.base()).second,
  2345. generator(g)));
  2346. }
  2347. /**
  2348. * Return the number of edges outgoing from a particular vertex. The
  2349. * vertex @param v must be local to the processor executing this
  2350. * routine.
  2351. */
  2352. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2353. typename PBGL_DISTRIB_ADJLIST_TYPE::degree_size_type
  2354. out_degree(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v,
  2355. const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2356. {
  2357. BOOST_ASSERT(v.owner == g.processor());
  2358. return out_degree(v.local, g.base());
  2359. }
  2360. /***************************************************************************
  2361. * Implementation of Bidirectional Graph concept
  2362. ***************************************************************************/
  2363. /**
  2364. * Returns the set of edges incoming to a particular vertex. The
  2365. * vertex @param v must be local to the processor executing this
  2366. * routine.
  2367. */
  2368. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2369. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2370. ::in_edge_iterator,
  2371. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2372. ::in_edge_iterator>
  2373. in_edges(typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2374. ::vertex_descriptor v,
  2375. const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)& g)
  2376. {
  2377. BOOST_ASSERT(v.owner == g.processor());
  2378. typedef PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS) impl;
  2379. typedef typename impl::inherited base_graph_type;
  2380. typedef typename impl::in_edge_generator generator;
  2381. typename property_map<base_graph_type, vertex_in_edges_t>::const_type
  2382. in_edges = get(vertex_in_edges, g.base());
  2383. return std::make_pair(make_transform_iterator(in_edges[v.local].begin(),
  2384. generator(g)),
  2385. make_transform_iterator(in_edges[v.local].end(),
  2386. generator(g)));
  2387. }
  2388. /**
  2389. * \overload
  2390. */
  2391. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2392. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)
  2393. ::in_edge_iterator,
  2394. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)
  2395. ::in_edge_iterator>
  2396. in_edges(typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)
  2397. ::vertex_descriptor v,
  2398. const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)& g)
  2399. {
  2400. BOOST_ASSERT(v.owner == g.processor());
  2401. typedef PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS) impl;
  2402. typedef typename impl::in_edge_generator generator;
  2403. return std::make_pair(
  2404. make_transform_iterator(out_edges(v.local, g.base()).first,
  2405. generator(g)),
  2406. make_transform_iterator(out_edges(v.local, g.base()).second,
  2407. generator(g)));
  2408. }
  2409. /**
  2410. * Returns the number of edges incoming to a particular vertex. The
  2411. * vertex @param v must be local to the processor executing this
  2412. * routine.
  2413. */
  2414. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2415. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)::degree_size_type
  2416. in_degree(typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2417. ::vertex_descriptor v,
  2418. const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)& g)
  2419. {
  2420. BOOST_ASSERT(v.owner == g.processor());
  2421. return get(vertex_in_edges, g.base())[v.local].size();
  2422. }
  2423. /**
  2424. * \overload
  2425. */
  2426. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2427. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)::degree_size_type
  2428. in_degree(typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)
  2429. ::vertex_descriptor v,
  2430. const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)& g)
  2431. {
  2432. BOOST_ASSERT(v.owner == g.processor());
  2433. return out_degree(v.local, g.base());
  2434. }
  2435. /**
  2436. * Returns the number of edges incident on the given vertex. The
  2437. * vertex @param v must be local to the processor executing this
  2438. * routine.
  2439. */
  2440. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2441. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)
  2442. ::degree_size_type
  2443. degree(typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)
  2444. ::vertex_descriptor v,
  2445. const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)& g)
  2446. {
  2447. BOOST_ASSERT(v.owner == g.processor());
  2448. return out_degree(v.local, g.base());
  2449. }
  2450. /**
  2451. * \overload
  2452. */
  2453. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2454. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2455. ::degree_size_type
  2456. degree(typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2457. ::vertex_descriptor v,
  2458. const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)& g)
  2459. {
  2460. BOOST_ASSERT(v.owner == g.processor());
  2461. return out_degree(v, g) + in_degree(v, g);
  2462. }
  2463. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2464. typename PBGL_DISTRIB_ADJLIST_TYPE::edges_size_type
  2465. num_edges(const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2466. {
  2467. return num_edges(g.base());
  2468. }
  2469. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2470. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)::edges_size_type
  2471. num_edges(const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)& g)
  2472. {
  2473. return g.local_edges().size();
  2474. }
  2475. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2476. std::pair<
  2477. typename PBGL_DISTRIB_ADJLIST_TYPE::edge_iterator,
  2478. typename PBGL_DISTRIB_ADJLIST_TYPE::edge_iterator>
  2479. edges(const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2480. {
  2481. typedef PBGL_DISTRIB_ADJLIST_TYPE impl;
  2482. typedef typename impl::out_edge_generator generator;
  2483. return std::make_pair(make_transform_iterator(edges(g.base()).first,
  2484. generator(g)),
  2485. make_transform_iterator(edges(g.base()).second,
  2486. generator(g)));
  2487. }
  2488. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2489. std::pair<
  2490. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)::edge_iterator,
  2491. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)::edge_iterator>
  2492. edges(const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)& g)
  2493. {
  2494. return std::make_pair(g.local_edges().begin(), g.local_edges().end());
  2495. }
  2496. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2497. inline
  2498. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor
  2499. vertex(typename PBGL_DISTRIB_ADJLIST_TYPE::vertices_size_type n,
  2500. const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2501. {
  2502. typedef typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor
  2503. vertex_descriptor;
  2504. return vertex_descriptor(g.distribution()(n), g.distribution().local(n));
  2505. }
  2506. /***************************************************************************
  2507. * Access to particular edges
  2508. ***************************************************************************/
  2509. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2510. std::pair<
  2511. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)::edge_descriptor,
  2512. bool
  2513. >
  2514. edge(typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)::vertex_descriptor u,
  2515. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)::vertex_descriptor v,
  2516. const PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)& g)
  2517. {
  2518. typedef typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)
  2519. ::edge_descriptor edge_descriptor;
  2520. // For directed graphs, u must be local
  2521. BOOST_ASSERT(u.owner == process_id(g.process_group()));
  2522. typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)
  2523. ::out_edge_iterator ei, ei_end;
  2524. for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) {
  2525. if (target(*ei, g) == v) return std::make_pair(*ei, true);
  2526. }
  2527. return std::make_pair(edge_descriptor(), false);
  2528. }
  2529. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2530. std::pair<
  2531. typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor,
  2532. bool
  2533. >
  2534. edge(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor u,
  2535. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v,
  2536. const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2537. {
  2538. typedef typename PBGL_DISTRIB_ADJLIST_TYPE
  2539. ::edge_descriptor edge_descriptor;
  2540. // For bidirectional and undirected graphs, u must be local or v
  2541. // must be local
  2542. if (u.owner == process_id(g.process_group())) {
  2543. typename PBGL_DISTRIB_ADJLIST_TYPE::out_edge_iterator ei, ei_end;
  2544. for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) {
  2545. if (target(*ei, g) == v) return std::make_pair(*ei, true);
  2546. }
  2547. return std::make_pair(edge_descriptor(), false);
  2548. } else if (v.owner == process_id(g.process_group())) {
  2549. typename PBGL_DISTRIB_ADJLIST_TYPE::in_edge_iterator ei, ei_end;
  2550. for (boost::tie(ei, ei_end) = in_edges(v, g); ei != ei_end; ++ei) {
  2551. if (source(*ei, g) == u) return std::make_pair(*ei, true);
  2552. }
  2553. return std::make_pair(edge_descriptor(), false);
  2554. } else {
  2555. BOOST_ASSERT(false);
  2556. abort();
  2557. }
  2558. }
  2559. #if 0
  2560. // TBD: not yet supported
  2561. std::pair<out_edge_iterator, out_edge_iterator>
  2562. edge_range(vertex_descriptor u, vertex_descriptor v,
  2563. const adjacency_list& g);
  2564. #endif
  2565. /***************************************************************************
  2566. * Implementation of Adjacency Graph concept
  2567. ***************************************************************************/
  2568. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2569. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::adjacency_iterator,
  2570. typename PBGL_DISTRIB_ADJLIST_TYPE::adjacency_iterator>
  2571. adjacent_vertices(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v,
  2572. const PBGL_DISTRIB_ADJLIST_TYPE& g)
  2573. {
  2574. typedef typename PBGL_DISTRIB_ADJLIST_TYPE::adjacency_iterator iter;
  2575. return std::make_pair(iter(out_edges(v, g).first, &g),
  2576. iter(out_edges(v, g).second, &g));
  2577. }
  2578. /***************************************************************************
  2579. * Implementation of Mutable Graph concept
  2580. ***************************************************************************/
  2581. /************************************************************************
  2582. * add_edge
  2583. ************************************************************************/
  2584. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2585. typename PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge
  2586. add_edge(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor u,
  2587. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v,
  2588. PBGL_DISTRIB_ADJLIST_TYPE& g)
  2589. {
  2590. typedef typename PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_edge lazy_add_edge;
  2591. return lazy_add_edge(g, u, v);
  2592. }
  2593. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2594. typename PBGL_DISTRIB_ADJLIST_TYPE
  2595. ::lazy_add_edge_with_property
  2596. add_edge(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor u,
  2597. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v,
  2598. typename PBGL_DISTRIB_ADJLIST_TYPE::edge_property_type const& p,
  2599. PBGL_DISTRIB_ADJLIST_TYPE& g)
  2600. {
  2601. typedef typename PBGL_DISTRIB_ADJLIST_TYPE
  2602. ::lazy_add_edge_with_property lazy_add_edge_with_property;
  2603. return lazy_add_edge_with_property(g, u, v, p);
  2604. }
  2605. /************************************************************************
  2606. *
  2607. * remove_edge
  2608. *
  2609. ************************************************************************/
  2610. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2611. void
  2612. remove_edge(typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor e,
  2613. PBGL_DISTRIB_ADJLIST_TYPE& g)
  2614. {
  2615. BOOST_ASSERT(source(e, g).owner == g.processor()
  2616. || target(e, g).owner == g.processor());
  2617. if (target(e, g).owner == g.processor())
  2618. detail::parallel::remove_in_edge(e, g, DirectedS());
  2619. if (source(e, g).owner == g.processor())
  2620. remove_edge(e.local, g.base());
  2621. g.remove_local_edge_from_list(source(e, g), target(e, g), DirectedS());
  2622. if (source(e, g).owner != g.processor()
  2623. || (target(e, g).owner != g.processor()
  2624. && !(is_same<DirectedS, directedS>::value))) {
  2625. g.send_remove_edge_request(e);
  2626. }
  2627. }
  2628. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2629. void
  2630. remove_edge(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor u,
  2631. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v,
  2632. PBGL_DISTRIB_ADJLIST_TYPE& g)
  2633. {
  2634. typedef typename PBGL_DISTRIB_ADJLIST_TYPE
  2635. ::edge_descriptor edge_descriptor;
  2636. std::pair<edge_descriptor, bool> the_edge = edge(u, v, g);
  2637. if (the_edge.second) remove_edge(the_edge.first, g);
  2638. }
  2639. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2640. inline void
  2641. remove_edge(typename PBGL_DISTRIB_ADJLIST_TYPE::out_edge_iterator ei,
  2642. PBGL_DISTRIB_ADJLIST_TYPE& g)
  2643. {
  2644. remove_edge(*ei, g);
  2645. }
  2646. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2647. inline void
  2648. remove_edge(typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)
  2649. ::out_edge_iterator ei,
  2650. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)& g)
  2651. {
  2652. BOOST_ASSERT(source(*ei, g).owner == g.processor());
  2653. remove_edge(ei->local, g.base());
  2654. }
  2655. /************************************************************************
  2656. *
  2657. * remove_out_edge_if
  2658. *
  2659. ************************************************************************/
  2660. namespace parallel { namespace detail {
  2661. /**
  2662. * Function object that applies the underlying predicate to
  2663. * determine if an out-edge should be removed. If so, either
  2664. * removes the incoming edge (if it is stored locally) or sends a
  2665. * message to the owner of the target requesting that it remove
  2666. * the edge.
  2667. */
  2668. template<typename Graph, typename Predicate>
  2669. struct remove_out_edge_predicate
  2670. {
  2671. typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor;
  2672. typedef typename Graph::local_edge_descriptor argument_type;
  2673. typedef typename Graph::directed_selector directed_selector;
  2674. typedef bool result_type;
  2675. remove_out_edge_predicate(Graph& g, Predicate& predicate)
  2676. : g(g), predicate(predicate) { }
  2677. bool operator()(const argument_type& le)
  2678. {
  2679. typedef typename edge_descriptor::template out_generator<Graph>
  2680. generator;
  2681. edge_descriptor e = generator(g)(le);
  2682. if (predicate(e)) {
  2683. if (source(e, g).owner != target(e, g).owner
  2684. && !(is_same<directed_selector, directedS>::value))
  2685. g.send_remove_edge_request(e);
  2686. else
  2687. ::boost::detail::parallel::remove_in_edge(e, g,
  2688. directed_selector());
  2689. g.remove_local_edge_from_list(source(e, g), target(e, g),
  2690. directed_selector());
  2691. return true;
  2692. } else return false;
  2693. }
  2694. private:
  2695. Graph& g;
  2696. Predicate predicate;
  2697. };
  2698. } } // end namespace parallel::detail
  2699. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename Predicate>
  2700. inline void
  2701. remove_out_edge_if
  2702. (typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor u,
  2703. Predicate predicate,
  2704. PBGL_DISTRIB_ADJLIST_TYPE& g)
  2705. {
  2706. typedef PBGL_DISTRIB_ADJLIST_TYPE Graph;
  2707. typedef parallel::detail::remove_out_edge_predicate<Graph, Predicate>
  2708. Pred;
  2709. BOOST_ASSERT(u.owner == g.processor());
  2710. remove_out_edge_if(u.local, Pred(g, predicate), g.base());
  2711. }
  2712. /************************************************************************
  2713. *
  2714. * remove_in_edge_if
  2715. *
  2716. ************************************************************************/
  2717. namespace parallel { namespace detail {
  2718. /**
  2719. * Function object that applies the underlying predicate to
  2720. * determine if an in-edge should be removed. If so, either
  2721. * removes the outgoing edge (if it is stored locally) or sends a
  2722. * message to the owner of the target requesting that it remove
  2723. * the edge. Only required for bidirectional graphs.
  2724. */
  2725. template<typename Graph, typename Predicate>
  2726. struct remove_in_edge_predicate
  2727. {
  2728. typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor;
  2729. typedef bool result_type;
  2730. remove_in_edge_predicate(Graph& g, const Predicate& predicate)
  2731. : g(g), predicate(predicate) { }
  2732. template<typename StoredEdge>
  2733. bool operator()(const StoredEdge& le)
  2734. {
  2735. typedef typename edge_descriptor::template in_generator<Graph>
  2736. generator;
  2737. edge_descriptor e = generator(g)(le);
  2738. if (predicate(e)) {
  2739. if (source(e, g).owner != target(e, g).owner)
  2740. g.send_remove_edge_request(e);
  2741. else
  2742. remove_edge(source(e, g).local, target(e, g).local, g.base());
  2743. return true;
  2744. } else return false;
  2745. }
  2746. private:
  2747. Graph& g;
  2748. Predicate predicate;
  2749. };
  2750. } } // end namespace parallel::detail
  2751. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG, typename Predicate>
  2752. inline void
  2753. remove_in_edge_if
  2754. (typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2755. ::vertex_descriptor u,
  2756. Predicate predicate,
  2757. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)& g)
  2758. {
  2759. typedef PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS) Graph;
  2760. typedef parallel::detail::remove_in_edge_predicate<Graph, Predicate>
  2761. Pred;
  2762. BOOST_ASSERT(u.owner == g.processor());
  2763. graph_detail::erase_if(get(vertex_in_edges, g.base())[u.local],
  2764. Pred(g, predicate));
  2765. }
  2766. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG, typename Predicate>
  2767. inline void
  2768. remove_in_edge_if
  2769. (typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)
  2770. ::vertex_descriptor u,
  2771. Predicate predicate,
  2772. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)& g)
  2773. {
  2774. remove_out_edge_if(u, predicate, g);
  2775. }
  2776. /************************************************************************
  2777. *
  2778. * remove_edge_if
  2779. *
  2780. ************************************************************************/
  2781. namespace parallel { namespace detail {
  2782. /**
  2783. * Function object that applies the underlying predicate to
  2784. * determine if a directed edge can be removed. This only applies
  2785. * to directed graphs.
  2786. */
  2787. template<typename Graph, typename Predicate>
  2788. struct remove_directed_edge_predicate
  2789. {
  2790. typedef typename Graph::local_edge_descriptor argument_type;
  2791. typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor;
  2792. typedef bool result_type;
  2793. remove_directed_edge_predicate(Graph& g, const Predicate& predicate)
  2794. : g(g), predicate(predicate) { }
  2795. bool operator()(const argument_type& le)
  2796. {
  2797. typedef typename edge_descriptor::template out_generator<Graph>
  2798. generator;
  2799. edge_descriptor e = generator(g)(le);
  2800. return predicate(e);
  2801. }
  2802. private:
  2803. Graph& g;
  2804. Predicate predicate;
  2805. };
  2806. } } // end namespace parallel::detail
  2807. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG, typename Predicate>
  2808. inline void
  2809. remove_edge_if(Predicate predicate,
  2810. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)& g)
  2811. {
  2812. typedef PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS) Graph;
  2813. typedef parallel::detail::remove_directed_edge_predicate<Graph,
  2814. Predicate> Pred;
  2815. remove_edge_if(Pred(g, predicate), g.base());
  2816. }
  2817. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG, typename Predicate>
  2818. inline void
  2819. remove_edge_if(Predicate predicate,
  2820. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)& g)
  2821. {
  2822. typedef PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS) Graph;
  2823. typedef parallel::detail::remove_out_edge_predicate<Graph,
  2824. Predicate> Pred;
  2825. remove_edge_if(Pred(g, predicate), g.base());
  2826. }
  2827. namespace parallel { namespace detail {
  2828. /**
  2829. * Function object that applies the underlying predicate to
  2830. * determine if an undirected edge should be removed. If so,
  2831. * removes the local edges associated with the edge and
  2832. * (potentially) sends a message to the remote processor that also
  2833. * is removing this edge.
  2834. */
  2835. template<typename Graph, typename Predicate>
  2836. struct remove_undirected_edge_predicate
  2837. {
  2838. typedef typename graph_traits<Graph>::edge_descriptor argument_type;
  2839. typedef bool result_type;
  2840. remove_undirected_edge_predicate(Graph& g, Predicate& predicate)
  2841. : g(g), predicate(predicate) { }
  2842. bool operator()(const argument_type& e)
  2843. {
  2844. if (predicate(e)) {
  2845. if (source(e, g).owner != target(e, g).owner)
  2846. g.send_remove_edge_request(e);
  2847. if (target(e, g).owner == g.processor())
  2848. ::boost::detail::parallel::remove_in_edge(e, g, undirectedS());
  2849. if (source(e, g).owner == g.processor())
  2850. remove_edge(e.local, g.base());
  2851. return true;
  2852. } else return false;
  2853. }
  2854. private:
  2855. Graph& g;
  2856. Predicate predicate;
  2857. };
  2858. } } // end namespace parallel::detail
  2859. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG, typename Predicate>
  2860. inline void
  2861. remove_edge_if(Predicate predicate,
  2862. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)& g)
  2863. {
  2864. typedef PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS) Graph;
  2865. typedef parallel::detail::remove_undirected_edge_predicate<Graph,
  2866. Predicate> Pred;
  2867. graph_detail::erase_if(g.local_edges(), Pred(g, predicate));
  2868. }
  2869. /************************************************************************
  2870. *
  2871. * clear_vertex
  2872. *
  2873. ************************************************************************/
  2874. namespace parallel { namespace detail {
  2875. struct always_true
  2876. {
  2877. typedef bool result_type;
  2878. template<typename T> bool operator()(const T&) const { return true; }
  2879. };
  2880. } } // end namespace parallel::detail
  2881. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2882. void
  2883. clear_vertex
  2884. (typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2885. ::vertex_descriptor u,
  2886. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)& g)
  2887. {
  2888. clear_out_edges(u, g);
  2889. clear_in_edges(u, g);
  2890. }
  2891. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2892. void
  2893. clear_vertex
  2894. (typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)
  2895. ::vertex_descriptor u,
  2896. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(undirectedS)& g)
  2897. {
  2898. remove_out_edge_if(u, parallel::detail::always_true(), g);
  2899. }
  2900. /************************************************************************
  2901. *
  2902. * clear_out_edges
  2903. *
  2904. ************************************************************************/
  2905. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2906. void
  2907. clear_out_edges
  2908. (typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)::vertex_descriptor u,
  2909. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(directedS)& g)
  2910. {
  2911. BOOST_ASSERT(u.owner == g.processor());
  2912. clear_out_edges(u.local, g.base());
  2913. }
  2914. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2915. void
  2916. clear_out_edges
  2917. (typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2918. ::vertex_descriptor u,
  2919. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)& g)
  2920. {
  2921. remove_out_edge_if(u, parallel::detail::always_true(), g);
  2922. }
  2923. /************************************************************************
  2924. *
  2925. * clear_in_edges
  2926. *
  2927. ************************************************************************/
  2928. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS_CONFIG>
  2929. void
  2930. clear_in_edges
  2931. (typename PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)
  2932. ::vertex_descriptor u,
  2933. PBGL_DISTRIB_ADJLIST_TYPE_CONFIG(bidirectionalS)& g)
  2934. {
  2935. remove_in_edge_if(u, parallel::detail::always_true(), g);
  2936. }
  2937. /************************************************************************
  2938. *
  2939. * add_vertex
  2940. *
  2941. ************************************************************************/
  2942. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2943. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor
  2944. add_vertex(PBGL_DISTRIB_ADJLIST_TYPE& g)
  2945. {
  2946. typedef PBGL_DISTRIB_ADJLIST_TYPE graph_type;
  2947. typename graph_type::vertex_property_type p;
  2948. return add_vertex(p, g);
  2949. }
  2950. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2951. typename PBGL_DISTRIB_ADJLIST_TYPE::lazy_add_vertex_with_property
  2952. add_vertex(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_property_type const& p,
  2953. PBGL_DISTRIB_ADJLIST_TYPE& g)
  2954. {
  2955. typedef typename PBGL_DISTRIB_ADJLIST_TYPE
  2956. ::lazy_add_vertex_with_property lazy_add_vertex;
  2957. return lazy_add_vertex(g, p);
  2958. }
  2959. /************************************************************************
  2960. *
  2961. * remove_vertex
  2962. *
  2963. ************************************************************************/
  2964. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2965. void
  2966. remove_vertex(typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor u,
  2967. PBGL_DISTRIB_ADJLIST_TYPE& g)
  2968. {
  2969. typedef typename PBGL_DISTRIB_ADJLIST_TYPE::graph_type graph_type;
  2970. typedef typename graph_type::named_graph_mixin named_graph_mixin;
  2971. BOOST_ASSERT(u.owner == g.processor());
  2972. static_cast<named_graph_mixin&>(static_cast<graph_type&>(g))
  2973. .removing_vertex(u, boost::graph_detail::iterator_stability(g.base().m_vertices));
  2974. g.distribution().clear();
  2975. remove_vertex(u.local, g.base());
  2976. }
  2977. /***************************************************************************
  2978. * Implementation of Property Graph concept
  2979. ***************************************************************************/
  2980. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename Property>
  2981. struct property_map<PBGL_DISTRIB_ADJLIST_TYPE, Property>
  2982. : detail::parallel::get_adj_list_pmap<Property>
  2983. ::template apply<PBGL_DISTRIB_ADJLIST_TYPE>
  2984. { };
  2985. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename Property>
  2986. struct property_map<PBGL_DISTRIB_ADJLIST_TYPE const, Property>
  2987. : boost::detail::parallel::get_adj_list_pmap<Property>
  2988. // FIXME: in the original code the following was not const
  2989. ::template apply<PBGL_DISTRIB_ADJLIST_TYPE const>
  2990. { };
  2991. template<typename Property, PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  2992. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, Property>::type
  2993. get(Property p, PBGL_DISTRIB_ADJLIST_TYPE& g)
  2994. {
  2995. typedef PBGL_DISTRIB_ADJLIST_TYPE Graph;
  2996. typedef typename property_map<Graph, Property>::type result_type;
  2997. typedef typename property_traits<result_type>::value_type value_type;
  2998. typedef typename property_reduce<Property>::template apply<value_type>
  2999. reduce;
  3000. typedef typename property_traits<result_type>::key_type descriptor;
  3001. typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
  3002. typedef typename mpl::if_<is_same<descriptor, vertex_descriptor>,
  3003. vertex_global_t, edge_global_t>::type
  3004. global_map_t;
  3005. return result_type(g.process_group(), get(global_map_t(), g),
  3006. get(p, g.base()), reduce());
  3007. }
  3008. template<typename Property, PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3009. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, Property>::const_type
  3010. get(Property p, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3011. {
  3012. typedef PBGL_DISTRIB_ADJLIST_TYPE Graph;
  3013. typedef typename property_map<Graph, Property>::const_type result_type;
  3014. typedef typename property_traits<result_type>::value_type value_type;
  3015. typedef typename property_reduce<Property>::template apply<value_type>
  3016. reduce;
  3017. typedef typename property_traits<result_type>::key_type descriptor;
  3018. typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
  3019. typedef typename mpl::if_<is_same<descriptor, vertex_descriptor>,
  3020. vertex_global_t, edge_global_t>::type
  3021. global_map_t;
  3022. return result_type(g.process_group(), get(global_map_t(), g),
  3023. get(p, g.base()), reduce());
  3024. }
  3025. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3026. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_local_index_t>::type
  3027. get(vertex_local_index_t, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3028. {
  3029. return get(vertex_local_index, g.base());
  3030. }
  3031. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3032. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE,
  3033. vertex_local_index_t>::const_type
  3034. get(vertex_local_index_t, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3035. {
  3036. return get(vertex_local_index, g.base());
  3037. }
  3038. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3039. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_global_t>::const_type
  3040. get(vertex_global_t, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3041. {
  3042. typedef typename property_map<
  3043. PBGL_DISTRIB_ADJLIST_TYPE,
  3044. vertex_global_t>::const_type result_type;
  3045. return result_type();
  3046. }
  3047. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3048. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_global_t>::const_type
  3049. get(vertex_global_t, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3050. {
  3051. typedef typename property_map<
  3052. PBGL_DISTRIB_ADJLIST_TYPE,
  3053. vertex_global_t>::const_type result_type;
  3054. return result_type();
  3055. }
  3056. /// Retrieve a property map mapping from a vertex descriptor to its
  3057. /// owner.
  3058. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3059. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_owner_t>::type
  3060. get(vertex_owner_t, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3061. {
  3062. typedef typename property_map<
  3063. PBGL_DISTRIB_ADJLIST_TYPE,
  3064. vertex_owner_t>::type result_type;
  3065. return result_type();
  3066. }
  3067. /// Retrieve a property map mapping from a vertex descriptor to its
  3068. /// owner.
  3069. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3070. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_owner_t>::const_type
  3071. get(vertex_owner_t, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3072. {
  3073. typedef typename property_map<
  3074. PBGL_DISTRIB_ADJLIST_TYPE,
  3075. vertex_owner_t>::const_type result_type;
  3076. return result_type();
  3077. }
  3078. /// Retrieve the owner of a vertex
  3079. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3080. inline processor_id_type
  3081. get(vertex_owner_t, PBGL_DISTRIB_ADJLIST_TYPE&,
  3082. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v)
  3083. {
  3084. return v.owner;
  3085. }
  3086. /// Retrieve the owner of a vertex
  3087. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3088. inline processor_id_type
  3089. get(vertex_owner_t, const PBGL_DISTRIB_ADJLIST_TYPE&,
  3090. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v)
  3091. {
  3092. return v.owner;
  3093. }
  3094. /// Retrieve a property map that maps from a vertex descriptor to
  3095. /// its local descriptor.
  3096. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3097. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_local_t>::type
  3098. get(vertex_local_t, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3099. {
  3100. typedef typename property_map<
  3101. PBGL_DISTRIB_ADJLIST_TYPE,
  3102. vertex_local_t>::type result_type;
  3103. return result_type();
  3104. }
  3105. /// Retrieve a property map that maps from a vertex descriptor to
  3106. /// its local descriptor.
  3107. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3108. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_local_t>::const_type
  3109. get(vertex_local_t, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3110. {
  3111. typedef typename property_map<
  3112. PBGL_DISTRIB_ADJLIST_TYPE,
  3113. vertex_local_t>::const_type result_type;
  3114. return result_type();
  3115. }
  3116. /// Retrieve the local descriptor of a vertex
  3117. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3118. inline typename PBGL_DISTRIB_ADJLIST_TYPE::local_vertex_descriptor
  3119. get(vertex_local_t, PBGL_DISTRIB_ADJLIST_TYPE&,
  3120. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v)
  3121. {
  3122. return v.local;
  3123. }
  3124. /// Retrieve the local descriptor of a vertex
  3125. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3126. inline typename PBGL_DISTRIB_ADJLIST_TYPE::local_vertex_descriptor
  3127. get(vertex_local_t, const PBGL_DISTRIB_ADJLIST_TYPE&,
  3128. typename PBGL_DISTRIB_ADJLIST_TYPE::vertex_descriptor v)
  3129. {
  3130. return v.local;
  3131. }
  3132. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3133. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, edge_global_t>::const_type
  3134. get(edge_global_t, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3135. {
  3136. typedef typename property_map<
  3137. PBGL_DISTRIB_ADJLIST_TYPE,
  3138. edge_global_t>::const_type result_type;
  3139. return result_type();
  3140. }
  3141. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3142. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, edge_global_t>::const_type
  3143. get(edge_global_t, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3144. {
  3145. typedef typename property_map<
  3146. PBGL_DISTRIB_ADJLIST_TYPE,
  3147. edge_global_t>::const_type result_type;
  3148. return result_type();
  3149. }
  3150. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3151. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, edge_owner_t>::type
  3152. get(edge_owner_t, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3153. {
  3154. typedef typename property_map<
  3155. PBGL_DISTRIB_ADJLIST_TYPE,
  3156. edge_owner_t>::type result_type;
  3157. return result_type();
  3158. }
  3159. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3160. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, edge_owner_t>::const_type
  3161. get(edge_owner_t, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3162. {
  3163. typedef typename property_map<
  3164. PBGL_DISTRIB_ADJLIST_TYPE,
  3165. edge_owner_t>::const_type result_type;
  3166. return result_type();
  3167. }
  3168. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3169. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, edge_local_t>::type
  3170. get(edge_local_t, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3171. {
  3172. typedef typename property_map<
  3173. PBGL_DISTRIB_ADJLIST_TYPE,
  3174. edge_local_t>::type result_type;
  3175. return result_type();
  3176. }
  3177. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3178. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, edge_local_t>::const_type
  3179. get(edge_local_t, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3180. {
  3181. typedef typename property_map<
  3182. PBGL_DISTRIB_ADJLIST_TYPE,
  3183. edge_local_t>::const_type result_type;
  3184. return result_type();
  3185. }
  3186. template<typename Property, PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS,
  3187. typename Key>
  3188. inline
  3189. typename property_traits<typename property_map<
  3190. PBGL_DISTRIB_ADJLIST_TYPE, Property>::const_type
  3191. >::value_type
  3192. get(Property p, const PBGL_DISTRIB_ADJLIST_TYPE& g, const Key& key)
  3193. {
  3194. if (owner(key) == process_id(g.process_group()))
  3195. return get(p, g.base(), local(key));
  3196. else
  3197. BOOST_ASSERT(false);
  3198. }
  3199. template<typename Property, PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS,
  3200. typename Key, typename Value>
  3201. void
  3202. put(Property p, PBGL_DISTRIB_ADJLIST_TYPE& g, const Key& key, const Value& v)
  3203. {
  3204. if (owner(key) == process_id(g.process_group()))
  3205. put(p, g.base(), local(key), v);
  3206. else
  3207. BOOST_ASSERT(false);
  3208. }
  3209. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3210. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_index_t>::type
  3211. get(vertex_index_t vi, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3212. {
  3213. typedef PBGL_DISTRIB_ADJLIST_TYPE graph_type;
  3214. typedef typename property_map<graph_type, vertex_index_t>::type
  3215. result_type;
  3216. return result_type(g.process_group(), get(vertex_global, g),
  3217. get(vi, g.base()));
  3218. }
  3219. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3220. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, vertex_index_t>::const_type
  3221. get(vertex_index_t vi, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3222. {
  3223. typedef PBGL_DISTRIB_ADJLIST_TYPE graph_type;
  3224. typedef typename property_map<graph_type, vertex_index_t>::const_type
  3225. result_type;
  3226. return result_type(g.process_group(), get(vertex_global, g),
  3227. get(vi, g.base()));
  3228. }
  3229. /***************************************************************************
  3230. * Implementation of bundled properties
  3231. ***************************************************************************/
  3232. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename T, typename Bundle>
  3233. struct property_map<PBGL_DISTRIB_ADJLIST_TYPE, T Bundle::*>
  3234. : detail::parallel::get_adj_list_pmap<T Bundle::*>
  3235. ::template apply<PBGL_DISTRIB_ADJLIST_TYPE>
  3236. { };
  3237. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename T, typename Bundle>
  3238. struct property_map<PBGL_DISTRIB_ADJLIST_TYPE const, T Bundle::*>
  3239. : detail::parallel::get_adj_list_pmap<T Bundle::*>
  3240. ::template apply<PBGL_DISTRIB_ADJLIST_TYPE const>
  3241. { };
  3242. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename T, typename Bundle>
  3243. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, T Bundle::*>::type
  3244. get(T Bundle::* p, PBGL_DISTRIB_ADJLIST_TYPE& g)
  3245. {
  3246. typedef PBGL_DISTRIB_ADJLIST_TYPE Graph;
  3247. typedef typename property_map<Graph, T Bundle::*>::type result_type;
  3248. typedef typename property_traits<result_type>::value_type value_type;
  3249. typedef typename property_reduce<T Bundle::*>::template apply<value_type>
  3250. reduce;
  3251. typedef typename property_traits<result_type>::key_type descriptor;
  3252. typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
  3253. typedef typename mpl::if_<is_same<descriptor, vertex_descriptor>,
  3254. vertex_global_t, edge_global_t>::type
  3255. global_map_t;
  3256. return result_type(g.process_group(), get(global_map_t(), g),
  3257. get(p, g.base()), reduce());
  3258. }
  3259. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS, typename T, typename Bundle>
  3260. typename property_map<PBGL_DISTRIB_ADJLIST_TYPE, T Bundle::*>::const_type
  3261. get(T Bundle::* p, const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3262. {
  3263. typedef PBGL_DISTRIB_ADJLIST_TYPE Graph;
  3264. typedef typename property_map<Graph, T Bundle::*>::const_type result_type;
  3265. typedef typename property_traits<result_type>::value_type value_type;
  3266. typedef typename property_reduce<T Bundle::*>::template apply<value_type>
  3267. reduce;
  3268. typedef typename property_traits<result_type>::key_type descriptor;
  3269. typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
  3270. typedef typename mpl::if_<is_same<descriptor, vertex_descriptor>,
  3271. vertex_global_t, edge_global_t>::type
  3272. global_map_t;
  3273. return result_type(g.process_group(), get(global_map_t(), g),
  3274. get(p, g.base()), reduce());
  3275. }
  3276. /***************************************************************************
  3277. * Implementation of DistributedGraph concept
  3278. ***************************************************************************/
  3279. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3280. void synchronize(const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3281. {
  3282. synchronize(g.process_group());
  3283. }
  3284. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  3285. ProcessGroup
  3286. process_group(const PBGL_DISTRIB_ADJLIST_TYPE& g)
  3287. { return g.process_group(); }
  3288. /***************************************************************************
  3289. * Specializations of is_mpi_datatype for Serializable entities
  3290. ***************************************************************************/
  3291. namespace mpi {
  3292. template<typename Directed, typename Vertex>
  3293. struct is_mpi_datatype<boost::detail::edge_base<Directed, Vertex> >
  3294. : is_mpi_datatype<Vertex> { };
  3295. template<typename Directed, typename Vertex>
  3296. struct is_mpi_datatype<boost::detail::edge_desc_impl<Directed, Vertex> >
  3297. : is_mpi_datatype<boost::detail::edge_base<Directed, Vertex> > { };
  3298. template<typename LocalDescriptor>
  3299. struct is_mpi_datatype<boost::detail::parallel::global_descriptor<LocalDescriptor> >
  3300. : is_mpi_datatype<LocalDescriptor> { };
  3301. template<typename Edge>
  3302. struct is_mpi_datatype<boost::detail::parallel::edge_descriptor<Edge> >
  3303. : is_mpi_datatype<Edge> { };
  3304. template<typename Vertex, typename LocalVertex>
  3305. struct is_mpi_datatype<boost::detail::parallel::
  3306. msg_add_edge_data<Vertex, LocalVertex> >
  3307. : is_mpi_datatype<Vertex> { };
  3308. template<typename Vertex, typename LocalVertex, typename EdgeProperty>
  3309. struct is_mpi_datatype<boost::detail::parallel::
  3310. msg_add_edge_with_property_data<Vertex,
  3311. LocalVertex,
  3312. EdgeProperty> >
  3313. : mpl::and_<is_mpi_datatype<Vertex>, is_mpi_datatype<EdgeProperty> > { };
  3314. template<typename EdgeProperty, typename EdgeDescriptor>
  3315. struct is_mpi_datatype<boost::detail::parallel::msg_nonlocal_edge_data<
  3316. EdgeProperty,EdgeDescriptor> >
  3317. : mpl::and_<
  3318. is_mpi_datatype<boost::detail::parallel::maybe_store_property<
  3319. EdgeProperty> >,
  3320. is_mpi_datatype<EdgeDescriptor> >
  3321. {};
  3322. template<typename EdgeDescriptor>
  3323. struct is_mpi_datatype<
  3324. boost::detail::parallel::msg_remove_edge_data<EdgeDescriptor> >
  3325. : is_mpi_datatype<EdgeDescriptor> {};
  3326. }
  3327. /***************************************************************************
  3328. * Specializations of is_bitwise_serializable for Serializable entities
  3329. ***************************************************************************/
  3330. namespace serialization {
  3331. template<typename Directed, typename Vertex>
  3332. struct is_bitwise_serializable<boost::detail::edge_base<Directed, Vertex> >
  3333. : is_bitwise_serializable<Vertex> { };
  3334. template<typename Directed, typename Vertex>
  3335. struct is_bitwise_serializable<boost::detail::edge_desc_impl<Directed, Vertex> >
  3336. : is_bitwise_serializable<boost::detail::edge_base<Directed, Vertex> > { };
  3337. template<typename LocalDescriptor>
  3338. struct is_bitwise_serializable<boost::detail::parallel::global_descriptor<LocalDescriptor> >
  3339. : is_bitwise_serializable<LocalDescriptor> { };
  3340. template<typename Edge>
  3341. struct is_bitwise_serializable<boost::detail::parallel::edge_descriptor<Edge> >
  3342. : is_bitwise_serializable<Edge> { };
  3343. template<typename Vertex, typename LocalVertex>
  3344. struct is_bitwise_serializable<boost::detail::parallel::
  3345. msg_add_edge_data<Vertex, LocalVertex> >
  3346. : is_bitwise_serializable<Vertex> { };
  3347. template<typename Vertex, typename LocalVertex, typename EdgeProperty>
  3348. struct is_bitwise_serializable<boost::detail::parallel::
  3349. msg_add_edge_with_property_data<Vertex,
  3350. LocalVertex,
  3351. EdgeProperty> >
  3352. : mpl::and_<is_bitwise_serializable<Vertex>,
  3353. is_bitwise_serializable<EdgeProperty> > { };
  3354. template<typename EdgeProperty, typename EdgeDescriptor>
  3355. struct is_bitwise_serializable<boost::detail::parallel::msg_nonlocal_edge_data<
  3356. EdgeProperty,EdgeDescriptor> >
  3357. : mpl::and_<
  3358. is_bitwise_serializable<
  3359. boost::detail::parallel::maybe_store_property<EdgeProperty> >,
  3360. is_bitwise_serializable<EdgeDescriptor> >
  3361. {};
  3362. template<typename EdgeDescriptor>
  3363. struct is_bitwise_serializable<
  3364. boost::detail::parallel::msg_remove_edge_data<EdgeDescriptor> >
  3365. : is_bitwise_serializable<EdgeDescriptor> {};
  3366. template<typename Directed, typename Vertex>
  3367. struct implementation_level<boost::detail::edge_base<Directed, Vertex> >
  3368. : mpl::int_<object_serializable> {};
  3369. template<typename Directed, typename Vertex>
  3370. struct implementation_level<boost::detail::edge_desc_impl<Directed, Vertex> >
  3371. : mpl::int_<object_serializable> {};
  3372. template<typename LocalDescriptor>
  3373. struct implementation_level<boost::detail::parallel::global_descriptor<LocalDescriptor> >
  3374. : mpl::int_<object_serializable> {};
  3375. template<typename Edge>
  3376. struct implementation_level<boost::detail::parallel::edge_descriptor<Edge> >
  3377. : mpl::int_<object_serializable> {};
  3378. template<typename Vertex, typename LocalVertex>
  3379. struct implementation_level<boost::detail::parallel::
  3380. msg_add_edge_data<Vertex, LocalVertex> >
  3381. : mpl::int_<object_serializable> {};
  3382. template<typename Vertex, typename LocalVertex, typename EdgeProperty>
  3383. struct implementation_level<boost::detail::parallel::
  3384. msg_add_edge_with_property_data<Vertex,
  3385. LocalVertex,
  3386. EdgeProperty> >
  3387. : mpl::int_<object_serializable> {};
  3388. template<typename EdgeProperty, typename EdgeDescriptor>
  3389. struct implementation_level<boost::detail::parallel::msg_nonlocal_edge_data<
  3390. EdgeProperty,EdgeDescriptor> >
  3391. : mpl::int_<object_serializable> {};
  3392. template<typename EdgeDescriptor>
  3393. struct implementation_level<
  3394. boost::detail::parallel::msg_remove_edge_data<EdgeDescriptor> >
  3395. : mpl::int_<object_serializable> {};
  3396. template<typename Directed, typename Vertex>
  3397. struct tracking_level<boost::detail::edge_base<Directed, Vertex> >
  3398. : mpl::int_<track_never> {};
  3399. template<typename Directed, typename Vertex>
  3400. struct tracking_level<boost::detail::edge_desc_impl<Directed, Vertex> >
  3401. : mpl::int_<track_never> {};
  3402. template<typename LocalDescriptor>
  3403. struct tracking_level<boost::detail::parallel::global_descriptor<LocalDescriptor> >
  3404. : mpl::int_<track_never> {};
  3405. template<typename Edge>
  3406. struct tracking_level<boost::detail::parallel::edge_descriptor<Edge> >
  3407. : mpl::int_<track_never> {};
  3408. template<typename Vertex, typename LocalVertex>
  3409. struct tracking_level<boost::detail::parallel::
  3410. msg_add_edge_data<Vertex, LocalVertex> >
  3411. : mpl::int_<track_never> {};
  3412. template<typename Vertex, typename LocalVertex, typename EdgeProperty>
  3413. struct tracking_level<boost::detail::parallel::
  3414. msg_add_edge_with_property_data<Vertex,
  3415. LocalVertex,
  3416. EdgeProperty> >
  3417. : mpl::int_<track_never> {};
  3418. template<typename EdgeProperty, typename EdgeDescriptor>
  3419. struct tracking_level<boost::detail::parallel::msg_nonlocal_edge_data<
  3420. EdgeProperty,EdgeDescriptor> >
  3421. : mpl::int_<track_never> {};
  3422. template<typename EdgeDescriptor>
  3423. struct tracking_level<
  3424. boost::detail::parallel::msg_remove_edge_data<EdgeDescriptor> >
  3425. : mpl::int_<track_never> {};
  3426. }
  3427. // Hash function for global descriptors
  3428. template<typename LocalDescriptor>
  3429. struct hash<detail::parallel::global_descriptor<LocalDescriptor> >
  3430. {
  3431. typedef detail::parallel::global_descriptor<LocalDescriptor> argument_type;
  3432. std::size_t operator()(argument_type const& x) const
  3433. {
  3434. std::size_t hash = hash_value(x.owner);
  3435. hash_combine(hash, x.local);
  3436. return hash;
  3437. }
  3438. };
  3439. // Hash function for parallel edge descriptors
  3440. template<typename Edge>
  3441. struct hash<detail::parallel::edge_descriptor<Edge> >
  3442. {
  3443. typedef detail::parallel::edge_descriptor<Edge> argument_type;
  3444. std::size_t operator()(argument_type const& x) const
  3445. {
  3446. std::size_t hash = hash_value(x.owner());
  3447. hash_combine(hash, x.local);
  3448. return hash;
  3449. }
  3450. };
  3451. } // end namespace boost
  3452. #include <boost/graph/distributed/adjlist/handlers.hpp>
  3453. #include <boost/graph/distributed/adjlist/initialize.hpp>
  3454. #include <boost/graph/distributed/adjlist/redistribute.hpp>
  3455. #include <boost/graph/distributed/adjlist/serialization.hpp>
  3456. #endif // BOOST_GRAPH_DISTRIBUTED_ADJACENCY_LIST_HPP