-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheuropar_tests.cpp
5381 lines (4264 loc) · 192 KB
/
europar_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2012 The Trustees of Indiana University.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Authors: Nicholas Edmonds
// Andrew Lumsdaine
// A small test of nearly everything
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
#include <stdint.h>
#include <inttypes.h>
#include <cstdlib>
//#define DISABLE_SELF_SEND_CHECK
#define AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
#define PBGL2_PRINT_WORK_STATS
// #define PRINT_STATS
// #define PRINT_DEBUG
#define AMPLUSPLUS_PRINT_HIT_RATES
#define BFS_SV_CC_HACK
// #define DS_SHARED_REDUCTIONS
// #define BFS_VECTOR
#define DISABLE_BFS_BITMAP
#ifdef __bgp__
#define BGP_REPORT_MEMORY 1 // if >1 all ranks will report memory usage
#endif
#define NUMBER_COMPONENTS
// #define PBGL_TIMING // turn on local component counting, sequential timing, and such in CC
// #define PRINT_ET
#define BARRIER_TRANS
// #define CLONE
#include <am++/am++.hpp>
#include <am++/mpi_transport.hpp>
#include <am++/counter_coalesced_message_type.hpp>
#include <boost/graph/use_mpi.hpp>
#include <boost/property_map/parallel/distributed_property_map.hpp>
#include <boost/graph/distributed/compressed_sparse_row_graph.hpp>
#include <boost/graph/recursive_rmat_generator.hpp>
#include <boost/graph/erdos_renyi_generator.hpp>
#include <boost/graph/graph500_generator.hpp>
#include <boost/graph/permute_graph.hpp>
#include <boost/graph/parallel/algorithm.hpp> // for all_reduce
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/distributed/delta_stepping_shortest_paths.hpp>
#include <boost/graph/distributed/self_stabilizing_shortest_paths.hpp>
#include <boost/graph/distributed/connected_components.hpp>
#include <boost/graph/distributed/page_rank.hpp>
#include <boost/graph/relax.hpp>
#include <boost/random/linear_congruential.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/property_map/parallel/global_index_map.hpp>
#include <boost/parallel/append_buffer.hpp>
#include <boost/graph/distributed/distributed_control.hpp>
#define HAS_NOT_BEEN_SEEN
// Testing purpose
#define DISABLE_SELF_SEND_CHECK
int _RANK;
using namespace boost;
//
// Memory utilization on BG/P
//
#ifdef BGP_REPORT_MEMORY
/* compile with -I/bgsys/drivers/ppcfloor/arch/include */
#include <spi/kernel_interface.h>
#include <common/bgp_personality.h>
#include <common/bgp_personality_inlines.h>
#include <malloc.h>
/* gives total memory size per MPI process */
void
getMemSize(long long *mem)
{
long long total;
int node_config;
_BGP_Personality_t personality;
Kernel_GetPersonality(&personality, sizeof(personality));
total = BGP_Personality_DDRSizeMB(&personality);
node_config = BGP_Personality_processConfig(&personality);
if (node_config == _BGP_PERS_PROCESSCONFIG_VNM) total /= 4;
else if (node_config == _BGP_PERS_PROCESSCONFIG_2x2) total /= 2;
total *= 1024*1024;
*mem = total;
}
/* gives total memory used
* NOTE: this does not account for static data, only heap
*/
void
getUsedMem(long long *mem)
{
long long alloc;
struct mallinfo m;
m = mallinfo();
alloc = m.hblkhd + m.uordblks;
*mem = alloc;
}
/* gives available memory
* NOTE: this does not account for static data
*/
void
getFreeMem(long long *mem)
{
long long total, alloc;
getMemSize(&total);
getUsedMem(&alloc);
*mem = total - alloc;
}
#endif // BGP_REPORT_MEMORY
//
// Timing code
//
#include <time.h>
#include <sys/time.h>
typedef double time_type;
inline time_type get_time()
{
return MPI_Wtime();
#if 0
timeval tp;
gettimeofday(&tp, 0);
return tp.tv_sec + tp.tv_usec / 1000000.0;
#endif
}
std::string print_time(time_type t)
{
std::ostringstream out;
out << std::setiosflags(std::ios::fixed) << std::setprecision(2) << t;
return out.str();
}
//
// Performance counters
//
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
std::vector<time_type> epoch_times;
// These should really be atomic
typedef unsigned long long flush_type;
typedef amplusplus::detail::atomic<flush_type> atomic_flush_type;
#define FLUSH_MPI_TYPE MPI_UNSIGNED_LONG
atomic_flush_type *flushes;
flush_type flushes_size;
std::vector<flush_type> all_flushes, cumulative_flushes;
atomic_flush_type full{}, messages_received{};
flush_type all_full{}, cumulative_full{}, all_messages{}, cumulative_messages{};
void print_and_clear_epoch_times()
{
if(_RANK == 0) {
std::cout << "There were " << epoch_times.size() << " epochs." << std::endl;
std::cout << "Epoch times ";
BOOST_FOREACH(time_type t, epoch_times) {
std::cout << print_time(t) << " ";
}
std::cout << "\n";
}
epoch_times.clear();
}
void clear_buffer_stats() {
for(unsigned int i = 0; i < flushes_size; ++i)
flushes[i] = 0;
full = 0;
messages_received = 0;
}
void clear_cumulative_buffer_stats() {
for(unsigned int i = 0; i < flushes_size; ++i)
cumulative_flushes[i] = 0;
cumulative_full = 0;
cumulative_messages = 0;
}
void print_buffer_stats() {
unsigned long long sum = 0;
unsigned long long number_of_buffers = 0;
flush_type tmp_flushes[flushes_size];
for(int i = 0; i < flushes_size; ++i)
tmp_flushes[i] = flushes[i].load();
flush_type tmp_full = full.load();
flush_type tmp_messages = messages_received.load();
MPI_Allreduce(&tmp_flushes, &all_flushes.front(), flushes_size, FLUSH_MPI_TYPE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&tmp_full, &all_full, 1, FLUSH_MPI_TYPE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&tmp_messages, &all_messages, 1, FLUSH_MPI_TYPE, MPI_SUM, MPI_COMM_WORLD);
if(_RANK == 0) std::cout << "Flushes: ";
for(unsigned int i = 0; i < all_flushes.size(); ++i) {
if(all_flushes[i] != 0) {
if(_RANK == 0) std::cout << i+1 << "->" << all_flushes[i] << " ";
sum += (i + 1) * all_flushes[i];
number_of_buffers += all_flushes[i];
cumulative_flushes[i] += all_flushes[i];
}
}
cumulative_full += all_full;
cumulative_messages += all_messages;
if(_RANK == 0) {
std::cout << std::endl;
std::cout << "There were " << number_of_buffers << " incomplete flushes with the average size of a flush of " << (number_of_buffers != 0 ? sum/number_of_buffers : 0) << std::endl;
std::cout << "Full buffers: " << all_full << std::endl;
std::cout << "Messages: " << all_messages << std::endl;
}
}
namespace amplusplus {
namespace performance_counters {
void hook_flushed_message_size(amplusplus::rank_type dest, size_t count, size_t elt_size)
{
if(count <= flushes_size)
flushes[count-1]++;
#ifdef PRINT_STATS
time_type t = get_time();
fprintf(stderr, "Flush: %d bytes to %d at %f\n", (count * elt_size), dest, t);
#endif
}
void hook_full_buffer_send(amplusplus::rank_type dest, size_t count, size_t elt_size)
{
full++;
#ifdef PRINT_STATS
time_type t = get_time();
fprintf(stderr, "Full buffer: %d bytes to %d at %f\n", (count * elt_size), dest, t);
#endif
}
void hook_message_received(amplusplus::rank_type src, size_t count, size_t elt_size)
{
messages_received += count;
#ifdef PRINT_STATS
time_type t = get_time();
fprintf(stderr, "%d: Message received: %d bytes from %d at %f\n", _RANK, (count * elt_size), src, t);
#endif
}
void hook_begin_epoch(amplusplus::transport& trans)
{
epoch_times.push_back(get_time());
}
void hook_epoch_finished(amplusplus::transport& trans)
{
epoch_times.back() = get_time() - epoch_times.back();
}
}
}
#endif // AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
// Hit rates
#ifdef AMPLUSPLUS_PRINT_HIT_RATES
unsigned long long cumulative_hits, cumulative_tests;
void print_and_accumulate_cache_stats(std::pair<unsigned long long, unsigned long long> stats) {
unsigned long long hits, tests;
MPI_Allreduce(&stats.first, &hits, 1, MPI_UNSIGNED_LONG, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&stats.second, &tests, 1, MPI_UNSIGNED_LONG, MPI_SUM, MPI_COMM_WORLD);
cumulative_hits += hits;
cumulative_tests += tests;
if(_RANK == 0) {
std::cout << "Cache hit rates: " << hits << " hits, " << tests << " tests. Success ratio: " << (double)hits / (double)tests << "." << std::endl;
}
}
#endif // AMPLUSPLUS_PRINT_HIT_RATES
#ifdef PBGL2_PRINT_WORK_STATS
typedef std::tuple<unsigned long long, unsigned long long, unsigned long long, unsigned long long> work_stats_t;
// Distributed control work stats
work_stats_t dc_stats, ds_stats;
void clear_cumulative_work_stats() {
dc_stats = work_stats_t{ 0ul, 0ul, 0ul, 0ul };
ds_stats = work_stats_t{ 0ul, 0ul, 0ul, 0ul };
}
void print_and_accumulate_work_stats(work_stats_t stats, work_stats_t &cummulative_stats) {
work_stats_t temp_stats;
MPI_Allreduce(&std::get<0>(stats), &std::get<0>(temp_stats), 1, MPI_UNSIGNED_LONG, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&std::get<1>(stats), &std::get<1>(temp_stats), 1, MPI_UNSIGNED_LONG, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&std::get<2>(stats), &std::get<2>(temp_stats), 1, MPI_UNSIGNED_LONG, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&std::get<3>(stats), &std::get<3>(temp_stats), 1, MPI_UNSIGNED_LONG, MPI_SUM, MPI_COMM_WORLD);
if(_RANK == 0) std::cout << "Useful work: " << std::get<0>(temp_stats) << ", ivalidated work: " << std::get<1>(temp_stats) << ", useless work: " << std::get<2>(temp_stats) << ", rejected work: " << std::get<3>(temp_stats) << std::endl;
std::get<0>(cummulative_stats) += std::get<0>(temp_stats);
std::get<1>(cummulative_stats) += std::get<1>(temp_stats);
std::get<2>(cummulative_stats) += std::get<2>(temp_stats);
std::get<3>(cummulative_stats) += std::get<3>(temp_stats);
}
#define PBGL2_DC_PRINT \
<< "\nUseful work: " << (std::get<0>(dc_stats) / num_sources) << " (per source), ivalidated work: " << (std::get<1>(dc_stats) / num_sources) << " (per source), useless work: " << (std::get<2>(dc_stats)/num_sources) << " (per source), rejected work: " << (std::get<3>(dc_stats)/num_sources) << " (per source). Rejected/useful ratio: " << ((double)std::get<3>(dc_stats) / (double)std::get<0>(dc_stats)) << ". Invalidated/useful ratio: " << ((double)std::get<1>(dc_stats) / (double)std::get<0>(dc_stats))
#define PBGL2_DS_PRINT \
<< "\nUseful work: " << (std::get<0>(ds_stats) / num_sources) << " (per source), ivalidated work: " << (std::get<1>(ds_stats) / num_sources) << " (per source), useless work: " << (std::get<2>(ds_stats)/num_sources) << " (per source), rejected work: " << (std::get<3>(ds_stats)/num_sources) << " (per source). Rejected/useful ratio: " << ((double)std::get<3>(ds_stats) / (double)std::get<0>(ds_stats)) << ". Invalidated/useful ratio: " << ((double)std::get<1>(ds_stats) / (double)std::get<0>(ds_stats))
#endif // PBGL2_PRINT_WORK_STATS
//
// Edge properties
//
typedef int32_t weight_type; // Needed so atomics are available on MacOS
struct WeightedEdge {
WeightedEdge(weight_type weight = 0) : weight(weight) { }
weight_type weight;
};
namespace amplusplus {
template<>
struct make_mpi_datatype<WeightedEdge> : make_mpi_datatype_base {
make_mpi_datatype<weight_type> dt1;
scoped_mpi_datatype dt;
make_mpi_datatype(): dt1() {
int blocklengths[1] = {1};
MPI_Aint displacements[1];
WeightedEdge test_object;
MPI_Aint test_object_ptr;
MPI_Get_address(&test_object, &test_object_ptr);
MPI_Get_address(&test_object.weight, &displacements[0]);
displacements[0] -= test_object_ptr;
MPI_Datatype types[1] = {dt1.get()};
MPI_Type_create_struct(1, blocklengths, displacements, types, dt.get_ptr());
MPI_Type_commit(dt.get_ptr());
}
MPI_Datatype get() const {return dt;}
};
}
//
// Edge weight generator iterator
//
template<typename F, typename RandomGenerator>
class generator_iterator
{
public:
typedef std::input_iterator_tag iterator_category;
typedef typename F::result_type value_type;
typedef const value_type& reference;
typedef const value_type* pointer;
typedef void difference_type;
explicit
generator_iterator(RandomGenerator& gen, const F& f = F())
: f(f), gen(&gen)
{
value = this->f(gen);
}
reference operator*() const { return value; }
pointer operator->() const { return &value; }
generator_iterator& operator++()
{
value = f(*gen);
return *this;
}
generator_iterator operator++(int)
{
generator_iterator temp(*this);
++(*this);
return temp;
}
bool operator==(const generator_iterator& other) const
{ return f == other.f; }
bool operator!=(const generator_iterator& other) const
{ return !(*this == other); }
private:
F f;
RandomGenerator* gen;
value_type value;
};
template<typename F, typename RandomGenerator>
inline generator_iterator<F, RandomGenerator>
make_generator_iterator( RandomGenerator& gen, const F& f)
{ return generator_iterator<F, RandomGenerator>(gen, f); }
//
//
//
template <typename Graph, typename OwnerMap, typename LocalMap>
class cc_vertex_compare
{
typedef typename property_traits<OwnerMap>::key_type Vertex;
public:
cc_vertex_compare (const OwnerMap& o, const LocalMap& l)
: owner(o), local(l) { }
bool operator() (const Vertex& x, const Vertex& y)
{
if (x == graph_traits<Graph>::null_vertex()) return false;
if (y == graph_traits<Graph>::null_vertex()) return true;
if (get(local, x) < get(local, y))
return true;
else if (get(local, x) == get(local, y))
return (get(owner, x) < get(owner, y));
return false;
}
private:
OwnerMap owner;
LocalMap local;
};
//
// BFS test helper
//
template <typename Graph, typename ColorMap, typename Queue>
time_type
run_bfs(amplusplus::transport& trans, amplusplus::transport& barrier_trans,
Graph& g, ColorMap& color, shared_ptr<Queue> Q,
typename graph_traits<Graph>::vertex_descriptor current_source, int num_threads,
typename graph_traits<Graph>::vertices_size_type n, bool verify)
{
typedef typename property_traits<ColorMap>::value_type ColorValue;
typedef color_traits<ColorValue> Color;
typedef typename graph_traits<Graph>::vertices_size_type vertices_size_type;
set_property_map_role(vertex_color, color);
color.set_consistency_model(0);
BGL_FORALL_VERTICES_T(v, g, Graph) { put(color, v, Color::white()); }
trans.set_nthreads(num_threads);
boost::graph::distributed::breadth_first_search<Graph, bfs_visitor<>, ColorMap, Queue>
bfs(g, make_bfs_visitor(null_visitor()), color, Q);
bfs.set_source(current_source);
trans.set_nthreads(1);
{ amplusplus::scoped_epoch epoch(barrier_trans); }
// num_threads threads now
trans.set_nthreads(num_threads);
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
epoch_times.clear();
clear_buffer_stats();
#endif
time_type start = get_time();
boost::scoped_array<boost::thread> threads(new boost::thread[num_threads - 1]);
for (int i = 0; i < num_threads - 1; ++i) {
boost::thread thr(boost::ref(bfs), i + 1);
threads[i].swap(thr);
}
// Run algorithm
bfs(0);
for (int i = 0; i < num_threads - 1; ++i)
threads[i].join();
time_type end = get_time();
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
print_and_clear_epoch_times();
print_buffer_stats();
#endif // AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
// Back to one thread
trans.set_nthreads(1);
vertices_size_type visited = 0;
BGL_FORALL_VERTICES_T(v, g, Graph) {
if (get(color, v) == Color::black())
++visited;
}
vertices_size_type total = boost::parallel::all_reduce_sum(barrier_trans, visited);
if (verify)
if (trans.rank() == 0)
std::cout << "Visited " << total << " vertices of " << n << std::endl;
// NGE: This is exceedingly arbitrary... remove later
if (total <= 100) return -1.;
return end - start;
}
struct flip_pair {
template <typename T>
T operator()(const T& x) const {
return std::make_pair(x.second, x.first);
}
};
template <typename Graph, typename WeightMap, typename DistanceMap, typename MessageGenerator>
time_type
run_delta_stepping(amplusplus::transport& trans, amplusplus::transport& barrier_trans, Graph& g, const WeightMap& weight,
DistanceMap& distance, typename graph_traits<Graph>::vertex_descriptor current_source,
weight_type delta, int num_threads, typename graph_traits<Graph>::vertices_size_type n, bool verify,
bool level_sync, MessageGenerator msg_gen) {
#ifdef CLONE
amplusplus::transport trans = trans.clone(); // Clone transport for this run
#endif
typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
typedef typename graph_traits<Graph>::vertices_size_type vertices_size_type;
BGL_FORALL_VERTICES_T(v, g, Graph)
{ put(distance, v, std::numeric_limits<weight_type>::max()); }
trans.set_nthreads(num_threads);
boost::graph::distributed::delta_stepping_shortest_paths<Graph, DistanceMap, WeightMap,
append_buffer<Vertex, 10u>, MessageGenerator>
D(g, distance, weight, delta, msg_gen);
trans.set_nthreads(1);
D.set_source(current_source);
if (level_sync)
D.set_level_sync();
{ amplusplus::scoped_epoch epoch(barrier_trans); }
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
epoch_times.clear();
clear_buffer_stats();
#endif
time_type start = get_time();
// Many threads now
trans.set_nthreads(num_threads);
boost::scoped_array<boost::thread> threads(new boost::thread[num_threads - 1]);
for (int i = 0; i < num_threads - 1; ++i) {
boost::thread thr(boost::ref(D), i + 1);
threads[i].swap(thr);
}
D(0);
for (int i = 0; i < num_threads - 1; ++i)
threads[i].join();
time_type end = get_time();
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
print_and_clear_epoch_times();
print_buffer_stats();
#endif
#ifdef AMPLUSPLUS_PRINT_HIT_RATES
const std::pair<unsigned long long, unsigned long long> stats = D.get_cache_stats();
print_and_accumulate_cache_stats(stats);
#endif
#ifdef PBGL2_PRINT_WORK_STATS
work_stats_t work_stats = D.get_work_stats();
print_and_accumulate_work_stats(work_stats, ds_stats);
#endif
// Back to one thread
trans.set_nthreads(1);
unsigned long long num_levels = D.get_num_levels();
if (verify) {
//
// TODO: DistanceMap uses trans which assumes num_threads are present!
//
distance.set_consistency_model(boost::parallel::cm_forward);
distance.set_max_ghost_cells(0);
{
amplusplus::scoped_epoch epoch(g.transport());
BGL_FORALL_VERTICES_T(v, g, Graph) {
BGL_FORALL_OUTEDGES_T(v, e, g, Graph) {
get(distance, target(e, g));
}
}
}
BGL_FORALL_VERTICES_T(v, g, Graph) {
BGL_FORALL_OUTEDGES_T(v, e, g, Graph) {
#ifdef PRINT_DEBUG
if (get(distance, target(e, g)) > boost::closed_plus<weight_type>()(get(distance, source(e, g)), get(weight, e)))
std::cout << get(get(vertex_local, g), source(e, g)) << "@" << get(get(vertex_owner, g), source(e, g)) << "->"
<< get(get(vertex_local, g), target(e, g)) << "@" << get(get(vertex_owner, g), target(e, g)) << " weight = "
<< get(weight, e)
<< " distance(" << get(get(vertex_local, g), source(e, g)) << "@" << get(get(vertex_owner, g), source(e, g))
<< ") = " << get(distance, source(e, g)) << " distance(" << get(get(vertex_local, g), target(e, g)) << "@"
<< get(get(vertex_owner, g), target(e, g)) << ") = " << get(distance, target(e, g)) << std::endl;
#else
if(get(distance, target(e, g)) >
boost::closed_plus<weight_type>()(get(distance, v), get(weight, e))) std::abort();
#endif
}
}
if (trans.rank() == 0) std::cout << "Verified." << std::endl;
distance.clear(); // Clear memory used by ghost cells
}
vertices_size_type visited = 0;
BGL_FORALL_VERTICES_T(v, g, Graph) {
if (get(distance, v) < std::numeric_limits<weight_type>::max())
++visited;
}
boost::parallel::all_reduce<vertices_size_type, std::plus<vertices_size_type> >
r(trans, std::plus<vertices_size_type>());
vertices_size_type total = r(visited);
//if (verify)
if (trans.rank() == 0)
std::cout << "Visited " << total << " vertices of " << n << " in " << print_time(end - start)
<< ", " << num_levels << " levels required." << std::endl;
if (total < 100) return -1.;
return end - start;
}
template <typename Graph, typename WeightMap, typename DistanceMap, typename MessageGenerator, typename PriorityQueueGenerator = boost::graph::distributed::default_priority_queue_gen>
time_type
run_distributed_control(amplusplus::transport& trans, amplusplus::transport& barrier_trans, Graph& g, const WeightMap& weight,
DistanceMap& distance, typename graph_traits<Graph>::vertex_descriptor current_source, int num_threads,
typename graph_traits<Graph>::vertices_size_type n, bool verify, MessageGenerator msg_gen, MessageGenerator priority_msg_gen, int flushFreq) {
#ifdef CLONE
amplusplus::transport trans = trans.clone(); // Clone transport for this run
#endif
typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
typedef typename graph_traits<Graph>::vertices_size_type vertices_size_type;
// Initialize with infinite (max) distance
BGL_FORALL_VERTICES_T(v, g, Graph)
{ put(distance, v, std::numeric_limits<weight_type>::max()); }
// find the incoming edge factor - i.e. an approximation of number of incoming edges per vertex
unsigned int in_edges = (num_edges(g) / num_vertices(g)) / 2;
trans.set_nthreads(num_threads);
boost::graph::distributed::distributed_control<Graph, DistanceMap, WeightMap, PriorityQueueGenerator, MessageGenerator>
D(g, distance, weight, g.transport(), msg_gen, priority_msg_gen,flushFreq);
trans.set_nthreads(1);
//trans.set_recvdepth(recvDepth);
D.set_source(current_source);
{ amplusplus::scoped_epoch epoch(barrier_trans); }
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
epoch_times.clear();
clear_buffer_stats();
#endif
time_type start = get_time();
// Many threads now
trans.set_nthreads(num_threads);
boost::scoped_array<boost::thread> threads(new boost::thread[num_threads - 1]);
for (int i = 0; i < num_threads - 1; ++i) {
boost::thread thr(boost::ref(D), i + 1);
threads[i].swap(thr);
}
D(0);
for (int i = 0; i < num_threads - 1; ++i)
threads[i].join();
time_type end = get_time();
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
print_and_clear_epoch_times();
print_buffer_stats();
#endif
#ifdef AMPLUSPLUS_PRINT_HIT_RATES
const std::pair<unsigned long long, unsigned long long> stats = D.get_cache_stats();
print_and_accumulate_cache_stats(stats);
#endif
#ifdef PBGL2_PRINT_WORK_STATS
work_stats_t work_stats = D.get_work_stats();
print_and_accumulate_work_stats(work_stats, dc_stats);
#endif
// Back to one thread
trans.set_nthreads(1);
if (verify) {
//
// TODO: DistanceMap uses trans which assumes num_threads are present!
//
distance.set_consistency_model(boost::parallel::cm_forward);
distance.set_max_ghost_cells(0);
{
amplusplus::scoped_epoch epoch(g.transport());
BGL_FORALL_VERTICES_T(v, g, Graph) {
BGL_FORALL_OUTEDGES_T(v, e, g, Graph) {
get(distance, target(e, g));
}
}
}
BGL_FORALL_VERTICES_T(v, g, Graph) {
BGL_FORALL_OUTEDGES_T(v, e, g, Graph) {
#ifdef PRINT_DEBUG
if (get(distance, target(e, g)) > boost::closed_plus<weight_type>()(get(distance, source(e, g)), get(weight, e)))
std::cout << get(get(vertex_local, g), source(e, g)) << "@" << get(get(vertex_owner, g), source(e, g)) << "->"
<< get(get(vertex_local, g), target(e, g)) << "@" << get(get(vertex_owner, g), target(e, g)) << " weight = "
<< get(weight, e)
<< " distance(" << get(get(vertex_local, g), source(e, g)) << "@" << get(get(vertex_owner, g), source(e, g))
<< ") = " << get(distance, source(e, g)) << " distance(" << get(get(vertex_local, g), target(e, g)) << "@"
<< get(get(vertex_owner, g), target(e, g)) << ") = " << get(distance, target(e, g)) << std::endl;
#else
if(get(distance, target(e, g)) >
boost::closed_plus<weight_type>()(get(distance, source(e, g)), get(weight, e))) std::abort();
#endif
}
}
if (trans.rank() == 0) std::cout << "Verified" << std::endl;
distance.clear(); // Clear memory used by ghost cells
}
vertices_size_type visited = 0;
BGL_FORALL_VERTICES_T(v, g, Graph) {
if (get(distance, v) < std::numeric_limits<weight_type>::max())
++visited;
}
boost::parallel::all_reduce<vertices_size_type, std::plus<vertices_size_type> >
r(trans, std::plus<vertices_size_type>());
vertices_size_type total = r(visited);
//if (verify)
if (trans.rank() == 0) {
std::cout << "Visited " << total << " vertices of " << n << " in " << print_time(end - start) << "\n" << std::endl;
}
if (total < 100) return -1.;
// if (trans.rank() == 0) {
// D.print_in_edge_map();
// }
return end - start;
}
template <typename Graph, typename WeightMap, typename DistanceMap, typename PredecessorMap, typename MessageGenerator>
time_type
run_self_stabilizing(amplusplus::transport& trans, amplusplus::transport& barrier_trans, Graph& g,
const WeightMap& weight, DistanceMap& distance, PredecessorMap& predecessor,
typename graph_traits<Graph>::vertex_descriptor current_source,
int num_threads, typename graph_traits<Graph>::vertices_size_type n, bool verify,
bool stats, MessageGenerator msg_gen, unsigned int ordering_size, unsigned int levels, unsigned int delta) {
#ifdef CLONE
amplusplus::transport trans = trans.clone(); // Clone transport for this run
#endif
typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
typedef typename graph_traits<Graph>::vertices_size_type vertices_size_type;
#ifdef PRINT_DEBUG
std::cerr << "run_self_stabilizing: started\n" << std::flush;
#endif
BGL_FORALL_VERTICES_T(v, g, Graph) {
put(distance, v, std::numeric_limits<weight_type>::max());
put(predecessor, v, v); // it does not really matter how we initialize that map as long as we can tell which values have been touched by the algorithm
}
#ifdef PRINT_DEBUG
std::cerr << "run_self_stabilizing: setting the number of threads to " << num_threads << "\n" << std::flush;
#endif
trans.set_nthreads(num_threads);
#ifdef PRINT_DEBUG
std::cerr << "run_self_stabilizing: The number of threads has been successfully set to " << num_threads << "\n" << std::flush;
#endif
boost::graph::distributed::self_stabilizing_shortest_paths<Graph, DistanceMap, WeightMap, PredecessorMap, MessageGenerator>
S(g, distance, weight, predecessor, ordering_size, levels, delta, msg_gen);
trans.set_nthreads(1);
S.set_source(current_source);
{ amplusplus::scoped_epoch epoch(barrier_trans); }
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
clear_buffer_stats();
#endif
time_type start = get_time();
// Many threads now
trans.set_nthreads(num_threads);
boost::scoped_array<boost::thread> threads(new boost::thread[num_threads - 1]);
for (int i = 0; i < num_threads - 1; ++i) {
boost::thread thr(boost::ref(S), i + 1);
threads[i].swap(thr);
}
S(0);
for (int i = 0; i < num_threads - 1; ++i)
threads[i].join();
time_type end = get_time();
#ifdef AMPLUSPLUS_ENABLE_PERFORMANCE_COUNTERS
print_buffer_stats();
#endif
#ifdef PRINT_DEBUG
std::cerr << "We have joined all the threads\n" << std::flush;
#endif
// Back to one thread
trans.set_nthreads(1);
#ifdef PRINT_DEBUG
std::cerr << "run_self_stabilizing: verify is " << verify << "\n" << std::flush;
#endif
if (verify) {
//
// TODO: DistanceMap uses trans which assumes num_threads are present!
//
distance.set_consistency_model(boost::parallel::cm_forward);
distance.set_max_ghost_cells(0);
{
amplusplus::scoped_epoch epoch(g.transport());
BGL_FORALL_VERTICES_T(v, g, Graph) {
BGL_FORALL_OUTEDGES_T(v, e, g, Graph) {
get(distance, target(e, g));
}
}
}
BGL_FORALL_VERTICES_T(v, g, Graph) {
BGL_FORALL_OUTEDGES_T(v, e, g, Graph) {
//#ifdef PRINT_DEBUG
if (get(distance, target(e, g)) > boost::closed_plus<weight_type>()(get(distance, source(e, g)), get(weight, e)))
std::cout << get(get(vertex_local, g), source(e, g)) << "@" << get(get(vertex_owner, g), source(e, g)) << "->"
<< get(get(vertex_local, g), target(e, g)) << "@" << get(get(vertex_owner, g), target(e, g)) << " weight = "
<< get(weight, e)
<< " distance(" << get(get(vertex_local, g), source(e, g)) << "@" << get(get(vertex_owner, g), source(e, g))
<< ") = " << get(distance, source(e, g)) << " distance(" << get(get(vertex_local, g), target(e, g)) << "@"
<< get(get(vertex_owner, g), target(e, g)) << ") = " << get(distance, target(e, g)) << std::endl;
#if 0
//#else
assert(get(distance, target(e, g)) <=
boost::closed_plus<weight_type>()(get(distance, source(e, g)), get(weight, e)));
#endif
}
}
distance.clear(); // Clear memory used by ghost cells
}
vertices_size_type visited = 0;
if(stats) {
BGL_FORALL_VERTICES_T(v, g, Graph) {
if (get(distance, v) < std::numeric_limits<weight_type>::max())
++visited;
}
}
boost::parallel::all_reduce<vertices_size_type, std::plus<vertices_size_type> >
r_count(trans, std::plus<vertices_size_type>());
vertices_size_type total = r_count(visited);
if (stats)
if (trans.rank() == 0) {
std::cout << "Visited " << total << " vertices of " << n << " in " << print_time(end - start) << "." << std::endl;
}
if (total < 100) return -1.;
return end - start;
}
template <typename Graph, typename ParentMap, typename ComponentMap, typename LockMap, typename MessageGenerator>
time_type
run_sv_cc(amplusplus::transport& trans, Graph& g, ParentMap& parent, ComponentMap& component,
LockMap& locks, int num_threads, bool verify, bool level_sync, MessageGenerator msg_gen) {
#ifdef CLONE
amplusplus::transport trans = trans.clone(); // Clone transport for this run
#endif
BGL_FORALL_VERTICES_T(v, g, Graph) {
put(parent, v, v);
}
trans.set_nthreads(num_threads);
boost::graph::distributed::connected_components<Graph, ParentMap, MessageGenerator>
CC(g, parent, locks, msg_gen);
trans.set_nthreads(1);
if (level_sync)
CC.set_level_sync();
{ amplusplus::scoped_epoch epoch(trans); }
time_type start = get_time();
// Many threads now
trans.set_nthreads(num_threads);
boost::scoped_array<boost::thread> threads(new boost::thread[num_threads - 1]);
for (int i = 0; i < num_threads - 1; ++i) {
boost::thread thr(boost::ref(CC), i + 1);
threads[i].swap(thr);
}
CC(0);
for (int i = 0; i < num_threads - 1; ++i)
threads[i].join();
time_type end = get_time();
// Back to one thread
trans.set_nthreads(1);
#ifdef NUMBER_COMPONENTS
int num_components = CC.template number_components<ComponentMap>(component);
if (trans.rank() == 0)
std::cout << num_components << " components found\n";
#endif
if (verify) {
parent.set_max_ghost_cells(0);
{
amplusplus::scoped_epoch epoch(trans);
BGL_FORALL_VERTICES_T(v, g, Graph) {
BGL_FORALL_OUTEDGES_T(v, e, g, Graph) {
get(parent, source(e, g));
get(parent, target(e, g));
}
}
}