Skip to content

Commit 940cc6e

Browse files
authored
Merge pull request #19 from SidoShiro/dev
Dev
2 parents 9c26cda + 21e222d commit 940cc6e

30 files changed

Lines changed: 1391 additions & 71 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*idea/*
33
*cmake-build-debug/*
44
*build/*
5+
*vscode/*
56

67
# Prerequisites
78
*.d

CMakeLists.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,29 @@ project(DistributedMalloc)
88
find_package(MPI REQUIRED)
99

1010
# Vars with files for compilation
11-
set(SRCS src/main/main.c src/utils/utils.c src/cli/cli.c src/network/message.c src/network/block.c src/network/node.c src/utils/command_queue.c src/graph/graph.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+
25+
set(MAIN src/main/main.c)
26+
27+
set(TEST_MAIN test/main_test.c)
28+
1229

1330
include_directories("include/")
1431
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
1532

16-
add_executable(dmalloc ${SRCS} ${MPI_C_LIBRARIES})
33+
add_executable(dmalloc ${SRCS} ${MAIN} ${MPI_C_LIBRARIES})
1734

35+
include_directories("include/")
36+
add_executable(test_dmalloc ${SRCS} ${TEST_MAIN} ${MPI_C_LIBRARIES})

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ make
2222
mpirun --hostfile hostfile dmalloc [DOTFILE]
2323
```
2424

25+
The *run.sh* script execute **mpirun** on build/dmalloc, takes 1 argument for number of nodes,
26+
default is 20.
27+
2528

2629
# Tooltips
2730

include/block.h

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
11
#ifndef DISTRIBUTEDMALLOC_BLOCK_H
22
#define DISTRIBUTEDMALLOC_BLOCK_H
33

4-
#include "stdlib.h"
4+
#include <stdlib.h>
5+
#include <stdio.h>
56

7+
/**
8+
* size of block
9+
* address on id node
10+
* address virtual (user view)
11+
* next block
12+
* free : 0 is free, 1 is allocated
13+
*/
614
struct block {
715
unsigned short id;
816
size_t size;
9-
size_t address;
17+
size_t node_address;
18+
size_t virtual_address;
1019
struct block *next;
20+
char free;
1121
};
1222

