Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. #include "test.h"
  2.  
  3. static gex_Client_t myclient;
  4. static gex_EP_t myep;
  5. static gex_TM_t myteam;
  6. static gex_Segment_t mysegment;
  7.  
  8. int myproc;
  9. int numprocs;
  10.  
  11. uint8_t *myseg; /* my segment */
  12. uint8_t *peerseg;
  13.  
  14. uintptr_t maxlongreq, maxlongrep;
  15. uintptr_t maxsz = 32*1024;
  16.  
  17. int peer;
  18. int iters = 1;
  19. size_t req_counter = 0, rep_counter = 0;
  20. int wait_counter = 0;
  21.  
  22. /* Test handlers */
  23. #define hidx_sleep_req_shorthandler 200
  24. #define hidx_sleep_rep_shorthandler 201
  25. #define hidx_done_req_shorthandler 202
  26. #define hidx_flood_req_longhandler 203
  27. #define hidx_flood_rep_longhandler 204
  28.  
  29. void sleep_req_shorthandler(gex_Token_t token, void *buf, size_t nbytes, gex_AM_Arg_t delay) {
  30. //MSG("sleep %d usec", delay);
  31. gex_Token_Info_t info;
  32.  
  33. usleep(delay);
  34. gex_Token_Info(token, &info, GEX_TI_SRCRANK);
  35. uint8_t *peerseg = TEST_SEG(info.gex_srcrank);
  36. gex_AM_ReplyLong0(token, hidx_sleep_rep_shorthandler, buf, nbytes, peerseg,
  37. GEX_EVENT_NOW, 0);
  38. }
  39.  
  40. void sleep_rep_shorthandler(gex_Token_t token, void *buf, size_t nbytes) {
  41. //MSG("rep");
  42. wait_counter++;
  43. }
  44.  
  45. void done_req_shorthandler(gex_Token_t token) {
  46. //MSG("done");
  47. iters = 0;
  48. }
  49.  
  50. void flood_req_longhandler(gex_Token_t token, void *buf, size_t nbytes) {
  51. gex_Token_Info_t info;
  52.  
  53. gex_Token_Info(token, &info, GEX_TI_SRCRANK);
  54. uint8_t *peerseg = TEST_SEG(info.gex_srcrank);
  55. req_counter++;
  56. gex_AM_ReplyLong0(token, hidx_flood_rep_longhandler, buf, nbytes, peerseg,
  57. GEX_EVENT_NOW, 0);
  58. }
  59.  
  60. void flood_rep_longhandler(gex_Token_t token, void *buf, size_t nbytes) {
  61. //MSG("flood_rep_longhandler");
  62. rep_counter++;
  63. }
  64.  
  65. int main(int argc, char **argv)
  66. {
  67. int delay = 1000000;
  68. gex_AM_Entry_t htable[] = {
  69. { hidx_sleep_req_shorthandler, sleep_req_shorthandler, GEX_FLAG_AM_REQREP|GEX_FLAG_AM_LONG, 1, NULL, NULL },
  70. { hidx_sleep_rep_shorthandler, sleep_rep_shorthandler, GEX_FLAG_AM_REQREP|GEX_FLAG_AM_LONG, 0, NULL, NULL },
  71. { hidx_done_req_shorthandler, done_req_shorthandler, GEX_FLAG_AM_REQUEST|GEX_FLAG_AM_SHORT, 0, NULL, NULL },
  72. { hidx_flood_req_longhandler, flood_req_longhandler, GEX_FLAG_AM_REQUEST|GEX_FLAG_AM_LONG, 0, NULL, NULL },
  73. { hidx_flood_rep_longhandler, flood_rep_longhandler, GEX_FLAG_AM_REQREP|GEX_FLAG_AM_LONG, 0, NULL, NULL },
  74. };
  75.  
  76. if (argc > 3) {
  77. fprintf(stderr, "Use:\n%s (iters) (delay)\n", argv[0]);
  78. return 1;
  79. }
  80. if (argc >= 2) {
  81. iters = atoi(argv[1]);
  82. }
  83. if (argc == 3) {
  84. delay = atoi(argv[2]);
  85. }
  86.  
  87. GASNET_Safe(gex_Client_Init(&myclient, &myep, &myteam, "testflood", &argc, &argv, 0));
  88. GASNET_Safe(gex_Segment_Attach(&mysegment, myteam, TEST_SEGSZ_REQUEST));
  89. GASNET_Safe(gex_EP_RegisterHandlers(myep, htable, sizeof(htable)/sizeof(gex_AM_Entry_t)));
  90.  
  91. myproc = gex_TM_QueryRank(myteam);
  92. numprocs = gex_TM_QuerySize(myteam);
  93.  
  94. //maxlongreq = MIN(maxsz, gex_AM_MaxRequestLong (myteam,peer,NULL,0,0));
  95. //maxlongrep = MIN(maxsz, gex_AM_MaxReplyLong (myteam,peer,GEX_EVENT_NOW,0,0));
  96.  
  97. TEST_PRINT_CONDUITINFO();
  98. MSG0("iters=%u, delay=%u (usec)", iters, delay);
  99.  
  100. myseg = TEST_MYSEG();
  101. switch (myproc) {
  102. case 0:
  103. case 1:
  104. peer = myproc ^ 1;
  105. break;
  106. default:
  107. peer = myproc & 1;
  108. break;
  109. }
  110. peerseg = TEST_SEG(peer);
  111. GASNET_Safe(gasnet_barrier(0,GASNET_BARRIERFLAG_UNNAMED));
  112.  
  113. while (iters) {
  114. if (myproc == 0 || myproc == 1) {
  115. iters--;
  116. wait_counter = 0;
  117. }
  118. switch (myproc) {
  119. case 0:
  120. case 1:
  121. //gex_AM_RequestShort1(myteam, peer, hidx_sleep_req_shorthandler, 0, delay);
  122. gex_AM_RequestLong1(myteam, peer, hidx_sleep_req_shorthandler,
  123. myseg, maxsz, peerseg, GEX_EVENT_NOW, 0, delay);
  124.  
  125. while (!wait_counter) {
  126. gasnet_AMPoll();
  127. }
  128. MSG0("%d", iters);
  129. break;
  130. default:
  131. gex_AM_RequestLong0(myteam, peer, hidx_flood_req_longhandler,
  132. myseg, maxsz, peerseg, GEX_EVENT_NOW, 0);
  133. break;
  134. }
  135. gasnet_AMPoll();
  136. }
  137.  
  138. if (myproc == 0) {
  139. for (int i = 2; i < numprocs; i++) {
  140. gex_AM_RequestShort0(myteam, i, hidx_done_req_shorthandler, 0);
  141. }
  142. }
  143.  
  144. GASNET_Safe(gasnet_barrier(0,GASNET_BARRIERFLAG_UNNAMED));
  145.  
  146. MSG("long req/rep %lu/%lu", req_counter, rep_counter);
  147. gasnet_exit(test_errs > 0 ? 1 : 0);
  148.  
  149. return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement