-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.cpp
More file actions
90 lines (65 loc) · 2.38 KB
/
master.cpp
File metadata and controls
90 lines (65 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// Created by focjoe on 12/08/2019.
//
#include "mpi.h"
#include "main.h"
#include<unistd.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
void works(MPI_Comm everyone) {
sleep(1);
int rank, size;
MPI_Comm_rank(everyone, &rank);
MPI_Comm_size(everyone, &size);
printf("%s: rank %d in %d doing work...\n", name, rank, size);
}
int main(int argc, char *argv[]) {
int world_size;
name = "parent";
char slave_names[12][4] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"};
int current_slaves = 0; /**< Current alive slave numbers */
int init_slave_num = 7; /** Initially created slave numbers */
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
if (world_size != 1) printf("Master program should be ran with \" -np 1 \"");
MPI_Comm everyone;
// spawn a node
spawn_and_merge(slave_path, "a", 1, &everyone);
current_slaves++;
// loop to create more slave process(es)
for (int i = 1; i < init_slave_num; ++i) {
add_process(slave_names[i], &everyone);
current_slaves++;
}
// test to remove process "c"
// int rank_to_remove = 3;
// MPI_Send(&rank_to_remove, 1, MPI_INT, rank_to_remove, TAG_REMOVE_SELF, everyone);
int matched;
// Main loop
remove_process(1, &everyone);
remove_process(1, &everyone);
remove_process(1, &everyone);
int i = 0;
while (1) {
// remove one process
// MPI_Iprobe(MPI_ANY_SOURCE, TAG_REMOVE_PROC, everyone, &matched, MPI_STATUS_IGNORE);
// if(matched) remove_process_handler(&everyone);
// else printf("parent: did't receive remove process message");
/*
* ::: ::: :::::::: ::::::::: ::: ::: ::::::::
* :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:
* +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
* +#+ +:+ +#+ +#+ +:+ +#++:++#: +#++:++ +#++:++#++
* +#+ +#+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+
* #+#+# #+#+# #+# #+# #+# #+# #+# #+# #+# #+#
* ### ### ######## ### ### ### ### ########
*
* Replace below placeholder works() function with yours.
*/
works(everyone);
i++;
}
MPI_Finalize();
return 0;
}
#pragma clang diagnostic pop