fucked up
This commit is contained in:
parent
61816ad046
commit
9c3447d22e
1 changed files with 125 additions and 36 deletions
|
@ -88,52 +88,140 @@ 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);
|
||||||
|
|
||||||
// Send it to the correct target
|
// TODO: This doesn't work :skull: substituting it for a slower method until i
|
||||||
int S_starting_process = S_global_start / n_over_p;
|
// Figure it out tomorrow
|
||||||
int S_offset = S_global_start % n_over_p,
|
if (0) {
|
||||||
L_offset = L_global_start % n_over_p;
|
// Send it to the correct target
|
||||||
int i, local_start;
|
int S_starting_process = S_global_start / n_over_p,
|
||||||
|
L_starting_process = L_global_start / n_over_p;
|
||||||
|
int S_offset = S_global_start % n_over_p,
|
||||||
|
L_offset = L_global_start % n_over_p;
|
||||||
|
|
||||||
for (i = S_starting_process, local_start = 0; i * n_over_p < S_global_end;
|
for (int i = S_lo, dest_pos = S_global_start,
|
||||||
++i) {
|
processor = S_starting_process;
|
||||||
int processor_start = S_offset;
|
i < S_hi;) {
|
||||||
int mod = S_global_end % n_over_p;
|
int next_break = MIN(int, dest_pos + (S_hi - S_lo),
|
||||||
int processor_end = MIN(int, n_over_p, mod == 0 ? n_over_p : mod);
|
(dest_pos / n_over_p) * n_over_p + n_over_p);
|
||||||
|
int count = next_break - dest_pos;
|
||||||
|
|
||||||
int total_start = i * n_over_p + processor_start;
|
int local_start = i, local_end = i + count;
|
||||||
int total_end = i * n_over_p + processor_end;
|
int dest_start = dest_pos, dest_end = dest_pos + count;
|
||||||
|
|
||||||
int n_bytes = total_end - total_start;
|
printf("[%d] copying from S, local[%d..%d] to dest #%d [%d..%d]\n", rank,
|
||||||
int local_end = local_start + n_bytes;
|
local_start, local_end, processor, dest_start, dest_end);
|
||||||
|
|
||||||
printf("[%d] - sending %d elements from local S [%d..%d] to destination S "
|
int recvbuf[count];
|
||||||
"[%d..%d]\n",
|
MPI_Sendrecv(&integers[local_start], count, MPI_INT, processor, 123,
|
||||||
rank, n_bytes, local_start, local_end, processor_start,
|
recvbuf, count, MPI_INT, rank, 123, MPI_COMM_WORLD,
|
||||||
processor_end);
|
MPI_STATUS_IGNORE);
|
||||||
// MPI_Sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
|
|
||||||
// int dest, int sendtag, void *recvbuf, int recvcount,
|
|
||||||
// MPI_Datatype recvtype, int source, int recvtag, MPI_Comm
|
|
||||||
// comm, MPI_Status *status)
|
|
||||||
|
|
||||||
local_start += n_bytes;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int L_starting_process = L_global_start / n_over_p;
|
if (0) {
|
||||||
for (i = L_starting_process; i * n_over_p < L_global_end; ++i) {
|
int *fucked = calloc(sizeof(int), n);
|
||||||
int processor_start = L_offset;
|
|
||||||
int mod = L_global_end % n_over_p;
|
|
||||||
int processor_end = MIN(int, n_over_p, mod == 0 ? n_over_p : mod);
|
|
||||||
|
|
||||||
int total_start = i * n_over_p + processor_start;
|
// Send it to the correct target
|
||||||
int total_end = i * n_over_p + processor_end;
|
int S_starting_process = S_global_start / n_over_p,
|
||||||
|
L_starting_process = L_global_start / n_over_p;
|
||||||
|
int S_offset = S_global_start % n_over_p,
|
||||||
|
L_offset = L_global_start % n_over_p;
|
||||||
|
|
||||||
int n_bytes = total_end - total_start;
|
for (int i = S_lo, dest_pos = S_global_start,
|
||||||
int local_end = local_start + n_bytes;
|
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;
|
||||||
|
|
||||||
printf("[%d] - sending %d elements from local L [%d..%d] to destination L "
|
int local_start = i, local_end = i + count;
|
||||||
"[%d..%d]\n",
|
int dest_start = dest_pos, dest_end = dest_pos + count;
|
||||||
rank, n_bytes, local_start, local_end, processor_start,
|
|
||||||
processor_end);
|
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);
|
||||||
|
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;
|
||||||
|
dest_pos += count;
|
||||||
|
processor += 1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -146,6 +234,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Finalize();
|
MPI_Finalize();
|
||||||
|
printf("Done.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue