Skip to content

Commit ab1292f

Browse files
authored
Merge pull request #31 from SidoShiro/dev
Dev
2 parents 940cc6e + d7a40f2 commit ab1292f

File tree

23 files changed

+728
-163
lines changed

23 files changed

+728
-163
lines changed

CMakeLists.txt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
cmake_minimum_required(VERSION 3.0)
22

33
set(CMAKE_C_COMPILER "mpicc")
4-
set(CMAKE_C_FLAGS "-O3 -std=c11 -Werror -Wall -Wextra -pedantic")
4+
set(CMAKE_C_FLAGS "-O3 -std=c11 -Werror -Wall -Wextra -pedantic -fsanitize=address")
55

66
project(DistributedMalloc)
77

88
find_package(MPI REQUIRED)
99

1010
# Vars with files for compilation
11-
set(SRCS
12-
src/utils/utils.c
13-
src/cli/cli.c
14-
src/network/message.c
15-
src/network/block.c
16-
src/network/node.c
17-
src/utils/command_queue.c
18-
src/graph/graph.c
19-
src/graph/map.c
20-
src/network/leader.c
21-
src/network/leader_election.c
22-
src/utils/debug.c
23-
src/cli/user.c)
11+
set(SRCS
12+
src/utils/utils.c
13+
src/cli/cli.c
14+
src/network/message.c
15+
src/network/block.c
16+
src/network/node.c
17+
src/utils/command_queue.c
18+
src/graph/graph.c
19+
src/graph/map.c
20+
src/network/leader.c
21+
src/network/leader_election.c
22+
src/utils/debug.c
23+
src/cli/user.c
24+
src/network/communication.c
25+
src/utils/queue.c)
26+
2427

2528
set(MAIN src/main/main.c)
2629

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ default is 20.
4949
* **Message**
5050
* id_s (source)
5151
* id_t (target)
52-
* id_o (final target for operation)
52+
* id_o (final target for operation or additional information)
53+
* need_callback (does this message require an ALIVE callback)
5354
* size
5455
* address
5556
* enum *Op*
5657
* OK
58+
* MALLOC
59+
* FREE
5760
* WRITE
5861
* READ
5962
* SNAP
@@ -62,6 +65,11 @@ default is 20.
6265
* (REVIVE)
6366
* (DIE)
6467
* (TEST)
68+
* NONE
69+
* DUMP
70+
* LEADER_OK (leader election is over + a success)
71+
* ALIVE (callback, proving its aliveness)
72+
* LEADER_AGAIN (supposed leader is dead, need to retart the election)
6573
* **Block**
6674
* Linked list of:
6775
* address

include/block.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ add_block(struct block *blk, unsigned short id, size_t size, size_t node_address
5252

5353
void merge_free_block(struct block_register *blks);
5454

55-
struct block_register *init_nodes_same_size(unsigned short nb_nodes, size_t size);
56-
5755
/**
5856
* Splited half 2 is free = 0
5957
* @param b

include/command_queue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ struct data_size *generate_data_size(size_t size);
4545

4646
struct data_id *generate_data_id(unsigned short id);
4747

48+
struct data_address *generate_data_address(size_t address);
49+
4850
struct data_write {
4951
size_t address;
5052
size_t size;

include/communication.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef DISTRIBUTEDMALLOC_COMMUNICATION_H
2+
#define DISTRIBUTEDMALLOC_COMMUNICATION_H
3+
4+
#include "message.h"
5+
6+
#include "queue.h"
7+
8+
// Number of attempts failed before considering the node as dead.
9+
#define NB_ITER 60
10+
11+
/*
12+
* Send the given message 'm' to the destination node
13+
* Return 1 if it's a success, 0 if the destination node didn't respond in time
14+
*/
15+
int send_safe_message(struct message *m_send, struct queue *queue);
16+
17+
/*
18+
* Receive a message sent with 'send_safe_message'
19+
* then send a OP_OK to the source node
20+
*/
21+
struct message *receive_message(struct queue *message_queue);
22+
23+
#endif /* !DISTRIBUTEDMALLOC_COMMUNICATION_H */

include/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef DISTRIBUTEDMALLOC_GLOBALS_H
22
#define DISTRIBUTEDMALLOC_GLOBALS_H
33

4-
#define DEF_NODE_SIZE 32
4+
#define DEF_NODE_SIZE 8
55
#define DEF_NODE_USER 0
66
#define DEF_NODE_LEADER 1
77

include/leader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ struct leader_resources {
1313
struct allocation_register *leader_reg;
1414
struct command_queue *leader_command_queue;
1515
unsigned short id;
16+
size_t availaible_memory;
17+
size_t max_memory;
1618
};
1719

1820
struct address_search {
@@ -27,4 +29,6 @@ struct leader_resources *generate_leader_resources(size_t nb_nodes , size_t id);
2729

2830
void leader_loop(struct node *n, unsigned short terminal_id, unsigned short nb_nodes);
2931

32+
struct allocation *give_for_v_address(struct leader_resources *l_r, size_t v_address, size_t *part);
33+
3034
#endif /* !DISTRIBUTEDMALLOC_LEADER_H */

include/message.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ enum operation {
1616
OP_KILL,
1717
OP_TEST,
1818
OP_NONE,
19-
OP_DUMP
19+
OP_DUMP,
20+
OP_DUMP_ALL,
21+
OP_LEADER_OK,
22+
OP_ALIVE,
23+
OP_LEADER_AGAIN
2024
};
2125

2226
struct message {
2327
unsigned short id_s; // Source message id
2428
unsigned short id_t; // Target message id
2529
unsigned short id_o; // Node id for the operation
30+
unsigned short need_callback; // 1 if the target node have to respond OP_ALIVE
2631
size_t address;
2732
size_t size;
2833
enum operation op;
@@ -35,4 +40,12 @@ struct message *generate_message(unsigned short id_s,
3540
size_t size,
3641
enum operation op);
3742

43+
struct message *generate_message_a(unsigned short id_s,
44+
unsigned short id_t,
45+
unsigned short id_o,
46+
size_t address,
47+
size_t size,
48+
enum operation op,
49+
unsigned short need_callback);
50+
3851
#endif /* !DISTRIBUTEDMALLOC_MESSAGE_H */

include/node.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ struct node {
1010
unsigned char isleader; // 1 = is Leader, 0 = no
1111
// map; // From .dot file
1212
size_t size;
13+
char *memory;
1314
};
1415

1516
struct node *generate_node(unsigned short id, size_t size);
1617

18+
void node_cycle(struct node *n);
19+
1720
#endif /* !DISTRIBUTEDMALLOC_NODE_H */

include/queue.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef DISTRIBUTEDMALLOC_QUEUE_H
2+
#define DISTRIBUTEDMALLOC_QUEUE_H
3+
4+
struct queue {
5+
struct queue_node *first;
6+
};
7+
8+
struct queue_node {
9+
void *data;
10+
struct queue_node *next;
11+
};
12+
13+
struct queue *queue_init();
14+
15+
void queue_push_back(struct queue *q, void *data);
16+
17+
void queue_free(struct queue *q);
18+
19+
void *queue_pop(struct queue *q);
20+
21+
#endif /* !DISTRIBUTEDMALLOC_QUEUE_H */

0 commit comments

Comments
 (0)