#define SMPI_RAND_SEED 5
#define MPI_ANY_SOURCE -1
+#define MPI_PROC_NULL -2
#define MPI_ANY_TAG -1
#define MPI_UNDEFINED -1
#define MPI_UNEQUAL 2
#define MPI_CONGRUENT 3
+#define MPI_WTIME_IS_GLOBAL 1
+
typedef ptrdiff_t MPI_Aint;
typedef long long MPI_Offset;
XBT_PUBLIC(int) MPI_Abort(MPI_Comm comm, int errorcode);
XBT_PUBLIC(double) MPI_Wtime(void);
+XBT_PUBLIC(int) MPI_Address(void *location, MPI_Aint *address);
+
+XBT_PUBLIC(int) MPI_Type_free(MPI_Datatype* datatype);
XBT_PUBLIC(int) MPI_Type_size(MPI_Datatype datatype, size_t* size);
XBT_PUBLIC(int) MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint* extent);
+XBT_PUBLIC(int) MPI_Type_extent(MPI_Datatype datatype, MPI_Aint* extent);
XBT_PUBLIC(int) MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp);
XBT_PUBLIC(int) MPI_Type_ub(MPI_Datatype datatype, MPI_Aint* disp);
XBT_PUBLIC(int) MPI_Scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm);
XBT_PUBLIC(int) MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
XBT_PUBLIC(int) MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
+XBT_PUBLIC(int) MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
XBT_PUBLIC(int) MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
XBT_PUBLIC(int) MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm);
XBT_PUBLIC(int) MPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm);
void smpi_mpi_scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm);
void smpi_mpi_reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
void smpi_mpi_allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
+void smpi_mpi_scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
void nary_tree_bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, int arity);
void nary_tree_barrier(MPI_Comm comm, int arity);
xbt_free(requests);
*/
}
+
+void smpi_mpi_scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
+ int system_tag = 666;
+ int rank, size, other, index, datasize;
+ int total;
+ MPI_Request* requests;
+ void** tmpbufs;
+
+ rank = smpi_comm_rank(comm);
+ size = smpi_comm_size(comm);
+ datasize = smpi_datatype_size(datatype);
+ // Local copy from self
+ memcpy(recvbuf, sendbuf, count * datasize * sizeof(char));
+ // Send/Recv buffers to/from others;
+ total = rank + (size - (rank + 1));
+ requests = xbt_new(MPI_Request, total);
+ tmpbufs = xbt_new(void*, rank);
+ index = 0;
+ for(other = 0; other < rank; other++) {
+ tmpbufs[index] = xbt_malloc(count * datasize);
+ requests[index] = smpi_mpi_irecv(tmpbufs[index], count, datatype, other, system_tag, comm);
+ index++;
+ }
+ for(other = rank + 1; other < size; other++) {
+ requests[index] = smpi_mpi_isend(sendbuf, count, datatype, other, system_tag, comm);
+ index++;
+ }
+ // Wait for completion of all comms.
+ for(other = 0; other < total; other++) {
+ index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
+ if(index == MPI_UNDEFINED) {
+ break;
+ }
+ if(index < rank) {
+ // #Request is below rank: it's a irecv
+ smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
+ }
+ }
+ for(index = 0; index < size - 1; index++) {
+ xbt_free(tmpbufs[index]);
+ }
+ xbt_free(tmpbufs);
+ xbt_free(requests);
+}
return time;
}
+int MPI_Address(void *location, MPI_Aint *address) {
+ int retval;
+
+ smpi_bench_end(-1, NULL);
+ if(!address) {
+ retval = MPI_ERR_ARG;
+ } else {
+ *address = (MPI_Aint)location;
+ }
+ smpi_bench_begin(-1, NULL);
+ return retval;
+}
+
+int MPI_Type_free(MPI_Datatype* datatype) {
+ int retval;
+
+ smpi_bench_end(-1, NULL);
+ if(!datatype) {
+ retval = MPI_ERR_ARG;
+ } else {
+ // FIXME: always fail for now
+ retval = MPI_ERR_TYPE;
+ }
+ smpi_bench_begin(-1, NULL);
+ return retval;
+}
+
int MPI_Type_size(MPI_Datatype datatype, size_t* size) {
int retval;
return retval;
}
+int MPI_Type_extent(MPI_Datatype datatype, MPI_Aint* extent) {
+ int retval;
+ MPI_Aint dummy;
+
+ smpi_bench_end(-1, NULL);
+ if(datatype == MPI_DATATYPE_NULL) {
+ retval = MPI_ERR_TYPE;
+ } else if(extent == NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ retval = smpi_datatype_extent(datatype, &dummy, extent);
+ }
+ smpi_bench_begin(-1, NULL);
+ return retval;
+}
+
int MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp) {
int retval;
return retval;
}
+int MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Scan");
+ if(comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else if(datatype == MPI_DATATYPE_NULL) {
+ retval = MPI_ERR_TYPE;
+ } else if(op == MPI_OP_NULL) {
+ retval = MPI_ERR_OP;
+ } else {
+ smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Scan");
+ return retval;
+}
+
int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
int retval, i, size, count;
int* displs;