fxt-tool-mpi.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2010 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include "fxt-tool.h"
  17. /* Returns 0 if a barrier is found, -1 otherwise. In case of success, offset is
  18. * filled with the timestamp of the barrier */
  19. int find_sync_point(char *filename_in, uint64_t *offset, int *key, int *rank)
  20. {
  21. STARPU_ASSERT(offset);
  22. /* Open the trace file */
  23. int fd_in;
  24. fd_in = open(filename_in, O_RDONLY);
  25. if (fd_in < 0) {
  26. perror("open failed :");
  27. exit(-1);
  28. }
  29. static fxt_t fut;
  30. fut = fxt_fdopen(fd_in);
  31. if (!fut) {
  32. perror("fxt_fdopen :");
  33. exit(-1);
  34. }
  35. fxt_blockev_t block;
  36. block = fxt_blockev_enter(fut);
  37. struct fxt_ev_64 ev;
  38. int func_ret = -1;
  39. unsigned found = 0;
  40. while(!found) {
  41. int ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  42. if (ret != FXT_EV_OK) {
  43. fprintf(stderr, "no more block ...\n");
  44. break;
  45. }
  46. if (ev.code == FUT_MPI_BARRIER)
  47. {
  48. /* We found the sync point */
  49. *offset = ev.time;
  50. *rank = ev.param[0];
  51. *key = ev.param[2];
  52. found = 1;
  53. func_ret = 0;
  54. }
  55. }
  56. /* Close the trace file */
  57. if (close(fd_in))
  58. {
  59. perror("close failed :");
  60. exit(-1);
  61. }
  62. return func_ret;
  63. }
  64. /*
  65. * Deal with the actual MPI transfers performed with the MPI lib
  66. */
  67. /* the list of MPI transfers found in the different traces */
  68. static struct mpi_transfer *mpi_sends[64] = {NULL};
  69. static struct mpi_transfer *mpi_recvs[64] = {NULL};
  70. /* number of available slots in the lists */
  71. unsigned mpi_sends_list_size[64] = {0};
  72. unsigned mpi_recvs_list_size[64] = {0};
  73. /* number of slots actually used in the list */
  74. unsigned mpi_sends_used[64] = {0};
  75. unsigned mpi_recvs_used[64] = {0};
  76. void add_mpi_send_transfer(int src, int dst, int mpi_tag, size_t size, float date)
  77. {
  78. unsigned slot = mpi_sends_used[src]++;
  79. if (mpi_sends_used[src] > mpi_sends_list_size[src])
  80. {
  81. if (mpi_sends_list_size[src] > 0)
  82. {
  83. mpi_sends_list_size[src] *= 2;
  84. }
  85. else {
  86. mpi_sends_list_size[src] = 1;
  87. }
  88. mpi_sends[src] = realloc(mpi_sends[src], mpi_sends_list_size[src]*sizeof(struct mpi_transfer));
  89. }
  90. mpi_sends[src][slot].matched = 0;
  91. mpi_sends[src][slot].other_rank = dst;
  92. mpi_sends[src][slot].mpi_tag = mpi_tag;
  93. mpi_sends[src][slot].size = size;
  94. mpi_sends[src][slot].date = date;
  95. }
  96. void add_mpi_recv_transfer(int src, int dst, int mpi_tag, float date)
  97. {
  98. unsigned slot = mpi_recvs_used[dst]++;
  99. if (mpi_recvs_used[dst] > mpi_recvs_list_size[dst])
  100. {
  101. if (mpi_recvs_list_size[dst] > 0)
  102. {
  103. mpi_recvs_list_size[dst] *= 2;
  104. }
  105. else {
  106. mpi_recvs_list_size[dst] = 1;
  107. }
  108. mpi_recvs[dst] = realloc(mpi_recvs[dst], mpi_recvs_list_size[dst]*sizeof(struct mpi_transfer));
  109. }
  110. mpi_recvs[dst][slot].matched = 0;
  111. mpi_recvs[dst][slot].other_rank = dst;
  112. mpi_recvs[dst][slot].mpi_tag = mpi_tag;
  113. mpi_recvs[dst][slot].date = date;
  114. }
  115. struct mpi_transfer *try_to_match_send_transfer(int src, int dst, int mpi_tag)
  116. {
  117. unsigned slot;
  118. #warning TODO improve !! this creates a quadratic complexity
  119. for (slot = 0; slot < mpi_recvs_used[dst]; slot++)
  120. {
  121. if (!mpi_recvs[dst][slot].matched)
  122. {
  123. if (mpi_recvs[dst][slot].mpi_tag == mpi_tag)
  124. {
  125. /* we found a match ! */
  126. mpi_recvs[dst][slot].matched = 1;
  127. return &mpi_recvs[dst][slot];
  128. }
  129. }
  130. }
  131. /* If we reached that point, we could not find a match */
  132. return NULL;
  133. }
  134. static unsigned long mpi_com_id = 0;
  135. void display_all_transfers_from_trace(FILE *out_paje_file, int src)
  136. {
  137. unsigned slot;
  138. for (slot = 0; slot < mpi_sends_used[src]; slot++)
  139. {
  140. int dst = mpi_sends[src][slot].other_rank;
  141. int mpi_tag = mpi_sends[src][slot].mpi_tag;
  142. float start_date = mpi_sends[src][slot].date;
  143. size_t size = mpi_sends[src][slot].size;
  144. struct mpi_transfer *match;
  145. match = try_to_match_send_transfer(src, dst, mpi_tag);
  146. if (match)
  147. {
  148. float end_date = match->date;
  149. unsigned long id = mpi_com_id++;
  150. /* TODO replace 0 by a MPI program ? */
  151. fprintf(out_paje_file, "18 %f MPIL MPIroot %d mpi_%d_p mpicom_%ld\n", start_date, size, /* XXX */src, id);
  152. fprintf(out_paje_file, "19 %f MPIL MPIroot %d mpi_%d_p mpicom_%ld\n", end_date, size, /* XXX */dst, id);
  153. }
  154. else
  155. {
  156. fprintf(stderr, "Warning, could not match MPI transfer from %d to %d (tag %x) starting at %f\n",
  157. src, dst, mpi_tag, start_date);
  158. }
  159. }
  160. }