13-
struct blocks {
23+
struct block_register {
1424
size_t nb_blocks;
1525
struct block **blks;
1626
};
1727

18-
struct blocks *generate_blocks(size_t nb_blks);
28+
struct allocation_register {
29+
size_t size_alloc;
30+
size_t count_alloc;
31+
struct allocation **allocs;
32+
};
33+
34+
struct allocation {
35+
size_t number_parts;
36+
size_t v_address_start;
37+
struct block **parts;
38+
};
39+
40+
struct allocation_register *generate_allocs(size_t size_alloc);
41+
42+
void add_allocation(struct allocation_register *a_r, struct allocation *a);
43+
44+
struct block_register *init_nodes_same_size(unsigned short nb_nodes, size_t size);
45+
46+
struct block_register *generate_blocks(size_t nb_blks);
47+
48+
struct block *generate_block(unsigned short id, size_t size, size_t node_address, size_t virtual_address, char free);
49+
50+
void
51+
add_block(struct block *blk, unsigned short id, size_t size, size_t node_address, size_t virtual_address, char free);
52+
53+
void merge_free_block(struct block_register *blks);
1954

20-
struct block *generate_block(unsigned short id, size_t size, size_t address);
55+
struct block_register *init_nodes_same_size(unsigned short nb_nodes, size_t size);
2156

22-
void add_block(struct block blk, unsigned short id, size_t size, size_t address);
57+
/**
58+
* Splited half 2 is free = 0
59+
* @param b
60+
* @param size
61+
* @return
62+
*/
63+
struct block *split_block_u(struct block *b, size_t size);
2364

2465
#endif /* !DISTRIBUTEDMALLOC_BLOCK_H */

include/cli.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
#include <stdlib.h>
88
#include <err.h>
99

10+
#include "message.h"
1011
#include "utils.h"
1112

1213
void start_cli();
1314

15+
void send_command(enum operation op, void *data, unsigned short leader);
16+
1417
#endif /* !DISTRIBUTEDMALLOC_CLI_H */

include/command_queue.h

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@
33

44
#include <stdlib.h>
55

6-
enum user_command {
7-
MALLOC, // Data => Size
8-
FREE, // Data => Address
9-
WRITE, // Data => Address; Data size; Data
10-
READ, // Data => Address; Data size
11-
DUMP, // Data => Address
12-
SNAP,
13-
DNET,
14-
KILL, // Data => id
15-
REVIVE, // Data => id
16-
NONE
17-
};
6+
#include "message.h"
7+
8+
// OP_MALLOC, // Data => Size
9+
// OP_FREE, // Data => Address
10+
// OP_WRITE, // Data => Address; Data size; Data
11+
// OP_READ, // Data => Address; Data size
12+
// OP_DUMP, // Data => Address
13+
// OP_SNAP,
14+
// OP_DNET,
15+
// OP_KILL, // Data => id
16+
// OP_REVIVE, // Data => id
17+
// OP_NONE
1818

1919
struct command_queue {
20-
enum user_command command;
20+
enum operation command;
2121
struct command_queue *next;
2222
void *data; // Contain the structure depending of the command
2323
};
2424

25+
26+
struct command_queue *generate_command_queue(enum operation op, void *data);
27+
2528
// Delete first command queue, return head
2629
struct command_queue *pop_command(struct command_queue *head);
2730

@@ -32,7 +35,15 @@ struct command_queue *push_command(struct command_queue *head, struct command_qu
3235
void *peek_command(struct command_queue *head);
3336

3437
// Get user command enum of the first of the queue
35-
enum user_command peek_user_command(struct command_queue *head);
38+
enum operation peek_user_command(struct command_queue *head);
39+
40+
struct data_write *generate_data_write(size_t address, size_t size, void *data);
41+
42+
struct data_read *generate_data_read(size_t address, size_t size);
43+
44+
struct data_size *generate_data_size(size_t size);
45+
46+
struct data_id *generate_data_id(unsigned short id);
3647

3748
struct data_write {
3849
size_t address;

include/debug.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef DISTRIBUTEDMALLOC_DEBUG_H
2+
#define DISTRIBUTEDMALLOC_DEBUG_H
3+
4+
#include <stdio.h>
5+
6+
void debug(char *msg, unsigned short id);
7+
8+
void debug_n(char *msg, unsigned short id, unsigned nb_bytes);
9+
10+
#endif /* !DISTRIBUTEDMALLOC_DEBUG_H */

include/globals.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef DISTRIBUTEDMALLOC_GLOBALS_H
2+
#define DISTRIBUTEDMALLOC_GLOBALS_H
3+
4+
#define DEF_NODE_SIZE 32
5+
#define DEF_NODE_USER 0
6+
#define DEF_NODE_LEADER 1
7+
8+
#endif /* !DISTRIBUTEDMALLOC_GLOBALS_H */

include/graph.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,27 @@ struct adjacency_matrix {
99
unsigned dimension;
1010
};
1111

12+
struct linked_list {
13+
unsigned id;
14+
struct linked_list* next;
15+
};
16+
17+
struct personal_map {
18+
struct linked_list** paths;
19+
// Import things:
20+
// - paths[id] == NULL (self)
21+
// - paths[0] == NULL (user)
22+
unsigned nb_paths;
23+
unsigned id;
24+
};
25+
26+
27+
1228
struct adjacency_matrix* dot_reader(char* path);
29+
struct personal_map* compute_personal_map(struct adjacency_matrix* a, unsigned id);
1330

1431
void free_adjacency_matrix(struct adjacency_matrix* a);
32+
void free_linked_list(struct linked_list* lkl); // really needs to be public ?
33+
void free_personal_map(struct personal_map* pm);
1534

1635
#endif //DISTRIBUTEDMALLOC_GRAPH_H

include/leader.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef DISTRIBUTEDMALLOC_LEADER_H
2+
#define DISTRIBUTEDMALLOC_LEADER_H
3+
4+
#include <stdlib.h>
5+
6+
#include "node.h"
7+
#include "message.h"
8+
#include "command_queue.h"
9+
#include "block.h"
10+
11+
struct leader_resources {
12+
struct block_register *leader_blks;
13+
struct allocation_register *leader_reg;
14+
struct command_queue *leader_command_queue;
15+
unsigned short id;
16+
};
17+
18+
struct address_search {
19+
unsigned short id;
20+
size_t r_address;
21+
size_t v_address;
22+
size_t n_address;
23+
size_t size;
24+
};
25+
26+
struct leader_resources *generate_leader_resources(size_t nb_nodes , size_t id);
27+
28+
void leader_loop(struct node *n, unsigned short terminal_id, unsigned short nb_nodes);
29+
30+
#endif /* !DISTRIBUTEDMALLOC_LEADER_H */

0 commit comments

Comments
 (0)