Skip to content

Commit

Permalink
Fixes 2
Browse files Browse the repository at this point in the history
  • Loading branch information
At0mn1yIvan committed Nov 30, 2023
1 parent 86b7310 commit 092aeec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions tasks/task_2/khramov_i_star_topology/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(Star_Topology_MPI, Test_Send_Through_Master) {
int receiver = world_size - 1;
int data = 0;

if (world_rank == source)
if (world_rank == source || world_size == 1)
data = 200;

sendDataStar(MPI_COMM_WORLD, master, source, receiver, 0, &data, MPI_INT);
Expand Down Expand Up @@ -78,7 +78,7 @@ TEST(Star_Topology_MPI, Test_Send_To_Yourself) {
int receiver = master;
int data = 0;

if (world_rank == source)
if (world_rank == source || world_size == 1)
data = 1000;

sendDataStar(MPI_COMM_WORLD, master, source, receiver, 0, &data, MPI_INT);
Expand All @@ -99,7 +99,7 @@ TEST(Star_Topology_MPI, Test_For_One_Processor) {
int receiver = 0;
int data = 0;

if (world_rank == source)
if (world_rank == source || world_size == 1)
data = 200;

sendDataStar(MPI_COMM_WORLD, master, source, receiver, 0, &data, MPI_INT);
Expand All @@ -120,7 +120,7 @@ TEST(Star_Topology_MPI, Test_For_Two_Processors) {
int receiver = 1;
int data = 0;

if (world_rank == source)
if (world_rank == source || world_size == 1)
data = 200;

sendDataStar(MPI_COMM_WORLD, master, source, receiver, 0, &data, MPI_INT);
Expand Down
9 changes: 7 additions & 2 deletions tasks/task_2/khramov_i_star_topology/star_topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void sendDataStar(
MPI_Comm_size(world, &world_size);
MPI_Comm_rank(world, &world_rank);


if (!(source < world_size && receiver < world_size)) return;
if (receiver - source == 0) return;

Expand All @@ -32,8 +33,12 @@ void sendDataStar(
MPI_Send(data, 1, datatype, master, tag, world);
}
} else if (world_rank == master) {
MPI_Recv(data, 1, datatype, source, tag, world, MPI_STATUS_IGNORE);
MPI_Send(data, 1, datatype, receiver, tag, world);
if (master != receiver) {
MPI_Recv(data, 1, datatype, source, tag, world, MPI_STATUS_IGNORE);
MPI_Send(data, 1, datatype, receiver, tag, world);
} else {
MPI_Recv(data, 1, datatype, source, tag, world, MPI_STATUS_IGNORE);
}
} else if (world_rank == receiver) {
MPI_Recv(data, 1, datatype, master, tag, world, MPI_STATUS_IGNORE);
}
Expand Down

0 comments on commit 092aeec

Please sign in to comment.