Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning
[simgrid.git] / src / smpi / colls / allreduce-rab2.c
1 #include "colls_private.h"
2 //#include <star-reduction.c>
3
4 // this requires that count >= NP
5 int smpi_coll_tuned_allreduce_rab2(void *sbuff, void *rbuff,
6                                    int count, MPI_Datatype dtype,
7                                    MPI_Op op, MPI_Comm comm)
8 {
9   MPI_Aint s_extent;
10   int i, rank, nprocs;
11   int nbytes, send_size, s_offset, r_offset;
12   void *recv, *send, *tmp;
13   /*
14      #ifdef MPICH2_REDUCTION
15      MPI_User_function * uop = MPIR_Op_table[op % 16 - 1];
16      #else
17      MPI_User_function *uop;
18      struct MPIR_OP *op_ptr;
19      op_ptr = MPIR_ToPointer(op);
20      uop  = op_ptr->op;
21      #endif
22    */
23   rank = smpi_comm_rank(comm);
24   nprocs = smpi_comm_size(comm);
25
26
27   s_extent = smpi_datatype_get_extent(dtype);
28
29   // uneven count
30   if (count % nprocs) {
31     if (count < nprocs)
32       send_size = nprocs;
33     else
34       send_size = (count + nprocs) / nprocs;
35     nbytes = send_size * s_extent;
36
37     send = (void *) xbt_malloc(s_extent * send_size * nprocs);
38     recv = (void *) xbt_malloc(s_extent * send_size * nprocs);
39     tmp = (void *) xbt_malloc(nbytes);
40
41     memcpy(send, sbuff, s_extent * count);
42
43     mpi_coll_alltoall_fun(send, send_size, dtype, recv, send_size, dtype, comm);
44
45     memcpy(tmp, recv, nbytes);
46
47     for (i = 1, s_offset = nbytes; i < nprocs; i++, s_offset = i * nbytes)
48       smpi_op_apply(op, (char *) recv + s_offset, tmp, &send_size, &dtype);
49
50     mpi_coll_allgather_fun(tmp, send_size, dtype, recv, send_size, dtype, comm);
51     memcpy(rbuff, recv, count * s_extent);
52
53     free(recv);
54     free(tmp);
55     free(send);
56   } else {
57     send = sbuff;
58     send_size = count / nprocs;
59     nbytes = send_size * s_extent;
60     r_offset = rank * nbytes;
61
62     recv = (void *) xbt_malloc(s_extent * send_size * nprocs);
63
64     mpi_coll_alltoall_fun(send, send_size, dtype, recv, send_size, dtype, comm);
65
66     memcpy((char *) rbuff + r_offset, recv, nbytes);
67
68     for (i = 1, s_offset = nbytes; i < nprocs; i++, s_offset = i * nbytes)
69       smpi_op_apply(op, (char *) recv + s_offset, (char *) rbuff + r_offset,
70                      &send_size, &dtype);
71
72     mpi_coll_allgather_fun((char *) rbuff + r_offset, send_size, dtype, rbuff, send_size,
73                   dtype, comm);
74     free(recv);
75   }
76
77   return MPI_SUCCESS;
78 }