Using an Array: #include <stdio.h> #include <mpi.h> int main(int argc, char** argv) { int rank, size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); // Define topology int topology[5][2] = {{1, 4}, {0, 2, 3}, {1,-1}, {0, 4}, {0, 3}}; // Initialize index and edge arrays int index[5] = {0}; int edges[5][3] = {{0}}; // Add edges into index array int i =0; int j =0; for (i = 0; i < 5; i++) { index[i] = sizeof(topology[i]) / sizeof(int); for (j = 0; j < index[i]; j++) { edges[i][j] = topology[i][j]; } } // Display topology for each process for (i = 0; i < size; i++) { if (rank == i) { printf("Process %d has %d neighbors: ", i, index[i]); for (j = 0; j < index[i]; j++) { printf("%d ", edges[i][j]); } printf("n"); } MPI_Barrier(MPI_COMM_WORLD); } MPI_Finalize(); return 0; } MPI Functions: #include <mpi.h> #include <stdio.h> int main(int argc, char** argv) { int rank, size; MPI_Init(&argc, &argv); // Initialize MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get the rank of the current process MPI_Comm_size(MPI_COMM_WORLD, &size); // Get the total number of processes int nnodes = 5; // Number of nodes in the topology int nedges = 8; // Number of edges in the topolofy // Index of the first edge for each node int index[5] = {2, 5, 6, 8, 9}; int edges[9] = {4, 1, 0, 2, 3, 1, 4, 0, 3}; // List of all edges MPI_Comm graph_comm; // Create a new communicator for the graph topology MPI_Graph_create(MPI_COMM_WORLD, nnodes, index, edges, 0, &graph_comm); // Create the graph topology int count; // Number of neighbors int* neighbors; // Neighbor Ranks MPI_Graph_neighbors_count(graph_comm, rank, &count); // Get the number of neighbors for the current process neighbors = (int*) malloc(count * sizeof(int)); // Allocate memory for the array of neighbor ranks MPI_Graph_neighbors(graph_comm, rank, count, neighbors); // Get the neighbor ranks for the current process // Display process and the node in the topologies neighbors printf("Process %d has %d neighbors:", rank, count); int i; for (i = 0; i < count; i++) { printf(" %d", neighbors[i]); // Print the neighbor ranks } printf("n"); MPI_Finalize(); return 0; } ive provided my own code above in case that helps or makes it easier on you guys. My output isnt quite right ive been at it for a while if someone could fix the output and explain it to me id be very happy :) 4. Use Graph topology to create following one. Once you create your topology, use one process (e.g., process 0 ) to display the number of neighbors and its neighbors at each node (i.e., process). Use following two methods to check your topology. (20 points) i) Use two arrays, index and edges, to display number of neighbors and its neighbors for each node. ii) Use two functions in MPI, "MPI Graph neighbors count" and "MPI Graph neighbors". llinn@scholar-fe06: /470 $ mpirun -n 5 ./hmwk5q4-b Process 0 has 2 neighbors: 41 Process 1 has 3 neighbors: 023 Process 2 has 1 neighbors: 1 Process 3 has 2 neighbors: 40.