|
9 | 9 | #include <unistd.h> |
10 | 10 | #include <mpi.h> |
11 | 11 | #include <stdint.h> |
| 12 | +#include <communication.h> |
12 | 13 |
|
13 | 14 | size_t get_message_size() { |
14 | 15 | return (sizeof(unsigned short) * 3 + 2 * sizeof(size_t) + sizeof(enum operation)); |
@@ -275,29 +276,36 @@ void execute_write(struct leader_resources *l_r) { |
275 | 276 | size_t part_s = 0; |
276 | 277 | struct allocation *c_a = give_for_v_address(l_r, d_w->address, &part_s); |
277 | 278 | 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); |
279 | 280 | return; |
280 | 281 | } |
281 | 282 |
|
282 | 283 | // 2 Get the block to write to (Warning to multiple parts allocation) |
283 | 284 | // (Warning to size bigger than block) |
284 | 285 | size_t to_write_address_v = d_w->address; |
| 286 | + ssize_t x = d_w->size; |
285 | 287 | for (size_t i = part_s; i < c_a->number_parts; i++) { |
286 | 288 | // 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 | + } |
301 | 309 | } |
302 | 310 |
|
303 | 311 | // TODO Confirmation ? |
|
0 commit comments