Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish alltoall_bruck implementation #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ endif()
#####################
include(FetchContent)

set(gtest_tag 703bd9caab50b139428cea1aaff9974ebee5742e)
set(gtest_tag release-1.12.1)

FetchContent_Declare(
googletest
Expand Down
39 changes: 28 additions & 11 deletions src/collective/alltoall.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
* on-node so that each process holds
* the correct final data
*************************************************/
int MPIX_Alltoall(const void* sendbuf,
const int sendcount,
MPI_Datatype sendtype,
void* recvbuf,
const int recvcount,
MPI_Datatype recvtype,
MPIX_Comm* mpi_comm);

int MPI_Alltoall(const void* sendbuf,
const int sendcount,
MPI_Datatype sendtype,
Expand Down Expand Up @@ -305,14 +313,14 @@ int alltoall_bruck(const void* sendbuf,
if (rank)
rotate(recv_buffer, rank*msg_size, num_procs*msg_size);

if (rank == 0) for (int i = 0; i < total_count; i++)
printf("%d\n", ((int*)(recvbuf))[i]);
// if (rank == 0) for (int i = 0; i < total_count; i++)
// printf("%d\n", ((int*)(recvbuf))[i]);

// 2. send to left, recv from right
stride = 1;
for (int i = 0; i < num_steps; i++)
{
if (rank == 0) printf("Step %d\n", i);
// if (rank == 0) printf("Step %d\n", i);
recv_proc = rank - stride;
if (recv_proc < 0) recv_proc += num_procs;
send_proc = rank + stride;
Expand All @@ -327,17 +335,17 @@ int alltoall_bruck(const void* sendbuf,
{
for (int k = 0; k < recv_size; k++)
{
if (rank == 0) printf("i = %d, j = %d, k = %d\n", i, j, k);
// if (rank == 0) printf("i = %d, j = %d, k = %d\n", i, j, k);
contig_buf[ctr*recv_size+k] = recv_buffer[(i+j)*recv_size+k];
}
if (rank == 0) printf("Contigbuf[%d] = %d\n", ctr, ((int*)(contig_buf))[ctr]);
// if (rank == 0) printf("Contigbuf[%d] = %d\n", ctr, ((int*)(contig_buf))[ctr]);
ctr++;
}
}

size = ((int)(total_count / group_size) * group_size) / 2;

if (rank == 0) printf("Rank %d sending %d vals (%d) to %d\n", rank, size, ((int*)(contig_buf))[0], send_proc);
// if (rank == 0) printf("Rank %d sending %d vals (%d) to %d\n", rank, size, ((int*)(contig_buf))[0], send_proc);
MPI_Isend(contig_buf, size, recvtype, send_proc, tag, comm, &(requests[0]));
MPI_Irecv(tmpbuf, size, recvtype, recv_proc, tag, comm, &(requests[1]));
MPI_Waitall(2, requests, MPI_STATUSES_IGNORE);
Expand All @@ -355,8 +363,8 @@ int alltoall_bruck(const void* sendbuf,
}
}

if (rank == 0) for (int i = 0; i < total_count; i++)
printf("%d\n", ((int*)(recvbuf))[i]);
// if (rank == 0) for (int i = 0; i < total_count; i++)
// printf("%d\n", ((int*)(recvbuf))[i]);

stride *= 2;

Expand All @@ -366,10 +374,19 @@ int alltoall_bruck(const void* sendbuf,
if (rank < num_procs)
rotate(recv_buffer, (rank+1)*msg_size, num_procs*msg_size);

if (rank == 0) for (int i = 0; i < total_count; i++)
printf("%d\n", ((int*)(recvbuf))[i]);
// if (rank == 0) for (int i = 0; i < total_count; i++)
// printf("%d\n", ((int*)(recvbuf))[i]);

// TODO :: REVERSE!
// 4. reverse local data
memcpy(tmpbuf, recv_buffer, total_count*recv_size);
int i_rev = num_procs - 1;
for (int i = 0; i < num_procs; ++i)
{
memcpy(((char*)recvbuf) + i*msg_size, ((char*)tmpbuf) + i_rev*msg_size, msg_size);
i_rev -= 1;
}

free(contig_buf);
free(tmpbuf);
return 0;
}
3 changes: 1 addition & 2 deletions src/collective/tests/test_alltoall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ TEST(RandomCommTest, TestsInTests)
for (int j = 0; j < s*num_procs; j++)
ASSERT_EQ(std_alltoall[j], loc_p2p_alltoall[j]);

/*
alltoall_bruck(local_data.data(),
s,
MPI_INT,
Expand All @@ -94,7 +93,7 @@ TEST(RandomCommTest, TestsInTests)
MPI_INT,
MPI_COMM_WORLD);
for (int j = 0; j < s*num_procs; j++)
ASSERT_EQ(std_alltoall[j], bruck_alltoall[j]);*/
ASSERT_EQ(std_alltoall[j], bruck_alltoall[j]);
}

MPIX_Comm_free(locality_comm);
Expand Down