too bad can't do alltoallv

This commit is contained in:
Michael Zhang 2023-10-30 07:08:35 +00:00
parent 9c3447d22e
commit f499ca434f

View file

@ -88,61 +88,15 @@ int main(int argc, char **argv) {
printf("[%d] S: [%d - %d], L: [%d - %d]\n", rank, S_global_start, printf("[%d] S: [%d - %d], L: [%d - %d]\n", rank, S_global_start,
S_global_end - 1, L_global_start, L_global_end - 1); S_global_end - 1, L_global_start, L_global_end - 1);
// TODO: This doesn't work :skull: substituting it for a slower method until i {
// Figure it out tomorrow int recvpart[n_over_p];
if (0) { int send_counts[p];
// Send it to the correct target int send_displs[p];
int S_starting_process = S_global_start / n_over_p, for (int i = 0; i < p; ++i) {
L_starting_process = L_global_start / n_over_p; send_counts[i] = 0;
int S_offset = S_global_start % n_over_p, send_displs[i] = 0;
L_offset = L_global_start % n_over_p;
for (int i = S_lo, dest_pos = S_global_start,
processor = S_starting_process;
i < S_hi;) {
int next_break = MIN(int, dest_pos + (S_hi - S_lo),
(dest_pos / n_over_p) * n_over_p + n_over_p);
int count = next_break - dest_pos;
int local_start = i, local_end = i + count;
int dest_start = dest_pos, dest_end = dest_pos + count;
printf("[%d] copying from S, local[%d..%d] to dest #%d [%d..%d]\n", rank,
local_start, local_end, processor, dest_start, dest_end);
int recvbuf[count];
MPI_Sendrecv(&integers[local_start], count, MPI_INT, processor, 123,
recvbuf, count, MPI_INT, rank, 123, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
i += count;
dest_pos += count;
processor += 1;
} }
for (int i = L_lo, dest_pos = L_global_start,
processor = L_starting_process;
i < L_hi;) {
int next_break = MIN(int, L_global_end,
MIN(int, dest_pos + (L_hi - L_lo),
(dest_pos / n_over_p) * n_over_p + n_over_p));
int count = next_break - dest_pos;
int local_start = i, local_end = i + count;
int dest_start = dest_pos, dest_end = dest_pos + count;
printf("[%d] copying from L, local[%d..%d] to dest #%d [%d..%d]\n", rank,
local_start, local_end, processor, dest_start, dest_end);
i += count;
dest_pos += count;
processor += 1;
}
}
if (0) {
int *fucked = calloc(sizeof(int), n);
// Send it to the correct target // Send it to the correct target
int S_starting_process = S_global_start / n_over_p, int S_starting_process = S_global_start / n_over_p,
L_starting_process = L_global_start / n_over_p; L_starting_process = L_global_start / n_over_p;
@ -161,67 +115,29 @@ int main(int argc, char **argv) {
printf("[%d] copying from S, local[%d..%d] to dest #%d [%d..%d]\n", rank, printf("[%d] copying from S, local[%d..%d] to dest #%d [%d..%d]\n", rank,
local_start, local_end, processor, dest_start, dest_end); local_start, local_end, processor, dest_start, dest_end);
send_counts[processor] = count;
int recvbuf[count]; // int recvbuf[count];
// MPI_Sendrecv(&integers[local_start], count, MPI_INT, processor, 123, // MPI_Sendrecv(&integers[local_start], count, MPI_INT, processor, 123,
// recvbuf, count, MPI_INT, rank, 123, MPI_COMM_WORLD, // recvbuf, count, MPI_INT, rank, 123, MPI_COMM_WORLD,
// MPI_STATUS_IGNORE); // MPI_STATUS_IGNORE);
for (int j = 0; j < count; ++j) {
fucked[j] = integers[local_start + j];
}
// MPI_Scatter(&integers[local_start], count, MPI_INT,
// &fucked[dest_start],
// count, MPI_INT, rank, MPI_COMM_WORLD);
// MPI_Bcast(&dest_start, 1, MPI_INT, rank, MPI_COMM_WORLD);
// printf("dest start is %d %d\n", dest_start, count);
// MPI_Bcast(&fucked[dest_start], count, MPI_INT, rank, MPI_COMM_WORLD);
// MPI_Alltoall(&fucked[dest_start], count, MPI_INT, &fucked[dest_start],
// count, MPI_INT, MPI_COMM_WORLD);
// MPI_Allgather(&fucked[dest_start], count, MPI_INT, &fucked[dest_start],
// count, MPI_INT, MPI_COMM_WORLD);
int recvs[p];
int displs[p];
MPI_Allgather(&count, 1, MPI_INT, &recvs, 1, MPI_INT, MPI_COMM_WORLD);
displs[0] = 0;
for (int j = 1; j < p; j++) {
displs[j] = displs[j - 1] + recvs[j - 1];
}
MPI_Allgatherv(&fucked[dest_start], count, MPI_INT, &fucked[dest_start],
&recvs[0], &displs[0], MPI_INT, MPI_COMM_WORLD);
// MPI_Alltoall(&fucked[local_start], count, MPI_INT,
// &fucked[local_start], count, MPI_INT,
// MPI_COMM_WORLD);
i += count;
dest_pos += count;
processor += 1;
for (int i = 0; i < n; ++i) {
printf("%d, ", fucked[i]);
}
printf("\n");
}
/*
for (int i = L_lo, dest_pos = L_global_start,
processor = L_starting_process;
i < L_hi;) {
int next_break = MIN(int, L_global_end,
MIN(int, dest_pos + (L_hi - L_lo),
(dest_pos / n_over_p) * n_over_p +
n_over_p)); int count = next_break - dest_pos;
int local_start = i, local_end = i + count;
int dest_start = dest_pos, dest_end = dest_pos + count;
printf("[%d] copying from L, local[%d..%d] to dest #%d [%d..%d]\n",
rank, local_start, local_end, processor, dest_start, dest_end);
i += count; i += count;
dest_pos += count; dest_pos += count;
processor += 1; processor += 1;
} }
*/
for (int i = 1; i < p; ++i) {
send_displs[i] = send_displs[i - 1] + send_counts[i - 1];
}
// MPI_Alltoallv(integers, send_counts, send_displs, MPI_INT, recvpart,
// const int *recvcounts, const int *rdispls, MPI_Datatype recvtype,
// MPI_Comm comm)
printf("[%d] send_counts: %s\n", rank, string_of_list(send_counts, p));
printf("[%d] send_displs: %s\n", rank, string_of_list(send_displs, p));
printf("[%d] after: %s\n", rank, string_of_list(recvpart, n_over_p));
} }
// The first node is responsible for collecting all the data and then printing // The first node is responsible for collecting all the data and then printing