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

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

EP update all

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