source: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp @ 1287

Last change on this file since 1287 was 1287, checked in by yushan, 7 years ago

EP updated

File size: 1.9 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(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
19  {
20
21    if(!comm.is_ep)
22    {
23      #pragma omp single nowait
24      ::MPI_Bcast(buffer, count, static_cast< ::MPI_Datatype>(datatype), root, static_cast< ::MPI_Comm>(comm.mpi_comm));
25      return 0;
26    }
27
28
29    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
30    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
31    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
32
33    int root_mpi_rank = comm.rank_map->at(root).second;
34    int root_ep_rank_loc = comm.rank_map->at(root).first;
35
36    // printf("root_mpi_rank = %d\n", root_mpi_rank);   
37
38    if((ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root)
39    {
40      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
41    }
42
43    if(mpi_rank == root_mpi_rank) MPI_Bcast_local(buffer, count, datatype, root_ep_rank_loc, comm);
44    else                          MPI_Bcast_local(buffer, count, datatype, 0, comm);
45
46    return 0;
47  }
48
49
50
51  int MPI_Bcast_local(void *buffer, int count, MPI_Datatype datatype, int local_root, MPI_Comm comm)
52  {
53    assert(valid_type(datatype));
54
55    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
56
57    ::MPI_Aint datasize, lb;
58    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
59   
60
61    if(ep_rank_loc == local_root)
62    {
63      comm.my_buffer->void_buffer[local_root] = buffer;
64    }
65
66//    #pragma omp flush
67    MPI_Barrier_local(comm);
68//    #pragma omp flush
69
70    if(ep_rank_loc != local_root)
71    {
72      #pragma omp critical (_bcast)     
73      memcpy(buffer, comm.my_buffer->void_buffer[local_root], datasize * count);
74    }
75
76    MPI_Barrier_local(comm);
77  }
78
79}
Note: See TracBrowser for help on using the repository browser.