adjacency_list.hpp 146 KB

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