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