1 /* Copyright (c) 2013-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
9 * University Research and Technology
10 * Corporation. All rights reserved.
11 * Copyright (c) 2004-2009 The University of Tennessee and The University
12 * of Tennessee Research Foundation. All rights
14 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
15 * University of Stuttgart. All rights reserved.
16 * Copyright (c) 2004-2005 The Regents of the University of California.
17 * All rights reserved.
19 * Additional copyrights may follow
21 /* -*- Mode: C; c-basic-offset:4 ; -*- */
22 /* Copyright (c) 2001-2014, The Ohio State University. All rights
25 * This file is part of the MVAPICH2 software package developed by the
26 * team members of The Ohio State University's Network-Based Computing
27 * Laboratory (NBCL), headed by Professor Dhabaleswar K. (DK) Panda.
29 * For detailed copyright and licensing information, please refer to the
30 * copyright file COPYRIGHT in the top level MVAPICH2 directory.
34 * (C) 2001 by Argonne National Laboratory.
35 * See COPYRIGHT in top-level directory.
38 #include "colls_private.h"
40 #define MPIR_Allreduce_pt2pt_rd_MV2 smpi_coll_tuned_allreduce_rdb
41 #define MPIR_Allreduce_pt2pt_rs_MV2 smpi_coll_tuned_allreduce_mvapich2_rs
43 extern int (*MV2_Allreduce_function)(void *sendbuf,
46 MPI_Datatype datatype,
47 MPI_Op op, MPI_Comm comm);
50 extern int (*MV2_Allreduce_intra_function)( void *sendbuf,
53 MPI_Datatype datatype,
54 MPI_Op op, MPI_Comm comm);
56 static int MPIR_Allreduce_reduce_p2p_MV2( void *sendbuf,
59 MPI_Datatype datatype,
60 MPI_Op op, MPI_Comm comm)
62 mpi_coll_reduce_fun(sendbuf,recvbuf,count,datatype,op,0,comm);
66 static int MPIR_Allreduce_reduce_shmem_MV2( void *sendbuf,
69 MPI_Datatype datatype,
70 MPI_Op op, MPI_Comm comm)
72 mpi_coll_reduce_fun(sendbuf,recvbuf,count,datatype,op,0,comm);
77 /* general two level allreduce helper function */
78 int smpi_coll_tuned_allreduce_mvapich2_two_level(void *sendbuf,
81 MPI_Datatype datatype,
82 MPI_Op op, MPI_Comm comm)
84 int mpi_errno = MPI_SUCCESS;
86 MPI_Aint true_lb, true_extent;
87 MPI_Comm shmem_comm = MPI_COMM_NULL, leader_comm = MPI_COMM_NULL;
88 int local_rank = -1, local_size = 0;
90 //if not set (use of the algo directly, without mvapich2 selector)
91 if(MV2_Allreduce_intra_function==NULL)
92 MV2_Allreduce_intra_function = smpi_coll_tuned_allreduce_mpich;
93 if(MV2_Allreduce_function==NULL)
94 MV2_Allreduce_function = smpi_coll_tuned_allreduce_rdb;
96 if(smpi_comm_get_leaders_comm(comm)==MPI_COMM_NULL){
97 smpi_comm_init_smp(comm);
103 smpi_datatype_extent(datatype, &true_lb,
106 total_size = smpi_comm_size(comm);
107 shmem_comm = smpi_comm_get_intra_comm(comm);
108 local_rank = smpi_comm_rank(shmem_comm);
109 local_size = smpi_comm_size(shmem_comm);
111 leader_comm = smpi_comm_get_leaders_comm(comm);
113 if (local_rank == 0) {
114 if (sendbuf != MPI_IN_PLACE) {
115 smpi_datatype_copy(sendbuf, count, datatype, recvbuf,
120 /* Doing the shared memory gather and reduction by the leader */
121 if (local_rank == 0) {
122 if ((MV2_Allreduce_intra_function == &MPIR_Allreduce_reduce_shmem_MV2) ||
123 (MV2_Allreduce_intra_function == &MPIR_Allreduce_reduce_p2p_MV2) ) {
125 MV2_Allreduce_intra_function(sendbuf, recvbuf, count, datatype,
130 MV2_Allreduce_intra_function(sendbuf, recvbuf, count, datatype,
134 if (local_size != total_size) {
135 void* sendtmpbuf = (char *)smpi_get_tmp_sendbuffer(count*smpi_datatype_get_extent(datatype));
136 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
137 /* inter-node allreduce */
138 if(MV2_Allreduce_function == &MPIR_Allreduce_pt2pt_rd_MV2){
140 MPIR_Allreduce_pt2pt_rd_MV2(sendtmpbuf, recvbuf, count, datatype, op,
144 MPIR_Allreduce_pt2pt_rs_MV2(sendtmpbuf, recvbuf, count, datatype, op,
147 smpi_free_tmp_buffer(sendtmpbuf);
150 /* insert the first reduce here */
151 if ((MV2_Allreduce_intra_function == &MPIR_Allreduce_reduce_shmem_MV2) ||
152 (MV2_Allreduce_intra_function == &MPIR_Allreduce_reduce_p2p_MV2) ) {
154 MV2_Allreduce_intra_function(sendbuf, recvbuf, count, datatype,
159 MV2_Allreduce_intra_function(sendbuf, recvbuf, count, datatype,
164 /* Broadcasting the mesage from leader to the rest */
165 /* Note: shared memory broadcast could improve the performance */
166 mpi_errno = mpi_coll_bcast_fun(recvbuf, count, datatype, 0, shmem_comm);