Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to split the data structures that represent the graph evenly across the processes using MPI. And update the result I have brought my

image text in transcribed

I want to split the data structures that represent the graph evenly across the processes using MPI. And update the result

image text in transcribed

I have brought my code up to this point. However I am having problem to update the result array for each processes to make sure that they have relevant information

This is what I am trying to solve.

In this part, you will have to split the graph vertices. This might seem trivial at first, but since every vertices neighbor might be assigned to a different process, communication is required. To implement it, you have to split the data structures that represent the graph evenly across the processes. However, you would still need a set of variables or a data structure that will be shared across the processes to make sure each of them has relevant and updated information about the already visited nodes and their corresponding depths.

NM no 4 8 1 int mpi_vertex_dist(graph_t *graph, int start vertex, int *result) 2{ 3 int num_vertices = graph ->num_vertices; fill_n(result, num_vertices, MAX_DIST); 5 6 auto start_time = Time:: now(); 7 int depth = 0; 9 result[start_vertex] = depth; 10 11 int keep going = true; 12 13 while (keep going) 14 { 15 keep going = false; 16 17 for (int vertex 0; vertex v_adj_begin[vertex]; na graph->v_adj_begin[vertex] + graph->v_adj_length[vertex]; 22 n++) 23 { 24 int neighbor = graph->v_adj_list[n]; 25 26 if (result[neighbor] > depth+1) 27 { 28 result[neighbor] = depth+1; 29 keep going = true; 30 au 21 NNN N NNN mm } 31 } } 32 33 34 } 35 depth++; mmm } 36 37 38 39 //print_result(graph, result, depth); return std::chrono:: duration_cast us>(Time:: now()-start_time).count(); 40 } NM 00 1 int mpi_vertex_dist(graph_t *graph, int start_vertex, int *result) 2{ 3 4 // Init MPI 5 MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); 6 MPI_Comm_size(MPI_COMM_WORLD, &num_proc); 7 8 int num_vertices = graph->num_vertices; 9 fill_n(result, num_vertices, MAX_DIST); 10 11 auto start_time = Time:: now(); 12 13 int depth = 0; 14 result[start_vertex] depth; 15 16 int keep going = true; 17 18 while (keep going) 19 { 20 keep going = false; 21 22 for (int vertex = 0; vertex v_adj_begin[vertex]; 28 n v_adj_begin[vertex] + graph ->v_adj_length[vertex]; 29 n++) 30 { int neighbor = graph->v_adj_list[n]; 32 if (result[neighbor] > depth+1) 34 { result[neighbor ] = depth+1; 36 keep going = true; 37 } 38 } 39 40 } 41 42 depth++; 43 } 44 45 //print_result(graph, result, depth); 46 return std::chrono:: duration_cast us>(Time:: now()-start_time).count(); 47 } 27 31 OOO OUAWNO 00 OWN 33 35 NM no 4 8 1 int mpi_vertex_dist(graph_t *graph, int start vertex, int *result) 2{ 3 int num_vertices = graph ->num_vertices; fill_n(result, num_vertices, MAX_DIST); 5 6 auto start_time = Time:: now(); 7 int depth = 0; 9 result[start_vertex] = depth; 10 11 int keep going = true; 12 13 while (keep going) 14 { 15 keep going = false; 16 17 for (int vertex 0; vertex v_adj_begin[vertex]; na graph->v_adj_begin[vertex] + graph->v_adj_length[vertex]; 22 n++) 23 { 24 int neighbor = graph->v_adj_list[n]; 25 26 if (result[neighbor] > depth+1) 27 { 28 result[neighbor] = depth+1; 29 keep going = true; 30 au 21 NNN N NNN mm } 31 } } 32 33 34 } 35 depth++; mmm } 36 37 38 39 //print_result(graph, result, depth); return std::chrono:: duration_cast us>(Time:: now()-start_time).count(); 40 } NM 00 1 int mpi_vertex_dist(graph_t *graph, int start_vertex, int *result) 2{ 3 4 // Init MPI 5 MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); 6 MPI_Comm_size(MPI_COMM_WORLD, &num_proc); 7 8 int num_vertices = graph->num_vertices; 9 fill_n(result, num_vertices, MAX_DIST); 10 11 auto start_time = Time:: now(); 12 13 int depth = 0; 14 result[start_vertex] depth; 15 16 int keep going = true; 17 18 while (keep going) 19 { 20 keep going = false; 21 22 for (int vertex = 0; vertex v_adj_begin[vertex]; 28 n v_adj_begin[vertex] + graph ->v_adj_length[vertex]; 29 n++) 30 { int neighbor = graph->v_adj_list[n]; 32 if (result[neighbor] > depth+1) 34 { result[neighbor ] = depth+1; 36 keep going = true; 37 } 38 } 39 40 } 41 42 depth++; 43 } 44 45 //print_result(graph, result, depth); 46 return std::chrono:: duration_cast us>(Time:: now()-start_time).count(); 47 } 27 31 OOO OUAWNO 00 OWN 33 35

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago