Skip to content

Commit 2ebc60b

Browse files
committed
leader: fixes in execute_write
1 parent 6627864 commit 2ebc60b

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

src/network/leader.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <unistd.h>
1010
#include <mpi.h>
1111
#include <stdint.h>
12+
#include <communication.h>
1213

1314
size_t get_message_size() {
1415
return (sizeof(unsigned short) * 3 + 2 * sizeof(size_t) + sizeof(enum operation));
@@ -275,29 +276,36 @@ void execute_write(struct leader_resources *l_r) {
275276
size_t part_s = 0;
276277
struct allocation *c_a = give_for_v_address(l_r, d_w->address, &part_s);
277278
if (c_a == NULL) {
278-
debug("Seg Fault: requested write to a not address", l_r->id);
279+
debug("Seg Fault: requested write to a not allocated address", l_r->id);
279280
return;
280281
}
281282

282283
// 2 Get the block to write to (Warning to multiple parts allocation)
283284
// (Warning to size bigger than block)
284285
size_t to_write_address_v = d_w->address;
286+
ssize_t x = d_w->size;
285287
for (size_t i = part_s; i < c_a->number_parts; i++) {
286288
// TODO handle size overflow
287-
288-
289-
struct block *b = c_a->parts[i];
290-
// compute size to write for this block
291-
size_t to_write_size = d_w->size - b->size;
292-
d_w->size -= to_write_size;
293-
// compute local address to write
294-
size_t local_address = b->virtual_address - to_write_address_v;
295-
to_write_address_v += local_address;
296-
297-
// 3 Send Write OP to each node (Warning to the local address of the node, not the virtual)
298-
struct message *m = generate_message(l_r->id, b->id, b->id, local_address, to_write_size, OP_WRITE);
299-
MPI_Send(m, sizeof(struct message), MPI_BYTE, b->id, 3, MPI_COMM_WORLD);
300-
MPI_Send(d_w->data, to_write_size, MPI_BYTE, b->id, 4, MPI_COMM_WORLD);
289+
while (x > 0) {
290+
struct block *b = c_a->parts[i];
291+
// compute size to write for this block
292+
ssize_t to_write_size = b->size - x;
293+
x -= to_write_size;
294+
if (to_write_size < 0) {
295+
debug("Fatal error in write operation, size to write negative", l_r->id);
296+
}
297+
// compute local address to write
298+
size_t local_address = b->virtual_address - to_write_address_v;
299+
to_write_address_v += local_address;
300+
301+
struct queue *q = queue_init();
302+
printf("Size to send for Write %ld\n\n", to_write_size);
303+
// 3 Send Write OP to each node (Warning to the local address of the node, not the virtual)
304+
struct message *m = generate_message(l_r->id, b->id, b->id, local_address, to_write_size, OP_WRITE);
305+
send_safe_message(m, q);
306+
debug_n(d_w->data, l_r->id, d_w->size);
307+
MPI_Send(d_w->data, to_write_size, MPI_BYTE, b->id, 4, MPI_COMM_WORLD);
308+
}
301309
}
302310

303311
// TODO Confirmation ?

0 commit comments

Comments
 (0)