source: XIOS/dev/branch_openmp/extern/ep_dev/ep_bcast.cpp @ 1506

Last change on this file since 1506 was 1503, checked in by yushan, 6 years ago

rank_map is passed from vector to map, in order to have more flexibility in comm_split

File size: 1.8 KB
Line 
1/*!
2   \file ep_bcast.cpp
3   \since 2 may 2016
4
5   \brief Definitions of MPI collective function: MPI_Bcast
6 */
7
8#include "ep_lib.hpp"
9#include <mpi.h>
10#include "ep_declaration.hpp"
11#include "ep_mpi.hpp"
12
13using namespace std;
14
15namespace ep_lib
16{
17
18  int MPI_Bcast_local(void *buffer, int count, MPI_Datatype datatype, int local_root, MPI_Comm comm)
19  {
20    assert(valid_type(datatype));
21
22    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
23
24    ::MPI_Aint datasize, lb;
25    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
26   
27
28    if(ep_rank_loc == local_root)
29    {
30      comm->my_buffer->void_buffer[local_root] = buffer;
31    }
32
33    MPI_Barrier_local(comm);
34
35    if(ep_rank_loc != local_root)
36    {
37      #pragma omp critical (_bcast)     
38      memcpy(buffer, comm->my_buffer->void_buffer[local_root], datasize * count);
39    }
40
41    MPI_Barrier_local(comm);
42  }
43
44  int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
45  {
46
47    if(!comm->is_ep)
48    {
49      #pragma omp single nowait
50      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm->mpi_comm));
51      return 0;
52    }
53
54
55    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
56    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
57    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
58
59    int root_mpi_rank = comm->ep_rank_map->at(root).second;
60    int root_ep_rank_loc = comm->ep_rank_map->at(root).first;
61
62
63    if((ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root)
64    {
65      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
66    }
67
68    if(mpi_rank == root_mpi_rank) MPI_Bcast_local(buffer, count, datatype, root_ep_rank_loc, comm);
69    else                          MPI_Bcast_local(buffer, count, datatype, 0, comm);
70
71    return 0;
72  }
73
74
75
76
77
78}
Note: See TracBrowser for help on using the repository browser.