93 {
94 using namespace G4mpi;
95 unsigned int worldSize = 10;
96 if ( argc > 1 ) worldSize = atoi(argv[1]);
97 unsigned int myRank = worldSize-1;
98 if ( argc > 2 ) myRank = atoi(argv[2]);
99 std::cout<<"World size: "<<worldSize<<std::endl;
100
101 assert( myRank < worldSize);
102
103 auto MPI_Receive = [](
const rank_t& s,
const rank_t& r) {
104 std::cout<<"MPI_Receive from: "<<s<<" to "<<r<<std::endl;
105 return 0;
106 };
108 std::cout<<"MPI_Send from: "<<s<<" to "<<r<<std::endl;;
109 return 0;
110 };
111 auto MPI_Barrier = [] {
112 std::cout<<"MPI_Barrier"<<std::endl;
113 return 0;
114 };
115
116
117 std::vector<rank_t> ranks(worldSize);
118 for ( unsigned int i = 0 ; i<worldSize ; ++i ) {
119 if ( i != 2 )
120 { ranks.push_back(i);
121 } else {
122 ranks.push_back(i);
123 ranks.push_back(i);
124 }
125 }
126
127 ranks.erase( std::unique(ranks.begin(),ranks.end()),ranks.end());
128
129
130 if ( ranks.size() == 1 ) {
131 std::cout<<"only one rank, nothing to do"<<std::endl;
132 return 0;
133 }
135 assert( ranks.size() == 1 && ranks[0] == 0 );
136
137 std::cout<<"Communiction Map (size: "<<comms.size()<<"):"<<std::endl;
138 for ( const auto& x : comms ) {
139 std::cout<<"Cycle "<<x.first<<": ";
140 for ( const auto& y : x.second ) {
141 std::cout<<y.first<<"->"<<y.second<<", ";
142 }
143 std::cout<<std::endl;
144 }
145
146 std::cout<<"Simulate communication pattern for rank: "<<myRank<<std::endl;
147 for (const auto& x: comms ) {
148 std::cout<<"Cycle "<<x.first<<std::endl;
149 for ( const auto& y : x.second ) {
150 if ( myRank == y.first ) { MPI_Send(y.first,y.second); }
151 else if ( myRank == y.second ) { MPI_Receive(y.first,y.second); }
152 }
153
154
155
156 MPI_Barrier();
157 }
158 return 0;
159}
commMap_t buildCommunicationMap(std::vector< rank_t > &input)