1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| #include <stdio.h> #include <stdlib.h> #include "mpi.h"
#define DATALEN 6553600
int main(int argc, char ** argv) { MPI_Status sstatus, rstatus; MPI_Request sreq, rreq; int a[DATALEN], b[DATALEN]; char * buf; int i, j, rank, size, errs = 0; int sflag, rflag, other; int s1, bufsize;
MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Pack_size(DATALEN, MPI_INT, MPI_COMM_WORLD, &s1); bufsize = MPI_BSEND_OVERHEAD + s1; buf = (char *)malloc(bufsize);
MPI_Buffer_attach(buf, bufsize);
if (size != 2) { fprintf(stderr, "number of processes must be 2"); MPI_Finalize(); fflush(stderr); }
if (rank == 0) { other = 1; } else { other = 0; }
sflag = 0; rflag = 0; for (i = 0; i < DATALEN; ++i) { a[i] = (rank + DATALEN*i) + i; }
if (rank == 0) { fprintf(stderr, "proc %d: before ibsend...%f\n", rank, MPI_Wtime()); MPI_Ibsend(a, DATALEN, MPI_INT, other, 111, MPI_COMM_WORLD, &sreq); fprintf(stderr, "proc %d: after ibsend...%f\n", rank, MPI_Wtime());
while (!sflag) { fprintf(stderr, "proc %d: before Ibsend test, sflag = %d...%f\n", rank, sflag, MPI_Wtime()); MPI_Test(&sreq, &sflag, &sstatus); fprintf(stderr, "proc %d: after Ibsend test, sflag = %d...%f\n", rank, sflag, MPI_Wtime()); } }
if (rank == 1) { for (i = 0; i < 9999999; ++i) { MPI_Wtime(); } fprintf(stderr, "proc %d: before Irecv...%f\n", rank, MPI_Wtime()); MPI_Irecv(b, DATALEN, MPI_INT, other, 111, MPI_COMM_WORLD, &rreq); fprintf(stderr, "proc %d: after Irecv...%f\n", rank, MPI_Wtime());
while (!rflag) { fprintf(stderr, "proc %d: before Irecv test, rflag = %d...%f\n", rank, rflag, MPI_Wtime()); MPI_Test(&rreq, &rflag, &rstatus); fprintf(stderr, "proc %d: after Irecv test, rflag = %d...%f\n", rank, rflag, MPI_Wtime()); }
fprintf(stderr, "proc: %d, received ...\n", rank); for (i = 0; i < 2; ++i) { fprintf(stderr, "b[%d]=%d\n", i, b[i]); } }
fprintf(stderr, "proc: %d before Buffer_detach...%f\n", rank, MPI_Wtime()); MPI_Buffer_detach(&buf, &bufsize); fprintf(stderr, "proc: %d after Buffer_detach...%f\n", rank, MPI_Wtime()); free(buf); MPI_Finalize(); return 0; }
|