Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. /*
  2. ============================================================================
  3. Name : l12.c
  4. Author :
  5. Version :
  6. Copyright : Your copyright notice
  7. Description : Calculate Pi in MPI
  8. ============================================================================
  9. */
  10. #include <mpi.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. int main(int argc, char *argv[])
  15. {
  16. int my_rank; /* rank of process */
  17. int p; /* number of processes */
  18. int tag = 0; /* tag for messages */
  19. int message; /* storage for message */
  20. MPI_Status status ; /* return status for receive */
  21.  
  22. int no_neighbors;
  23. int neighbors[no_neighbors];
  24. int statut;
  25. /* start up MPI */
  26.  
  27. MPI_Init(&argc, &argv);
  28.  
  29. MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  30.  
  31. MPI_Comm_size(MPI_COMM_WORLD, &p);
  32.  
  33.  
  34. int i, max_id;
  35. int nnodes = 9;
  36. int runda;
  37. int index[] = { 4, 6, 9, 12, 15, 18, 21, 25, 28 };
  38. 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 };
  39. int d = 3; //graph diameter
  40. int reorder = 0;
  41. MPI_Comm comm_graph;
  42. MPI_Graph_create(MPI_COMM_WORLD, nnodes, index, edges, reorder,
  43. &comm_graph);
  44.  
  45. /*
  46. MPI_Graph_neighbors_count(comm_graph, my_rank, &no_neighbors);
  47. MPI_Graph_neighbors(comm_graph, my_rank, no_neighbors, neighbors);
  48.  
  49. int m;
  50. max_id = my_rank;
  51. for (runda = 1; runda <= d; runda++) {
  52. for(m = 0;m< no_neighbors;m++)
  53. {
  54.  
  55. MPI_Send(&max_id, 1, MPI_INT, neighbors[m], 0, comm_graph);
  56. }
  57. for (m = 0; m < no_neighbors; m++)
  58. {
  59. MPI_Recv(&message, 1, MPI_INT, neighbors[m], 0, comm_graph, &status);
  60. if (message > max_id)
  61. max_id = message;
  62. }
  63. }
  64. if(max_id == my_rank)
  65. statut = 1;
  66. else
  67. statut = 0;
  68. printf("Procesul %d: are statut:%d cu lider:%d\n", my_rank, statut, max_id);
  69. MPI_Comm_free(&comm_graph);*/
  70. MPI_Finalize();
  71.  
  72.  
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement