| 1 | void MPI_Send(void *buf, int count, MPI_Datatype datatype,
|
|---|
| 2 | int dest, int tag, MPI_Comm comm) {
|
|---|
| 3 | $atom {
|
|---|
| 4 | int size;
|
|---|
| 5 |
|
|---|
| 6 | switch (datatype) {
|
|---|
| 7 | case MPI_INT:
|
|---|
| 8 | buf = (int*)buf;
|
|---|
| 9 | size = count*sizeof(int);
|
|---|
| 10 | break;
|
|---|
| 11 | case MPI_FLOAT:
|
|---|
| 12 | buf = (float*)buf;
|
|---|
| 13 | size = count*sizeof(float);
|
|---|
| 14 | break;
|
|---|
| 15 | case MPI_DOUBLE:
|
|---|
| 16 | buf = (double*)buf;
|
|---|
| 17 | size = count*sizeof(double);
|
|---|
| 18 | break;
|
|---|
| 19 | case MPI_CHAR:
|
|---|
| 20 | buf = (char*)buf;
|
|---|
| 21 | size = count*sizeof(char);
|
|---|
| 22 | break;
|
|---|
| 23 | default:
|
|---|
| 24 | printf("Unsupported datatype %d\n", datatype);
|
|---|
| 25 | $assert $false;
|
|---|
| 26 | }
|
|---|
| 27 | $message out = $message_pack(rank, dest, tag, buf, size);
|
|---|
| 28 | $comm_enqueue(comm, out);
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | void MPI_Recv(void *buf, int count, MPI_Datatype datatype,
|
|---|
| 33 | int source, int tag, MPI_Comm comm, MPI_Status *status) {
|
|---|
| 34 | $message in = $comm_dequeue(comm, source, rank, tag);
|
|---|
| 35 | $atom {
|
|---|
| 36 | int size;
|
|---|
| 37 |
|
|---|
| 38 | switch (datatype) {
|
|---|
| 39 | case MPI_INT:
|
|---|
| 40 | buf = (int*)buf;
|
|---|
| 41 | size = count*sizeof(int);
|
|---|
| 42 | break;
|
|---|
| 43 | case MPI_FLOAT:
|
|---|
| 44 | buf = (float*)buf;
|
|---|
| 45 | size = count*sizeof(float);
|
|---|
| 46 | break;
|
|---|
| 47 | case MPI_DOUBLE:
|
|---|
| 48 | buf = (double*)buf;
|
|---|
| 49 | size = count*sizeof(double);
|
|---|
| 50 | break;
|
|---|
| 51 | case MPI_CHAR:
|
|---|
| 52 | buf = (char*)buf;
|
|---|
| 53 | size = count*sizeof(char);
|
|---|
| 54 | break;
|
|---|
| 55 | default:
|
|---|
| 56 | printf("Unsupported datatype %d\n", datatype);
|
|---|
| 57 | $assert $false;
|
|---|
| 58 | }
|
|---|
| 59 | $message_unpack(in, buf, size);
|
|---|
| 60 | status->source = in.source;
|
|---|
| 61 | status->tag = in.tag;
|
|---|
| 62 | status->size = in.size;
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | $when (__start);
|
|---|