This repository has been archived by the owner on Nov 14, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.c
140 lines (121 loc) · 5.97 KB
/
node.c
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// Created by ken on 30.05.16.
//
#include <simgrid/msg.h>
#include "messages.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(node, "messages specific for nodes");
int tier1(int argc, char *argv[]){
MSG_process_set_kill_time(MSG_process_self(), 100.0);
XBT_INFO("I'am ready to work");
msg_task_t task = NULL;
msg_task_t data = NULL;
char mailbox[80];
char dispatcher_mail[80];
int num = xbt_str_parse_int(argv[1], "Invalid argument %s");
int id = xbt_str_parse_int(argv[2], "Invalid argument %s");
sprintf(mailbox, "Tier1_%i_%i", num, id);
//At first moment nodes go to dispatcher
sprintf(dispatcher_mail, "dispatcher1_%i_TS", num);
msg_task_t first_task = MSG_task_create("Firstrequest", 0, MESSAGES_SIZE, NULL);
XBT_INFO("Send a pilot message to dispatcher");
MSG_task_send(first_task, dispatcher_mail);
while(1){
int res = MSG_task_receive(&task, mailbox);
if (res == MSG_OK) {
if (!strcmp(MSG_task_get_name(task), "finalize")) {
MSG_task_destroy(task);
break;
}
message_t message = MSG_task_get_data(task);
switch (message->type) {
case MONTE_CARLO:
XBT_INFO("Receive %s", MSG_task_get_name(task));
XBT_INFO("Start to execute Monte-Carlo %s", MSG_task_get_name(task));
message_t sms_from_task = MSG_task_get_data(task);
msg_task_t mc_task = MSG_task_create("", sms_from_task->flops_amount, 0, NULL);
int errcode = MSG_task_execute(mc_task);
if (errcode == MSG_OK){
XBT_INFO("Finished execute Monte-Carlo %s", MSG_task_get_name(task));
MSG_task_destroy(mc_task);
MSG_task_destroy(task);
task = NULL;
XBT_INFO("Send a pilot message to dispatcherxx");
MSG_task_send(MSG_task_create("Request", 0, MESSAGES_SIZE, NULL), dispatcher_mail);
} else if(errcode == MSG_HOST_FAILURE){
XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
MSG_task_destroy(task);
task = NULL;
return 0;
} else{
XBT_INFO("Hey ?! What's up ? ");
xbt_die("Unexpected behavior");
}
break;
case INSTRUCTION:
XBT_INFO("Receive %s", MSG_task_get_name(task));
if (!strcmp(message->downloadfrom, MSG_host_get_name(MSG_host_self()))) {
XBT_INFO("Start to execute %s.I have all data", MSG_task_get_name(task));
int errcode = MSG_task_execute(task);
if (errcode == MSG_OK){
XBT_INFO("Finished to execute %s", MSG_task_get_name(task));
MSG_task_destroy(task);
task = NULL;
XBT_INFO("Send a pilot message to dispatcher");
MSG_task_send(MSG_task_create("Request", 0, MESSAGES_SIZE, NULL), dispatcher_mail);
}
else if (errcode == MSG_HOST_FAILURE){
XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
MSG_task_destroy(task);
task = NULL;
return 0;
} else{
XBT_INFO("Hey ?! What's up ? ");
xbt_die("Unexpected behavior");
}
} else {
msg_task_t gtask = give_me_data(MSG_task_get_name(task), message->flops_amount,
message->size_data);
XBT_INFO("Hey %s, give me data for %s", message->downloadfrom, MSG_task_get_name(task));
MSG_task_send(gtask, message->downloadfrom);
XBT_INFO("yyyyyyyyyy");
MSG_task_destroy(task);
task = NULL;
}
break;
case DOWNLOADED:
XBT_INFO("Download data of %s from %s", MSG_task_get_name(task), sg_host_get_name(MSG_task_get_source(task)));
XBT_INFO("Start to execute %s", MSG_task_get_name(task));
errcode = MSG_task_execute(task);
if (errcode == MSG_OK){
XBT_INFO("Finished to execute %s", MSG_task_get_name(task));
MSG_task_destroy(task);
task = NULL;
XBT_INFO("Send a pilot message to dispatcher");
MSG_task_send(MSG_task_create("Request", 0, MESSAGES_SIZE, NULL), dispatcher_mail);
}
else if (errcode == MSG_HOST_FAILURE){
XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
MSG_task_destroy(task);
task = NULL;
} else{
XBT_INFO("Hey ?! What's up ? ");
xbt_die("Unexpected behavior");
}
break;
}
} else if (res == MSG_TIMEOUT) {
XBT_INFO("Anomaly occurred:Timeout Exception");
MSG_task_destroy(task);
task = NULL;
} else if (res == MSG_HOST_FAILURE) {
XBT_INFO("Anomaly occurred: HostFailure Exception");
MSG_task_destroy(task);
task = NULL;
} else if (res == MSG_TRANSFER_FAILURE){
XBT_INFO("Anomaly occurred: Transfer failure Exception");
MSG_task_destroy(task);
task = NULL;
break;
}
}
}