-#include "colls.h"
+/* Copyright (c) 2013-2014. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "colls_private.h"
/*****************************************************************************
int i, src, dst, rank, num_procs;
int mask, relative_rank, curr_size, recv_size, send_size, nbytes;
int scatter_size, left, right, next_src, *recv_counts, *disps;
- int tag = 1, success = 0, failure = 1;
+ int tag = COLL_TAG_BCAST;
- MPI_Comm_rank(comm, &rank);
- MPI_Comm_size(comm, &num_procs);
- MPI_Type_extent(data_type, &extent);
+ rank = smpi_comm_rank(comm);
+ num_procs = smpi_comm_size(comm);
+ extent = smpi_datatype_get_extent(data_type);
nbytes = extent * count;
curr_size = 0; // this process doesn't receive any data
// because of uneven division
else {
- MPI_Recv((char *) buff + relative_rank * scatter_size, recv_size,
+ smpi_mpi_recv((char *) buff + relative_rank * scatter_size, recv_size,
MPI_BYTE, src, tag, comm, &status);
- MPI_Get_count(&status, MPI_BYTE, &curr_size);
+ curr_size = smpi_mpi_get_count(&status, MPI_BYTE);
}
break;
}
dst = rank + mask;
if (dst >= num_procs)
dst -= num_procs;
- MPI_Send((char *) buff + scatter_size * (relative_rank + mask),
+ smpi_mpi_send((char *) buff + scatter_size * (relative_rank + mask),
send_size, MPI_BYTE, dst, tag, comm);
curr_size -= send_size;
}
// done scatter now do allgather
- recv_counts = (int *) malloc(sizeof(int) * num_procs);
- if (!recv_counts) {
- printf("bcast-scatter-LR-allgather:95: cannot allocate memory\n");
- MPI_Finalize();
- exit(failure);
- }
-
- disps = (int *) malloc(sizeof(int) * num_procs);
- if (!disps) {
- printf("bcast-scatter-LR-allgather:103: cannot allocate memory\n");
- MPI_Finalize();
- exit(failure);
- }
+ recv_counts = (int *) xbt_malloc(sizeof(int) * num_procs);
+ disps = (int *) xbt_malloc(sizeof(int) * num_procs);
for (i = 0; i < num_procs; i++) {
recv_counts[i] = nbytes - i * scatter_size;
next_src = left;
for (i = 1; i < num_procs; i++) {
- MPI_Sendrecv((char *) buff + disps[(src - root + num_procs) % num_procs],
+ smpi_mpi_sendrecv((char *) buff + disps[(src - root + num_procs) % num_procs],
recv_counts[(src - root + num_procs) % num_procs],
MPI_BYTE, right, tag,
(char *) buff +
free(recv_counts);
free(disps);
- return success;
+ return MPI_SUCCESS;
}