-/**
- * bcast
- **/
-static void tree_bcast(void *buf, int count, MPI_Datatype datatype,
- MPI_Comm comm, proc_tree_t tree)
-{
- int system_tag = COLL_TAG_BCAST;
- int rank, i;
- MPI_Request *requests;
-
- rank = smpi_comm_rank(comm);
- /* wait for data from my parent in the tree */
- if (!tree->isRoot) {
- XBT_DEBUG("<%d> tree_bcast(): i am not root: recv from %d, tag=%d)",
- rank, tree->parent, system_tag + rank);
- smpi_mpi_recv(buf, count, datatype, tree->parent, system_tag + rank,
- comm, MPI_STATUS_IGNORE);
- }
- requests = xbt_new(MPI_Request, tree->numChildren);
- XBT_DEBUG("<%d> creates %d requests (1 per child)", rank,
- tree->numChildren);
- /* iniates sends to ranks lower in the tree */
- for (i = 0; i < tree->numChildren; i++) {
- if (tree->child[i] == -1) {
- requests[i] = MPI_REQUEST_NULL;
- } else {
- XBT_DEBUG("<%d> send to <%d>, tag=%d", rank, tree->child[i],
- system_tag + tree->child[i]);
- requests[i] =
- smpi_isend_init(buf, count, datatype, tree->child[i],
- system_tag + tree->child[i], comm);
- }
- }
- smpi_mpi_startall(tree->numChildren, requests);
- smpi_mpi_waitall(tree->numChildren, requests, MPI_STATUS_IGNORE);
- xbt_free(requests);
-}
-
-/**
- * anti-bcast
- **/
-static void tree_antibcast(void *buf, int count, MPI_Datatype datatype,
- MPI_Comm comm, proc_tree_t tree)
-{
- int system_tag = COLL_TAG_BCAST;
- int rank, i;
- MPI_Request *requests;
-
- rank = smpi_comm_rank(comm);
- // everyone sends to its parent, except root.
- if (!tree->isRoot) {
- XBT_DEBUG("<%d> tree_antibcast(): i am not root: send to %d, tag=%d)",
- rank, tree->parent, system_tag + rank);
- smpi_mpi_send(buf, count, datatype, tree->parent, system_tag + rank,
- comm);
- }
- //every one receives as many messages as it has children
- requests = xbt_new(MPI_Request, tree->numChildren);
- XBT_DEBUG("<%d> creates %d requests (1 per child)", rank,
- tree->numChildren);
- for (i = 0; i < tree->numChildren; i++) {
- if (tree->child[i] == -1) {
- requests[i] = MPI_REQUEST_NULL;
- } else {
- XBT_DEBUG("<%d> recv from <%d>, tag=%d", rank, tree->child[i],
- system_tag + tree->child[i]);
- requests[i] =
- smpi_irecv_init(buf, count, datatype, tree->child[i],
- system_tag + tree->child[i], comm);
- }
- }
- smpi_mpi_startall(tree->numChildren, requests);
- smpi_mpi_waitall(tree->numChildren, requests, MPI_STATUS_IGNORE);
- xbt_free(requests);
-}
-
-/**
- * bcast with a binary, ternary, or whatever tree ..
- **/
-void nary_tree_bcast(void *buf, int count, MPI_Datatype datatype, int root,
- MPI_Comm comm, int arity)
-{
- proc_tree_t tree = alloc_tree(arity);
- int rank, size;
-
- rank = smpi_comm_rank(comm);
- size = smpi_comm_size(comm);
- build_tree(root, rank, size, &tree);
- tree_bcast(buf, count, datatype, comm, tree);
- free_tree(tree);
-}
-
-/**
- * barrier with a binary, ternary, or whatever tree ..
- **/
-void nary_tree_barrier(MPI_Comm comm, int arity)
-{
- proc_tree_t tree = alloc_tree(arity);
- int rank, size;
- char dummy = '$';
-
- rank = smpi_comm_rank(comm);
- size = smpi_comm_size(comm);
- build_tree(0, rank, size, &tree);
- tree_antibcast(&dummy, 1, MPI_CHAR, comm, tree);
- tree_bcast(&dummy, 1, MPI_CHAR, comm, tree);
- free_tree(tree);
-}