| 1 |
|
|---|
| 2 | int MPI_Comm_size(MPI_Comm comm, int *size) {
|
|---|
| 3 | *size = $comm_size(comm);
|
|---|
| 4 | return 0;
|
|---|
| 5 | }
|
|---|
| 6 |
|
|---|
| 7 | int MPI_Comm_rank(MPI_Comm comm, int* rank) {
|
|---|
| 8 | // this only works for MPI_COMM_WORLD.
|
|---|
| 9 | // for multiple communicators, you will need
|
|---|
| 10 | // a map (array) from PID to rank for each comm
|
|---|
| 11 | *rank = comm->place;
|
|---|
| 12 | return 0;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | int MPI_Send(void *buf, int count, MPI_Datatype datatype,
|
|---|
| 16 | int dest, int tag, MPI_Comm comm) {
|
|---|
| 17 | //$atom {
|
|---|
| 18 | int size;
|
|---|
| 19 |
|
|---|
| 20 | switch (datatype) {
|
|---|
| 21 | case MPI_INT:
|
|---|
| 22 | buf = (int*)buf;
|
|---|
| 23 | size = count*sizeof(int);
|
|---|
| 24 | break;
|
|---|
| 25 | case MPI_FLOAT:
|
|---|
| 26 | buf = (float*)buf;
|
|---|
| 27 | size = count*sizeof(float);
|
|---|
| 28 | break;
|
|---|
| 29 | case MPI_DOUBLE:
|
|---|
| 30 | buf = (double*)buf;
|
|---|
| 31 | size = count*sizeof(double);
|
|---|
| 32 | break;
|
|---|
| 33 | case MPI_CHAR:
|
|---|
| 34 | buf = (char*)buf;
|
|---|
| 35 | size = count*sizeof(char);
|
|---|
| 36 | break;
|
|---|
| 37 | default:
|
|---|
| 38 | printf("Unsupported datatype %d\n", datatype);
|
|---|
| 39 | $assert($false);
|
|---|
| 40 | }
|
|---|
| 41 | $message out = $message_pack(__rank, dest, tag, buf, size);
|
|---|
| 42 | $comm_enqueue(comm, out);
|
|---|
| 43 | //}
|
|---|
| 44 | return 0;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | int MPI_Recv(void *buf, int count, MPI_Datatype datatype,
|
|---|
| 48 | int source, int tag, MPI_Comm comm, MPI_Status *status) {
|
|---|
| 49 | $message in = $comm_dequeue(comm, source, tag);
|
|---|
| 50 | //$atom {
|
|---|
| 51 | int size;
|
|---|
| 52 |
|
|---|
| 53 | switch (datatype) {
|
|---|
| 54 | case MPI_INT:
|
|---|
| 55 | buf = (int*)buf;
|
|---|
| 56 | size = count*sizeof(int);
|
|---|
| 57 | break;
|
|---|
| 58 | case MPI_FLOAT:
|
|---|
| 59 | buf = (float*)buf;
|
|---|
| 60 | size = count*sizeof(float);
|
|---|
| 61 | break;
|
|---|
| 62 | case MPI_DOUBLE:
|
|---|
| 63 | buf = (double*)buf;
|
|---|
| 64 | size = count*sizeof(double);
|
|---|
| 65 | break;
|
|---|
| 66 | case MPI_CHAR:
|
|---|
| 67 | buf = (char*)buf;
|
|---|
| 68 | size = count*sizeof(char);
|
|---|
| 69 | break;
|
|---|
| 70 | default:
|
|---|
| 71 | printf("Unsupported datatype %d\n", datatype);
|
|---|
| 72 | $assert($false);
|
|---|
| 73 | }
|
|---|
| 74 | $message_unpack(in, buf, size);
|
|---|
| 75 | if (status != MPI_STATUS_IGNORE) {
|
|---|
| 76 | status->MPI_SOURCE = in.source;
|
|---|
| 77 | status->MPI_TAG = in.tag;
|
|---|
| 78 | status->size = in.size;
|
|---|
| 79 | }
|
|---|
| 80 | //}
|
|---|
| 81 | return 0;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | $when (__start);
|
|---|