| [8a9124e] | 1 | #ifdef __MPI__
|
|---|
| 2 | #else
|
|---|
| 3 | #include<mpi-common.h>
|
|---|
| 4 | #include<civlc.h>
|
|---|
| 5 | #define __MPI__
|
|---|
| 6 |
|
|---|
| 7 | int sizeofDatatype(MPI_Datatype datatype) {
|
|---|
| 8 | switch (datatype) {
|
|---|
| 9 | case MPI_INT:
|
|---|
| 10 | return sizeof(int);
|
|---|
| 11 | case MPI_FLOAT:
|
|---|
| 12 | return sizeof(float);
|
|---|
| 13 | case MPI_DOUBLE:
|
|---|
| 14 | return sizeof(double);
|
|---|
| 15 | case MPI_CHAR:
|
|---|
| 16 | return sizeof(char);
|
|---|
| 17 | default:
|
|---|
| 18 | $assert(0, "Unreachable");
|
|---|
| 19 | }
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | int __MPI_Init() {
|
|---|
| 23 | return 0;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | int MPI_Finalize() {
|
|---|
| 27 | return 0;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | int MPI_Comm_size(MPI_Comm comm, int *size) {
|
|---|
| 31 | *size = $comm_size(comm);
|
|---|
| 32 | return 0;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | int MPI_Comm_rank(MPI_Comm comm, int *rank) {
|
|---|
| 36 | *rank = $comm_place(comm);
|
|---|
| 37 | return 0;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest,
|
|---|
| 41 | int tag, MPI_Comm comm) {
|
|---|
| 42 | if (dest >= 0) {
|
|---|
| 43 | int size = count*sizeofDatatype(datatype);
|
|---|
| 44 | int place = $comm_place(comm);
|
|---|
| 45 | $message out = $message_pack(place, dest, tag, buf, size);
|
|---|
| 46 |
|
|---|
| 47 | $comm_enqueue(comm, out);
|
|---|
| 48 | }
|
|---|
| 49 | return 0;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
|
|---|
| 53 | int tag, MPI_Comm comm, MPI_Status *status) {
|
|---|
| 54 | if (source >= 0) {
|
|---|
| 55 | $message in = $comm_dequeue(comm, source, tag);
|
|---|
| 56 | int size = count*sizeofDatatype(datatype);
|
|---|
| 57 |
|
|---|
| 58 | $message_unpack(in, buf, size);
|
|---|
| 59 | if (status != MPI_STATUS_IGNORE) {
|
|---|
| 60 | status->size = $message_size(in);
|
|---|
| 61 | status->MPI_SOURCE = $message_source(in);
|
|---|
| 62 | status->MPI_TAG = $message_tag(in);
|
|---|
| 63 | status->MPI_ERROR = 0;
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | return 0;
|
|---|
| 67 | }
|
|---|
| 68 | #endif
|
|---|