-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cc
More file actions
107 lines (92 loc) · 3.28 KB
/
test.cc
File metadata and controls
107 lines (92 loc) · 3.28 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
// to compile: mpic++ -std=c++11 test.cc rand_gen.cc
// run example: mpirun --bind-to core -np 8 /gpfs/u/home/PCPF/PCPFrttn/scratch/proj/self/a.out
#include "EdgeInfo.h"
#include "generateRR.h"
#include "parsefile.h"
#include "clockcycle.h"
#include <mpi.h>
#include <iostream>
void populate_graph(graph &mygraph,
int num_node_per_rank,
int num_in_neighbor,
int num_out_neighbor,
int world_size,
int myrank)
{
NumberType max_id = world_size * num_node_per_rank;
for (int i = 0; i < num_node_per_rank; i++) {
std::vector<EdgeType> neighbor_vector;
NumberType current_id = i * world_size + myrank;
// add neighbor from remote graph
for (int k = 0; k < num_out_neighbor; k++) {
NumberType neighbor_id = (current_id + k + 1) % max_id;
while ((neighbor_id - myrank) % world_size == 0) {
neighbor_id++;
if (neighbor_id >= max_id )
{
neighbor_id = neighbor_id % max_id;
}
}
neighbor_vector.push_back({neighbor_id,1.0});
}
// add neighbor from local graph
for (int j = 0; j < num_in_neighbor; j++) {
neighbor_vector.push_back({(current_id + (j + 1) * world_size) % max_id,1.0});
}
mygraph.adj_vector.push_back(neighbor_vector);
}
}
void populate_graph(graph &mygraph, const char* fileName)
{
mygraph.adj_vector = readFile(fileName);
}
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get my rank id
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
graph mygraph;
// mygraph.nodes.push_back(rank);
// mygraph.nodes.push_back(world_size + rank);
// mygraph.nodes.push_back(2 * world_size + rank);
// mygraph.nodes.push_back(3 * world_size + rank);
#ifdef GENERATEGRAPH
populate_graph(mygraph,
5,
3,
2,
world_size,
rank
);
#else
ticks startIOTimer = clock_now();
populate_graph(mygraph,"edges_huge.txt");
ticks endIOTimer = clock_now();
#endif
std::cout << "Rank " << rank << " of " << world_size << " have graph of: ";
for (int i = 0; i < mygraph.size(); i++)
{
std::cout << id_local_to_global(i, world_size, rank) << " ";
}
std::cout << "\n";
std::cout << "with adjacency matrix\n";
for (const auto& row : mygraph.adj_vector) {
for (const auto& elem : row) {
std::cout << elem << " ";
}
std::cout << std::endl;
}
ticks startGenRRTimer = clock_now();
generate_RR(mygraph, 2, rank, world_size, false);
ticks endGenRRTimer = clock_now();
MPI_Finalize();
if (rank == 0)
{
std::cout << "Elapsed time (Reading in data) = " << getElapsedSeconds(startIOTimer, endIOTimer) << " seconds\n";
std::cout << "Elapsed time (Generating RRR sets) = " << getElapsedSeconds(startGenRRTimer, endGenRRTimer) << " seconds\n";
}
return 0;
}