- int retval = 0;
- smpi_bench_end();
- if (comm == MPI_COMM_NULL) {
- retval= MPI_ERR_COMM;
- }else if (disp_unit <= 0 || size < 0 ){
- retval= MPI_ERR_OTHER;
- }else{
- void* ptr = xbt_malloc(size);
- if(ptr==nullptr)
- return MPI_ERR_NO_MEM;
- *static_cast<void**>(base) = ptr;
- *win = new simgrid::smpi::Win( ptr, size, disp_unit, info, comm,1);
- retval = MPI_SUCCESS;
- }
- smpi_bench_begin();
- return retval;
+ CHECK_COMM(5)
+ CHECK_NEGATIVE(2, MPI_ERR_OTHER, size)
+ CHECK_NEGATIVE(3, MPI_ERR_OTHER, disp_unit)
+ void* ptr = xbt_malloc(size);
+ const SmpiBenchGuard suspend_bench;
+ *static_cast<void**>(base) = ptr;
+ *win = new simgrid::smpi::Win(ptr, size, disp_unit, info, comm, true);
+ return MPI_SUCCESS;
+}
+
+int PMPI_Win_allocate_shared( MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, void *base, MPI_Win *win){
+ CHECK_COMM(5)
+ CHECK_NEGATIVE(2, MPI_ERR_OTHER, size)
+ CHECK_NEGATIVE(3, MPI_ERR_OTHER, disp_unit)
+ void* ptr = nullptr;
+ int rank = comm->rank();
+ if(rank==0){
+ ptr = xbt_malloc(size*comm->size());
+ }
+ const SmpiBenchGuard suspend_bench;
+ simgrid::smpi::colls::bcast(&ptr, sizeof(void*), MPI_BYTE, 0, comm);
+ simgrid::smpi::colls::barrier(comm);
+ *static_cast<void**>(base) = (char*)ptr+rank*size;
+ *win = new simgrid::smpi::Win(ptr, size, disp_unit, info, comm, rank == 0);
+ return MPI_SUCCESS;