fxt_tool_mpi.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 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. /* number of slots already matched at the beginning of the list. This permits
  77. * going through the lists from the beginning to match each and every
  78. * transfer, thus avoiding a quadratic complexity. */
  79. unsigned mpi_recvs_matched[64] = {0};
  80. void add_mpi_send_transfer(int src, int dst, int mpi_tag, size_t size, float date)
  81. {
  82. unsigned slot = mpi_sends_used[src]++;
  83. if (mpi_sends_used[src] > mpi_sends_list_size[src])
  84. {
  85. if (mpi_sends_list_size[src] > 0)
  86. {
  87. mpi_sends_list_size[src] *= 2;
  88. }
  89. else {
  90. mpi_sends_list_size[src] = 1;
  91. }
  92. mpi_sends[src] = realloc(mpi_sends[src], mpi_sends_list_size[src]*sizeof(struct mpi_transfer));
  93. }
  94. mpi_sends[src][slot].matched = 0;
  95. mpi_sends[src][slot].other_rank = dst;
  96. mpi_sends[src][slot].mpi_tag = mpi_tag;
  97. mpi_sends[src][slot].size = size;
  98. mpi_sends[src][slot].date = date;
  99. }
  100. void add_mpi_recv_transfer(int src, int dst, int mpi_tag, float date)
  101. {
  102. unsigned slot = mpi_recvs_used[dst]++;
  103. if (mpi_recvs_used[dst] > mpi_recvs_list_size[dst])
  104. {
  105. if (mpi_recvs_list_size[dst] > 0)
  106. {
  107. mpi_recvs_list_size[dst] *= 2;
  108. }
  109. else {
  110. mpi_recvs_list_size[dst] = 1;
  111. }
  112. mpi_recvs[dst] = realloc(mpi_recvs[dst], mpi_recvs_list_size[dst]*sizeof(struct mpi_transfer));
  113. }
  114. mpi_recvs[dst][slot].matched = 0;
  115. mpi_recvs[dst][slot].other_rank = dst;
  116. mpi_recvs[dst][slot].mpi_tag = mpi_tag;
  117. mpi_recvs[dst][slot].date = date;
  118. }
  119. struct mpi_transfer *try_to_match_send_transfer(int src, int dst, int mpi_tag)
  120. {
  121. unsigned slot;
  122. unsigned firstslot = mpi_recvs_matched[dst];
  123. unsigned all_previous_were_matched = 1;
  124. for (slot = firstslot; slot < mpi_recvs_used[dst]; slot++)
  125. {
  126. if (!mpi_recvs[dst][slot].matched)
  127. {
  128. if (mpi_recvs[dst][slot].mpi_tag == mpi_tag)
  129. {
  130. /* we found a match ! */
  131. mpi_recvs[dst][slot].matched = 1;
  132. return &mpi_recvs[dst][slot];
  133. }
  134. all_previous_were_matched = 0;
  135. }
  136. else {
  137. if (all_previous_were_matched)
  138. {
  139. /* All previous transfers are already matched,
  140. * we need not consider them anymore */
  141. mpi_recvs_matched[dst] = slot;
  142. }
  143. }
  144. }
  145. /* If we reached that point, we could not find a match */
  146. return NULL;
  147. }
  148. static unsigned long mpi_com_id = 0;
  149. void display_all_transfers_from_trace(FILE *out_paje_file, int src)
  150. {
  151. unsigned slot;
  152. for (slot = 0; slot < mpi_sends_used[src]; slot++)
  153. {
  154. int dst = mpi_sends[src][slot].other_rank;
  155. int mpi_tag = mpi_sends[src][slot].mpi_tag;
  156. float start_date = mpi_sends[src][slot].date;
  157. size_t size = mpi_sends[src][slot].size;
  158. struct mpi_transfer *match;
  159. match = try_to_match_send_transfer(src, dst, mpi_tag);
  160. if (match)
  161. {
  162. float end_date = match->date;
  163. unsigned long id = mpi_com_id++;
  164. /* TODO replace 0 by a MPI program ? */
  165. fprintf(out_paje_file, "18 %f MPIL MPIroot %d mpi_%d_p mpicom_%ld\n", start_date, size, /* XXX */src, id);
  166. fprintf(out_paje_file, "19 %f MPIL MPIroot %d mpi_%d_p mpicom_%ld\n", end_date, size, /* XXX */dst, id);
  167. }
  168. else
  169. {
  170. fprintf(stderr, "Warning, could not match MPI transfer from %d to %d (tag %x) starting at %f\n",
  171. src, dst, mpi_tag, start_date);
  172. }
  173. }
  174. }