GADGET-4
hypercube_allgatherv.cc
Go to the documentation of this file.
1 /*******************************************************************************
2  * \copyright This file is part of the GADGET4 N-body/SPH code developed
3  * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4  * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5  *******************************************************************************/
6 
12 #include "gadgetconfig.h"
13 
14 #include <math.h>
15 #include <mpi.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 
20 #include "../data/allvars.h"
21 #include "../data/dtypes.h"
22 
23 #ifdef MPI_HYPERCUBE_ALLGATHERV
24 
25 #define TAG 100
26 
27 int MPI_hypercube_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcount, int *displs,
28  MPI_Datatype recvtype, MPI_Comm comm)
29 {
30  int ntask, thistask, ptask, ngrp, size_sendtype, size_recvtype;
31  MPI_Status status;
32 
33  MPI_Comm_rank(comm, &thistask);
34  MPI_Comm_size(comm, &ntask);
35 
36  MPI_Type_size(sendtype, &size_sendtype);
37  MPI_Type_size(recvtype, &size_recvtype);
38 
39  for(ptask = 0; ntask > (1 << ptask); ptask++)
40  ;
41 
42  for(ngrp = 1; ngrp < (1 << ptask); ngrp++)
43  {
44  int recvtask = thistask ^ ngrp;
45 
46  if(recvtask < ntask)
47  MPI_Sendrecv(sendbuf, sendcount, sendtype, recvtask, TAG, (char *)recvbuf + displs[recvtask] * size_recvtype,
48  recvcount[recvtask], recvtype, recvtask, TAG, comm, &status);
49  }
50 
51  if((char *)sendbuf != (char *)recvbuf + displs[thistask] * size_recvtype)
52  memcpy((char *)recvbuf + displs[thistask] * size_recvtype, sendbuf, sendcount * size_sendtype);
53 
54  return 0;
55 }
56 
57 #endif
int MPI_hypercube_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcount, int *displs, MPI_Datatype recvtype, MPI_Comm comm)