19 #include <numeric/random/random.hh>
20 #include <basic/Tracer.hh>
22 #include <utility/exit.hh>
24 #include <utility/vector1.hh>
27 static basic::Tracer
TR(
"protocols.ReplicaExchangeMC");
28 static numeric::random::RandomGenerator
re_RG(1801);
34 Pose const & init_pose,
41 nreplica_frequency_(nint),
45 last_energylist(NULL),
60 nreplica_frequency_(nint),
64 last_energylist(NULL),
76 MPI_Comm_rank( MPI_COMM_WORLD, &
rank_ );
77 MPI_Comm_size( MPI_COMM_WORLD, &
size_ );
82 std::cerr <<
"size " <<
size_ <<
" and Tlist-size: " <<
Tlist_.size() <<
" don't match up!" << std::endl;
84 runtime_assert(
size_ == static_cast<int>(
Tlist_.size()));
91 for (
int i=0; i<
size_; i++)
101 TR <<
"I am proc:" <<
rank_ <<
", of all " << size_ <<
" procs!";
108 for (
int i=0; i<size_-1; i+=2)
110 std::pair<int, int> elem(i, i+1);
111 list.push_back(elem);
115 for (
int i=1; i<size_-1; i+=2)
117 std::pair<int, int> elem(i, i+1);
118 list.push_back(elem);
123 TR <<
"Building exchange schedule 1" << std::endl;
128 TR <<
"Building exchange schedule 2" << std::endl;
145 int nlist=(3+flag)/2;
147 TR <<
"Building " << nlist << std::endl;
151 Size node2=
T_rev[exchange_schedule[nlist][i].second];
158 Real probability = 0;
161 if (delta<0) probability = 1.0;
162 else probability = std::exp( std::max(-40.0, -delta) );
163 TR <<
"Try:" <<
Tlist_[exchange_schedule[nlist][i].first+1]
164 <<
" <==> " <<
Tlist_[exchange_schedule[nlist][i].second+1]
168 if (
re_RG.uniform()<probability)
170 TR <<
"Switch:" <<
Tlist_[exchange_schedule[nlist][i].first+1] <<
"<==>" <<
Tlist_[exchange_schedule[nlist][i].second+1] << std::endl;
175 tmp=
T_rev[exchange_schedule[nlist][i].first];
176 T_rev[exchange_schedule[nlist][i].first]=
T_rev[exchange_schedule[nlist][i].second];
177 T_rev[exchange_schedule[nlist][i].second]=tmp;
180 TR <<
"Done" << std::endl;
195 MPI_Barrier(MPI_COMM_WORLD);
201 MPI_Gather(&last_energy_, 1, MPI_DOUBLE,
last_energylist, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
205 MPI_Scatter(
T_tag, 1, MPI_INT, &
T_ndx, 1, MPI_INT, 0, MPI_COMM_WORLD);