Commit 80e0bb88 authored by pnorbert's avatar pnorbert Committed by GitHub
Browse files

Merge pull request #203 from pnorbert/fix_heatTransfer

fix the left-right/up-down direction in code to make communication co…
parents 3f98f3fe 7857faaa
...@@ -158,16 +158,16 @@ void HeatTransfer::exchange(MPI_Comm comm) ...@@ -158,16 +158,16 @@ void HeatTransfer::exchange(MPI_Comm comm)
MPI_Status status; MPI_Status status;
if (m_s.rank_left >= 0) if (m_s.rank_left >= 0)
{ {
std::cout << "Rank " << m_s.rank << " send left to rank " // std::cout << "Rank " << m_s.rank << " send left to rank "
<< m_s.rank_left << std::endl; // << m_s.rank_left << std::endl;
for (unsigned int i = 0; i < m_s.ndx + 2; ++i) for (unsigned int i = 0; i < m_s.ndx + 2; ++i)
send_x[i] = m_TCurrent[i][1]; send_x[i] = m_TCurrent[i][1];
MPI_Send(send_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_left, tag, comm); MPI_Send(send_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_left, tag, comm);
} }
if (m_s.rank_right >= 0) if (m_s.rank_right >= 0)
{ {
std::cout << "Rank " << m_s.rank << " receive from right from rank " // std::cout << "Rank " << m_s.rank << " receive from right from rank "
<< m_s.rank_right << std::endl; // << m_s.rank_right << std::endl;
MPI_Recv(recv_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_right, tag, comm, MPI_Recv(recv_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_right, tag, comm,
&status); &status);
for (unsigned int i = 0; i < m_s.ndx + 2; ++i) for (unsigned int i = 0; i < m_s.ndx + 2; ++i)
...@@ -178,16 +178,16 @@ void HeatTransfer::exchange(MPI_Comm comm) ...@@ -178,16 +178,16 @@ void HeatTransfer::exchange(MPI_Comm comm)
tag = 2; tag = 2;
if (m_s.rank_right >= 0) if (m_s.rank_right >= 0)
{ {
std::cout << "Rank " << m_s.rank << " send right to rank " // std::cout << "Rank " << m_s.rank << " send right to rank "
<< m_s.rank_right << std::endl; // << m_s.rank_right << std::endl;
for (unsigned int i = 0; i < m_s.ndx + 2; ++i) for (unsigned int i = 0; i < m_s.ndx + 2; ++i)
send_x[i] = m_TCurrent[i][m_s.ndy]; send_x[i] = m_TCurrent[i][m_s.ndy];
MPI_Send(send_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_right, tag, comm); MPI_Send(send_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_right, tag, comm);
} }
if (m_s.rank_left >= 0) if (m_s.rank_left >= 0)
{ {
std::cout << "Rank " << m_s.rank << " receive from left from rank " // std::cout << "Rank " << m_s.rank << " receive from left from rank "
<< m_s.rank_left << std::endl; // << m_s.rank_left << std::endl;
MPI_Recv(recv_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_left, tag, comm, MPI_Recv(recv_x, m_s.ndx + 2, MPI_REAL8, m_s.rank_left, tag, comm,
&status); &status);
for (unsigned int i = 0; i < m_s.ndx + 2; ++i) for (unsigned int i = 0; i < m_s.ndx + 2; ++i)
...@@ -198,15 +198,15 @@ void HeatTransfer::exchange(MPI_Comm comm) ...@@ -198,15 +198,15 @@ void HeatTransfer::exchange(MPI_Comm comm)
tag = 3; tag = 3;
if (m_s.rank_down >= 0) if (m_s.rank_down >= 0)
{ {
std::cout << "Rank " << m_s.rank << " send down to rank " // std::cout << "Rank " << m_s.rank << " send down to rank "
<< m_s.rank_down << std::endl; // << m_s.rank_down << std::endl;
MPI_Send(m_TCurrent[m_s.ndx], m_s.ndy + 2, MPI_REAL8, m_s.rank_down, MPI_Send(m_TCurrent[m_s.ndx], m_s.ndy + 2, MPI_REAL8, m_s.rank_down,
tag, comm); tag, comm);
} }
if (m_s.rank_up >= 0) if (m_s.rank_up >= 0)
{ {
std::cout << "Rank " << m_s.rank << " receive from above from rank " // std::cout << "Rank " << m_s.rank << " receive from above from rank "
<< m_s.rank_up << std::endl; // << m_s.rank_up << std::endl;
MPI_Recv(m_TCurrent[0], m_s.ndy + 2, MPI_REAL8, m_s.rank_up, tag, comm, MPI_Recv(m_TCurrent[0], m_s.ndy + 2, MPI_REAL8, m_s.rank_up, tag, comm,
&status); &status);
} }
...@@ -215,14 +215,15 @@ void HeatTransfer::exchange(MPI_Comm comm) ...@@ -215,14 +215,15 @@ void HeatTransfer::exchange(MPI_Comm comm)
tag = 4; tag = 4;
if (m_s.rank_up >= 0) if (m_s.rank_up >= 0)
{ {
std::cout << "Rank " << m_s.rank << " send up to rank " << m_s.rank_up // std::cout << "Rank " << m_s.rank << " send up to rank " <<
<< std::endl; // m_s.rank_up
// << std::endl;
MPI_Send(m_TCurrent[1], m_s.ndy + 2, MPI_REAL8, m_s.rank_up, tag, comm); MPI_Send(m_TCurrent[1], m_s.ndy + 2, MPI_REAL8, m_s.rank_up, tag, comm);
} }
if (m_s.rank_down >= 0) if (m_s.rank_down >= 0)
{ {
std::cout << "Rank " << m_s.rank << " receive from below from rank " // std::cout << "Rank " << m_s.rank << " receive from below from rank "
<< m_s.rank_down << std::endl; // << m_s.rank_down << std::endl;
MPI_Recv(m_TCurrent[m_s.ndx + 1], m_s.ndy + 2, MPI_REAL8, m_s.rank_down, MPI_Recv(m_TCurrent[m_s.ndx + 1], m_s.ndy + 2, MPI_REAL8, m_s.rank_down,
tag, comm, &status); tag, comm, &status);
} }
......
...@@ -64,22 +64,22 @@ Settings::Settings(int argc, char *argv[], int rank, int nproc) : rank{rank} ...@@ -64,22 +64,22 @@ Settings::Settings(int argc, char *argv[], int rank, int nproc) : rank{rank}
// determine neighbors // determine neighbors
if (posx == 0) if (posx == 0)
rank_left = -1; rank_up = -1;
else else
rank_left = rank - 1; rank_up = rank - 1;
if (posx == npx - 1) if (posx == npx - 1)
rank_right = -1; rank_down = -1;
else else
rank_right = rank + 1; rank_down = rank + 1;
if (posy == 0) if (posy == 0)
rank_up = -1; rank_left = -1;
else else
rank_up = rank - npx; rank_left = rank - npx;
if (posy == npy - 1) if (posy == npy - 1)
rank_down = -1; rank_right = -1;
else else
rank_down = rank + npx; rank_right = rank + npx;
} }
...@@ -63,7 +63,7 @@ int main(int argc, char *argv[]) ...@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
HeatTransfer ht(settings); HeatTransfer ht(settings);
IO io(settings, mpiHeatTransferComm); IO io(settings, mpiHeatTransferComm);
ht.init(true); ht.init(false);
// ht.printT("Initialized T:", mpiHeatTransferComm); // ht.printT("Initialized T:", mpiHeatTransferComm);
ht.heatEdges(); ht.heatEdges();
ht.exchange(mpiHeatTransferComm); ht.exchange(mpiHeatTransferComm);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment