Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ============================================================================
- Name : l12.c
- Author :
- Version :
- Copyright : Your copyright notice
- Description : Calculate Pi in MPI
- ============================================================================
- */
- #include <mpi.h>
- #include <stdio.h>
- #include <string.h>
- int main(int argc, char *argv[])
- {
- int my_rank; /* rank of process */
- int p; /* number of processes */
- int tag = 0; /* tag for messages */
- int message; /* storage for message */
- MPI_Status status ; /* return status for receive */
- int no_neighbors;
- int neighbors[no_neighbors];
- int statut;
- /* start up MPI */
- MPI_Init(&argc, &argv);
- MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
- MPI_Comm_size(MPI_COMM_WORLD, &p);
- int i, max_id;
- int nnodes = 9;
- int runda;
- int index[] = { 4, 6, 9, 12, 15, 18, 21, 25, 28 };
- int edges[] = { 1, 4, 5, 6, 0, 6, 4, 7, 8, 5, 6, 8, 0, 2, 7, 0, 3, 7, 0, 1, 3, 2, 4, 5, 8, 2, 3, 7 };
- int d = 3; //graph diameter
- int reorder = 0;
- MPI_Comm comm_graph;
- MPI_Graph_create(MPI_COMM_WORLD, nnodes, index, edges, reorder,
- &comm_graph);
- /*
- MPI_Graph_neighbors_count(comm_graph, my_rank, &no_neighbors);
- MPI_Graph_neighbors(comm_graph, my_rank, no_neighbors, neighbors);
- int m;
- max_id = my_rank;
- for (runda = 1; runda <= d; runda++) {
- for(m = 0;m< no_neighbors;m++)
- {
- MPI_Send(&max_id, 1, MPI_INT, neighbors[m], 0, comm_graph);
- }
- for (m = 0; m < no_neighbors; m++)
- {
- MPI_Recv(&message, 1, MPI_INT, neighbors[m], 0, comm_graph, &status);
- if (message > max_id)
- max_id = message;
- }
- }
- if(max_id == my_rank)
- statut = 1;
- else
- statut = 0;
- printf("Procesul %d: are statut:%d cu lider:%d\n", my_rank, statut, max_id);
- MPI_Comm_free(&comm_graph);*/
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement