-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalg2_robincc.c
More file actions
2870 lines (2416 loc) · 78.4 KB
/
Copy pathalg2_robincc.c
File metadata and controls
2870 lines (2416 loc) · 78.4 KB
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
/*
It is RobinCC
It is similar to alg17, but we leave 4 threads per rank for communication
*/
#include "aux.c"
#include "graph.c"
#include "dist_cc.c"
void* robincc_distributed_cc(
struct dll_800_graph* g, unsigned long* exec_info, unsigned long* ccs_p, int graph_is_symmetric,
int* process_complete_p, unsigned long* in_md_vertex_ID
);
#ifndef __alg2_dont_include_main
int main(int argc, char** args)
{
// Locale initialization
setlocale(LC_NUMERIC, "");
setbuf(stdout, NULL);
setbuf(stderr, NULL);
read_env_vars();
printf("\n");
// Initializing omp
initialize_omp_par_env();
// MPI Init
mpi_init(argc, args, MPI_THREAD_FUNNELED);
// Loading the grpah
unsigned long exec_info[30] = {0};
unsigned int flags = 0U;// 1U: do not collect stats; 8U: do not flush_os_cache
struct dll_800_graph* graph = NULL;
if(strcmp(LL_INPUT_GRAPH_TYPE,"binary") == 0)
graph = get_dll_800_binary(LL_INPUT_GRAPH_PATH, &flags, 64, exec_info);
else if(
strcmp(LL_INPUT_GRAPH_TYPE,"PARAGRAPHER_CSX_WG_800_AP") == 0 ||
strcmp(LL_INPUT_GRAPH_TYPE,"PARAGRAPHER_CSX_WG_404_AP") == 0
)
graph = get_dll_800_webgraph(LL_INPUT_GRAPH_PATH, LL_INPUT_GRAPH_TYPE, &flags, 64, exec_info);
else
{
if(mw_rank == 0)
printf("Input format should be either binary or PARAGRAPHER_CSX_WG_800_AP.\n");
MPI_Finalize();
return -1;
}
if(graph == NULL)
return -2;
MPI_Barrier(MPI_COMM_WORLD);
unsigned long ccs_count = 0;
int process_complete = 0;
unsigned long md_vertex_ID = -1UL;
void* cc = robincc_distributed_cc(graph, exec_info + 10, &ccs_count,
LL_INPUT_GRAPH_IS_SYMMETRIC, &process_complete, &md_vertex_ID);
if(process_complete == 0)
goto report;
unsigned int* cc_ui = NULL;
unsigned long* cc_ul = NULL;
if(graph->vertices_count < (1UL<<32))
cc_ui = (unsigned int*)cc;
else
cc_ul = (unsigned long*)cc;
MPI_Barrier(MPI_COMM_WORLD);
// Verification
int validated = 0;
if(graph->edges_count < 1e11)
{
// Collect CC results if it is distributed
// Validation
{
unsigned long cenol_ccs_count = 0;
void* cenol_cc = dist_cc_jt_cent_non_olap_async(graph, NULL, &cenol_ccs_count, LL_INPUT_GRAPH_IS_SYMMETRIC);
unsigned int* cenol_cc_ui = NULL;
unsigned long* cenol_cc_ul = NULL;
if(graph->vertices_count < (1UL<<32))
cenol_cc_ui = (unsigned int*)cenol_cc;
else
cenol_cc_ul = (unsigned long*)cenol_cc;
if(mw_rank == 0 && cenol_cc != NULL)
{
if(cenol_cc_ui != NULL)
#pragma omp parallel for
for(unsigned long v = 0; v < graph->vertices_count; v++)
{
assert(cc_ui[cenol_cc_ui[v]] == cc_ui[v]);
if(cc_ui[v] == 0)
assert(cenol_cc_ui[v] == cenol_cc_ui[md_vertex_ID]);
else
assert(cenol_cc_ui[cc_ui[v] - 1] == cenol_cc_ui[v]);
}
else
#pragma omp parallel for
for(unsigned long v = 0; v < graph->vertices_count; v++)
{
assert(cc_ul[cenol_cc_ul[v]] == cc_ul[v]);
if(cc_ul[v] == 0)
assert(cenol_cc_ul[v] == cenol_cc_ul[md_vertex_ID]);
else
assert(cenol_cc_ul[cc_ul[v] - 1] == cenol_cc_ul[v]);
}
assert(cenol_ccs_count == ccs_count);
printf("\n\nValidation completed.\n");
fflush(stdout);
if(cenol_cc_ui != NULL)
{
numa_free(cenol_cc_ui, sizeof(unsigned int) * graph->vertices_count);
cenol_cc_ui = NULL;
}
else
{
numa_free(cenol_cc_ul, sizeof(unsigned long) * graph->vertices_count);
cenol_cc_ul = NULL;
}
validated = 1;
}
}
}
// Writing to the report
report:
if(LL_OUTPUT_REPORT_PATH != NULL && mw_rank == 0)
{
FILE* out = fopen(LL_OUTPUT_REPORT_PATH, "a");
if(out == NULL)
printf("Could not open the report file on %s.\n", LL_OUTPUT_REPORT_PATH);
else
{
if(LL_INPUT_GRAPH_BATCH_ORDER == 0)
{
fprintf(out, "%-20s; %-8s; %-8s;", "Dataset", "|V|", "|E|");
fprintf(out, " %-6s; %-6s; %-9s;", "#Nodes", "#Cores", "LD(s)");
fprintf(out, " %-10s; %-6s; %-9s;", "CC Time(s)", "LdImb%", "Net (GB)");
fprintf(out, " %-12s; %-1s;", "|CCs|", "V");
fprintf(out, "\n");
}
char temp1 [16];
char temp2 [16];
fprintf(out, "%-20s; %-8s; %-8s;", // "Dataset", "|V|", "|E|"
LL_INPUT_GRAPH_BASE_NAME, ul2s(graph->vertices_count, temp1), ul2s(graph->edges_count, temp2)
);
fprintf(out, " %6u; %6u; %9.1f;", // "#Nodes", "#Cores" "LD(s)"
mw_size, total_cores, exec_info[0] / 1e9
);
unsigned long* cei = exec_info + 10;
fprintf(out, " %10.1f; %6.1f; %9.1f;", // "CC Time(s)", "LdImb%", "Net (GB)"
cei[0] / 1e9, cei[1]/1e4, cei[3]/1e9
);
fprintf(out, " %12lu; %1d;", ccs_count, validated); // "|CCs|","Vld"
fprintf(out, "\n");
fclose(out);
out = NULL;
}
}
// Releasing memory
if(cc_ui != NULL)
{
numa_free(cc_ui, sizeof(unsigned int) * graph->vertices_count);
cc_ui = NULL;
}
if(cc_ul != NULL)
{
numa_free(cc_ul, sizeof(unsigned long) * graph->vertices_count);
cc_ul = NULL;
}
cc = NULL;
release_numa_interleaved_dll_800_graph(graph);
graph = NULL;
// Finalizing
int mret = MPI_Finalize();
assert(mret == MPI_SUCCESS);
if(mw_rank == 0)
printf("\n\n");
return 0;
}
#endif
/*
MPI tags:
40 (snapshot, non-zero and non-root values),
41 (#buffers for snapshot 40 and zerored CC vals 43),
42 (Initial Push, one & only one buffer),
43 (Zero-ed CC vals, sent, continuously)
*/
struct __robincc_buffer
{
unsigned long lock; // protecting writes to any of `allocated_count`, `access_count`, and `effective_blocks_count` fields
unsigned long allocated_count;
unsigned long access_count;
unsigned long sender_rank;
unsigned long effective_blocks_count;
unsigned long last_block_size;
unsigned long recv_type; // 40, 42, or 43
};
/*
Send buffer
Used to send type 43
Statuses:
(1) allocated_count < blocks_per_buffer
(2) allocated_count == blocks_per_buffer && access_count == 0: buffer is going to be sent, wait
Recv buffer
Used to receive all types: 40/42/43
Statuses:
(1) allocated_count == effective_blocks_count and access_count == 0: buffer does not contain any thing, waiting for receiving
(2) allocated_count < effective_blocks_count: each thread can allocate a block and process it
*/
struct __robincc_buffer_group
{
struct __robincc_buffer* buffers;
MPI_Request* requests;
struct __robincc_buffer_group* next_group;
unsigned char* mem;
};
struct __robincc_buffers
{
unsigned long send_0_recv_1;
unsigned long bytes_per_vertex;
unsigned long vertex_pairs_per_block;
unsigned long block_size;
unsigned long blocks_per_buffer;
unsigned long buffer_size;
unsigned long buffers_per_group;
unsigned long group_adding_lock;
unsigned long groups_count;
// For recv
unsigned long* processed_40_43_buffers;
unsigned long processed_42_buffer;
struct __robincc_buffer_group* first_group;
};
struct __robincc_block_ID
{
struct __robincc_buffer_group* group;
struct __robincc_buffer* buff;
unsigned long buff_index;
unsigned long block_index;
unsigned long block_size;
};
int __robincc_group_allocate(struct __robincc_buffers* buffs)
{
assert(buffs != NULL);
if(!__sync_bool_compare_and_swap(&buffs->group_adding_lock, 0UL, 1UL))
return -1;
struct __robincc_buffer_group** gp = &buffs->first_group;
while((*gp) != NULL)
gp = &((*gp)->next_group);
struct __robincc_buffer_group* g = calloc(sizeof(struct __robincc_buffer_group), 1);
assert(g != NULL);
g->buffers = calloc(sizeof(struct __robincc_buffer), buffs->buffers_per_group);
assert(g->buffers != NULL);
g->requests = calloc(sizeof(MPI_Request), buffs->buffers_per_group);
assert(g->requests != NULL);
for(unsigned long r = 0; r < buffs->buffers_per_group; r++)
g->requests[r] = MPI_REQUEST_NULL;
g->next_group = NULL;
g->mem = numa_alloc_interleaved(buffs->buffer_size * buffs->buffers_per_group);
assert(g->mem != NULL);
for(unsigned long b = 0; b < buffs->buffers_per_group; b++)
{
g->buffers[b].effective_blocks_count = buffs->blocks_per_buffer;
g->buffers[b].access_count = 0;
g->buffers[b].sender_rank = -1UL;
g->buffers[b].last_block_size = buffs->block_size;
g->buffers[b].recv_type = -1UL;
g->buffers[b].lock = 0;
if(buffs->send_0_recv_1 == 1)
g->buffers[b].allocated_count = buffs->blocks_per_buffer; // Prevent accessing by comp thread before receiving something
else
g->buffers[b].allocated_count = 0; // allow access
}
*gp = g;
buffs->groups_count++;
__sync_synchronize();
buffs->group_adding_lock = 0;
return 0;
}
void __robincc_cont_releae_block(struct __robincc_buffers* buffs, struct __robincc_block_ID* prev_block)
{
assert(buffs != NULL);
assert(buffs->first_group != NULL);
assert(prev_block != NULL);
assert(buffs->send_0_recv_1 == 0);
// Lock the buffer
while(1)
{
if(__sync_bool_compare_and_swap(&prev_block->buff->lock, 0, 1))
break;
usleep(10);
}
prev_block->buff->access_count--;
// Unlock the buffer
__sync_synchronize();
prev_block->buff->lock = 0;
prev_block->group = NULL;
prev_block->buff = NULL;
prev_block->buff_index = -1UL;
prev_block->block_index = -1UL;
return;
}
unsigned char* __robincc_get_a_block(struct __robincc_buffers* buffs, struct __robincc_block_ID* prev_block)
{
assert(buffs != NULL);
assert(buffs->first_group != NULL);
assert(prev_block != NULL);
if(prev_block->group == NULL)
{
// First access
prev_block->group = buffs->first_group;
prev_block->buff = prev_block->group->buffers;
prev_block->buff_index = 0UL;
prev_block->block_index = -1UL;
}
else
{
// Release the block
// Lock the buffer
while(1)
{
if(__sync_bool_compare_and_swap(&prev_block->buff->lock, 0, 1))
break;
usleep(10);
}
prev_block->buff->access_count--;
if(buffs->send_0_recv_1 == 1)
if(prev_block->buff->access_count == 0 && prev_block->buff->allocated_count == prev_block->buff->effective_blocks_count)
{
// A received buffer has been completely processed.
assert(buffs->processed_40_43_buffers != NULL);
assert(prev_block->buff->sender_rank < mw_size);
if(prev_block->buff->recv_type == 40 || prev_block->buff->recv_type == 43)
{
__sync_add_and_fetch(buffs->processed_40_43_buffers + prev_block->buff->sender_rank, 1UL);
}
else
{
assert(prev_block->buff->recv_type == 42);
assert(buffs->processed_42_buffer == 0);
buffs->processed_42_buffer = 1;
printf(" R%u; finished processing ZPIP buffer.\n", mw_rank);
}
}
// Unlock the buffer
__sync_synchronize();
prev_block->buff->lock = 0;
}
unsigned long tries = 1;
struct __robincc_buffer_group* g = prev_block->group;
while(1)
{
for(unsigned long rbf = 0; rbf < buffs->buffers_per_group; rbf++)
{
unsigned long bfi;
if(g == prev_block->group)
bfi = (rbf + prev_block->buff_index) % buffs->buffers_per_group;
else
bfi = rbf;
struct __robincc_buffer* bf = &g->buffers[bfi];
if(bf->allocated_count == bf->effective_blocks_count)
continue;
// Lock the buffer
while(1)
{
if(__sync_bool_compare_and_swap(&bf->lock, 0, 1))
break;
usleep(10);
}
if(bf->allocated_count >= bf->effective_blocks_count)
{
bf->lock = 0;
continue;
}
unsigned long bli = bf->allocated_count;
bf->allocated_count++;
bf->access_count++;
// Unlock the buffer
__sync_synchronize();
bf->lock = 0;
// Update the prev_block
prev_block->group = g;
prev_block->buff = bf;
prev_block->buff_index = bfi;
prev_block->block_index = bli;
if(bli + 1 == bf->effective_blocks_count)
prev_block->block_size = bf->last_block_size;
else
prev_block->block_size = buffs->block_size;
__sync_synchronize();
return g->mem + bfi * buffs->buffer_size + bli * buffs->block_size;
}
struct __robincc_buffer_group* ng = g->next_group;
if(ng == NULL)
ng = buffs->first_group;
if(ng != prev_block->group)
{
g = ng;
continue;
}
if(buffs->send_0_recv_1 == 1)
{
prev_block->group = NULL;
prev_block->buff = NULL;
prev_block->buff_index = -1UL;
prev_block->block_index = -1UL;
return NULL;
}
// We should not reach here ...
// Wait for a buffer to be released and try again
usleep(100);
g = ng;
tries++;
if(tries % 1000 == 0)
printf(" R%u; Could not assign send buff; tries: %u.\n", mw_rank, tries);
assert(tries < 1e6 );
}
return NULL;
}
void __robincc_buffer_free(struct __robincc_buffers* buffs)
{
assert(buffs != NULL);
if(buffs->processed_40_43_buffers != NULL)
{
free(buffs->processed_40_43_buffers);
buffs->processed_40_43_buffers = NULL;
}
struct __robincc_buffer_group* g = buffs->first_group;
while(g != NULL)
{
struct __robincc_buffer_group* ng = g->next_group;
free(g->buffers);
g->buffers = NULL;
free(g->requests);
g->requests = NULL;
numa_free(g->mem, buffs->buffer_size * buffs->buffers_per_group);
g->mem = NULL;
free(g);
g = ng;
}
free(buffs);
buffs = NULL;
return;
}
void* __robincc_comp_thread(void* in_args)
{
// Init
assert(in_args != NULL);
int min_paritions_per_iteration = 16;
unsigned long local_t0 = - get_nano_time();
unsigned int comp_threads_count;
if(mw_size == 0)
comp_threads_count = pe->threads_count;
else
comp_threads_count = pe->threads_count - 4;
// Thread pinning
#pragma omp parallel num_threads(comp_threads_count)
{
unsigned tid = omp_get_thread_num();
assert(tid < comp_threads_count);
cpu_set_t cs;
CPU_ZERO(&cs);
CPU_SET(pe->thread2cpu[tid], &cs);
int ret = sched_setaffinity(0, sizeof(cpu_set_t), &cs);
assert(ret == 0);
}
#pragma omp parallel num_threads(comp_threads_count)
{
unsigned tid = omp_get_thread_num();
assert(tid < comp_threads_count);
cpu_set_t cs;
CPU_ZERO(&cs);
int ret=sched_getaffinity(0, sizeof(cpu_set_t), &cs);
if(ret)
{
fprintf(LL_LOG, "Can't get the affinity, %d, %s\n", errno, strerror(errno));
assert(ret == 0);
}
for(unsigned int i = 0; i < CPU_SETSIZE; i++)
if(CPU_ISSET(i, &cs))
assert(i == pe->thread2cpu[tid]);
}
// Args
void** args = (void**)in_args;
struct dll_800_graph* g = (struct dll_800_graph*) args[0];
struct __robincc_buffers* sbuffs = (struct __robincc_buffers*) args[1];
struct __robincc_buffers* rbuffs = (struct __robincc_buffers*) args[2];
unsigned int* cc_ui = NULL;
unsigned long* cc_ul = NULL;
if(g->vertices_count < (1UL<<32))
cc_ui = (unsigned int*)args[3];
else
cc_ul = (unsigned long*)args[3];
unsigned long graph_is_symmetric = (unsigned long)args[4];
unsigned long* total_recv_p = (unsigned long*)args[5];
unsigned long t0 = (unsigned long)args[6];
unsigned long* comp_concluded = (unsigned long*)args[7];
unsigned long* nbsc = (unsigned long*)args[8];
int comm_children_count = (int)(unsigned long)(unsigned long*)args[9];
int* comm_children = (int*)args[10];
unsigned long md_vertex_ID = (unsigned long)args[11];
int comm_parent = (int)(unsigned long)(unsigned long*)args[12];
void** snapshot_p = (void**)args[13];
unsigned long* snapshot_pairs_p = (unsigned long*)args[14];
// args[15];
// args[16];
// args[17];
unsigned long* r_counters = (unsigned long*)args[18];
unsigned int md_rank = (unsigned int)(unsigned long)(unsigned long*)args[19];
unsigned long* steps_info = (unsigned long*)args[20];
// Variables and memory allocation
unsigned int bytes_per_vertex = rbuffs->bytes_per_vertex;
unsigned long partitions_count = g->IP_end_id - g->IP_start_id;
struct ul_dynamic_partitioning* sdp = ul_dynamic_partitioning_initialize(pe, partitions_count);
unsigned long* ttimes = calloc(sizeof(unsigned long), comp_threads_count);
assert(ttimes != NULL);
unsigned char* ZP_nzc = NULL; // Non zero counter
if(comm_parent != -1)
{
ZP_nzc = numa_alloc_interleaved(sizeof(unsigned char) * g->vertices_count);
assert(ZP_nzc != NULL);
#pragma omp parallel for num_threads(comp_threads_count)
for(unsigned long v = 0; v < g->vertices_count; v += 4096)
ZP_nzc[v] = 0;
}
// Traversing edges & processing receieved buffers
unsigned long last_report_timestamp = get_nano_time();
unsigned long mt = - last_report_timestamp;
unsigned long completed_parts = 0;
unsigned long total_zeroed_count = 0;
struct __robincc_block_ID** threads_sbid = calloc(sizeof(struct __robincc_block_ID*), comp_threads_count);
unsigned char** threads_sb_buff = calloc(sizeof(unsigned char*), comp_threads_count);
unsigned long* threads_sb_written_bytes = calloc(sizeof(unsigned long), comp_threads_count);
assert(threads_sbid != NULL && threads_sb_buff != NULL && threads_sb_written_bytes != NULL);
#pragma omp parallel num_threads(comp_threads_count) reduction(+:total_zeroed_count)
{
// Thread vars
unsigned int tid = omp_get_thread_num();
ttimes[tid] = - get_nano_time();
unsigned long zb_partition = -1UL;
unsigned long thread_zc = 0;
struct __robincc_block_ID* rbid = calloc(sizeof(struct __robincc_block_ID), 1);
assert(rbid != NULL);
rbid->group = NULL;
struct __robincc_block_ID* sbid = NULL;
unsigned char* sb_buff = NULL;
unsigned long sb_written_bytes = -1UL;
if(mw_rank != 0)
{
sbid = calloc(sizeof(struct __robincc_block_ID), 1);
assert(sbid != NULL);
sbid->group = NULL;
}
while(1)
{
int doing_nothing = 1;
int op = 0;
// Report status
// if(0)
{
unsigned long rt = get_nano_time();
unsigned long lrt = last_report_timestamp;
if((rt - lrt >= 60e9) && __sync_bool_compare_and_swap(&last_report_timestamp, lrt, rt) )
{
char temp[1024] = {0};
if(rbuffs->processed_40_43_buffers != NULL)
for(int r=0; r<mw_size; r++)
if(rbuffs->processed_40_43_buffers[r])
sprintf(temp+strlen(temp), "R%d: %ld/%lu/%lu, ", r, nbsc[r], r_counters[r], rbuffs->processed_40_43_buffers[r]);
char temp2[1024] = {0};
{
unsigned long total_buffs = 0;
unsigned long null_buffs = 0;
unsigned long incomplete_buffers = 0;
unsigned long accessing_buffers = 0;
struct __robincc_buffer * lb = NULL;
struct __robincc_buffer_group* g = rbuffs->first_group;
while(g != NULL)
{
for(unsigned long bfi = 0; bfi < rbuffs->buffers_per_group; bfi++)
{
total_buffs++;
if(g->requests[bfi] != MPI_REQUEST_NULL)
null_buffs++;
else
{
if(g->buffers[bfi].allocated_count < g->buffers[bfi].effective_blocks_count)
{
incomplete_buffers++;
lb = &g->buffers[bfi];
}
if(g->buffers[bfi].access_count > 0)
accessing_buffers++;
}
}
g = g->next_group;
}
sprintf(temp2, "tb: %lu; nb: %lu; ib: %lu; ab: %lu", total_buffs, null_buffs, incomplete_buffers, accessing_buffers);
if(lb != NULL)
sprintf(temp2 + strlen(temp2), "|%lu,%lu,%lu,%lu,%lu", lb->allocated_count, lb->access_count, lb->sender_rank,
lb->effective_blocks_count, lb->last_block_size);
}
printf(" \033[3;%um R%u,rep@%.1f\033[0;37m, tid:%3u, sdp_r:%lu/%lu, children: %s; buffers: %s\n",
mw_rank + 31, mw_rank, (rt + t0)/1e9, tid,
sdp->partitions_remained,sdp->partitions_count, temp, temp2
);
}
}
// Process own edges
while(completed_parts < partitions_count && op++ < min_paritions_per_iteration)
{
zb_partition = ul_dynamic_partitioning_get_next_partition(sdp, tid, zb_partition);
if(zb_partition == -1UL)
break;
// Processing the partition
{
unsigned long partition = g->IP_start_id + zb_partition;
unsigned long edges_offset =
g->offsets_list[g->partitions_start_vertex_ID[partition] - g->offsets_list_first_vertex_ID];
for(unsigned long v = g->partitions_start_vertex_ID[partition]; v < g->partitions_start_vertex_ID[partition + 1]; v++)
{
unsigned long offset_s = g->offsets_list[v - g->offsets_list_first_vertex_ID];
unsigned long offset_e = g->offsets_list[v + 1 - g->offsets_list_first_vertex_ID];
for(unsigned long e = offset_s; e < offset_e; e++)
{
unsigned long neighbor = g->partition_edges[partition][e - edges_offset];
if(graph_is_symmetric)
if(neighbor >= v)
break;
unsigned long zeroed_val = -1UL;
if(cc_ui != NULL)
{
unsigned int x = v;
unsigned int cc_x;
unsigned int y = neighbor;
unsigned int cc_y;
while(1)
{
cc_x = cc_ui[x];
cc_y = cc_ui[y];
while(cc_x != 0 && cc_x != x + 1)
{
x = cc_ui[x] - 1;
cc_x = cc_ui[x];
}
while(cc_y != 0 && cc_y != y + 1)
{
y = cc_ui[y] - 1;
cc_y = cc_ui[y];
}
if(cc_x == cc_y)
break;
if(cc_x < cc_y)
{
if(__sync_bool_compare_and_swap(&cc_ui[y], cc_y, cc_x))
{
if(cc_x == 0)
zeroed_val = y;
break;
}
}
else
{
if(__sync_bool_compare_and_swap(&cc_ui[x], cc_x, cc_y))
{
if(cc_y == 0)
zeroed_val = x;
break;
}
}
}
}
else
{
unsigned long x = v;
unsigned long cc_x;
unsigned long y = neighbor;
unsigned long cc_y;
while(1)
{
cc_x = cc_ul[x];
cc_y = cc_ul[y];
while(cc_x != 0 && cc_x != x + 1)
{
x = cc_ul[x] - 1;
cc_x = cc_ul[x];
}
while(cc_y != 0 && cc_y != y + 1)
{
y = cc_ul[y] - 1;
cc_y = cc_ul[y];
}
if(cc_x == cc_y)
break;
if(cc_x < cc_y)
{
if(__sync_bool_compare_and_swap(&cc_ul[y], cc_y, cc_x))
{
if(cc_x == 0)
zeroed_val = y;
break;
}
}
else
{
if(__sync_bool_compare_and_swap(&cc_ul[x], cc_x, cc_y))
{
if(cc_y == 0)
zeroed_val = x;
break;
}
}
}
}
// Write the zeroed_val to be sent to the parent
if(zeroed_val != -1UL && sbid != NULL && ZP_nzc != NULL && ZP_nzc[zeroed_val] == 0)
{
ZP_nzc[zeroed_val] = 1;
thread_zc++;
if(sb_buff == NULL || sb_written_bytes == sbid->block_size)
{
sb_buff = __robincc_get_a_block(sbuffs, sbid);
assert(sb_buff != NULL);
sb_written_bytes = 0;
}
unsigned long val = zeroed_val;
for(int b = 0; b < sbuffs->bytes_per_vertex; b++)
{
sb_buff[sb_written_bytes++] = (unsigned char)(val & 255);
val = (val >> 8);
}
}
}
}
doing_nothing = 0;
}
// Update stats
{
unsigned long total = __sync_add_and_fetch(&completed_parts, 1UL);
assert(total <= partitions_count);
if(total == partitions_count)
{
unsigned long gnt = t0 + get_nano_time();
fprintf(LL_LOG, " R%u finished processing own edges, @%.3f seconds.\n",
mw_rank, gnt/1e9);
printf(" R%u finished processing own edges, @%.3f seconds.\n",
mw_rank, gnt/1e9);
steps_info[0] = gnt;
}
}
}
// Process received buffers
while(rbuffs->first_group != NULL)
{
unsigned char* buff = __robincc_get_a_block(rbuffs, rbid);
if(buff == NULL)
break;
assert(rbid->buff != NULL);
if(rbid->buff->recv_type == 40) // snapshot
{
assert(rbid->block_size % (2 * rbuffs->bytes_per_vertex) == 0);
for(unsigned long c = 0; c < rbid->block_size; c += 2 * rbuffs->bytes_per_vertex)
{
unsigned long x = 0;
for(int i = 0; i < rbuffs->bytes_per_vertex; i++)
x += (((unsigned long)buff[c + i]) << (8 * i));
unsigned long y = 0;
for(int i = 0; i < rbuffs->bytes_per_vertex; i++)
y += (((unsigned long)buff[c + rbuffs->bytes_per_vertex + i]) << (8 * i));
assert(x < g->vertices_count);
assert(y < g->vertices_count);
// assert(y != 0);
assert(y != x + 1);
// Converting y, a CC val, to a root vertex
if(y == 0)
y = md_vertex_ID;
else
y--;
unsigned long zeroed_val = -1UL;
if(cc_ui != NULL)
{
unsigned int cc_x;
unsigned int cc_y;
while(1)
{
cc_x = cc_ui[x];
cc_y = cc_ui[y];
while(cc_x != 0 && cc_x != x + 1)
{
x = cc_ui[x] - 1;
cc_x = cc_ui[x];
}
while(cc_y != 0 && cc_y != y + 1)
{
y = cc_ui[y] - 1;
cc_y = cc_ui[y];
}
if(cc_x == cc_y)
break;
if(cc_x < cc_y)
{
if(__sync_bool_compare_and_swap(&cc_ui[y], cc_y, cc_x))
{
if(cc_x == 0)
zeroed_val = y;
break;
}
}
else
{
if(__sync_bool_compare_and_swap(&cc_ui[x], cc_x, cc_y))
{
if(cc_y == 0)
zeroed_val = x;
break;
}
}
}
}
else
{
unsigned long cc_x;
unsigned long cc_y;
while(1)
{
cc_x = cc_ul[x];
cc_y = cc_ul[y];
while(cc_x != 0 && cc_x != x + 1)
{
x = cc_ul[x] - 1;
cc_x = cc_ul[x];
}
while(cc_y != 0 && cc_y != y + 1)
{
y = cc_ul[y] - 1;
cc_y = cc_ul[y];
}
if(cc_x == cc_y)
break;
if(cc_x < cc_y)
{
if(__sync_bool_compare_and_swap(&cc_ul[y], cc_y, cc_x))
{
if(cc_x == 0)
zeroed_val = y;
break;
}
}
else