-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_main.cpp
118 lines (93 loc) · 2.51 KB
/
client_main.cpp
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
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <getopt.h>
#include "producer.hpp"
#include "consumer.hpp"
#include "controller.hpp"
#include "dolphin-client.hpp"
#include "FileReader.hpp"
#define NO_FLAGS 0
#define ADAPTER_NUM 0
DolphinClient *c;
FileReader *f;
extern "C" {
typedef struct {
uint32_t size;
void *data;
} package;
}
void shutdown(int i) {
c->shutdown();
delete c;
delete f;
// Close all dolphin related resources
SCITerminate();
exit(EXIT_SUCCESS);
}
int main(int argc, char **argv) {
int remote_node = -1;
char *input = NULL;
int opt = 0;
static struct option long_options[] = {
{"input", required_argument, 0, 'i' },
{"remote", required_argument, 0, 'r' },
{0, 0, 0, 0 }
};
int long_index =0;
while ((opt = getopt_long(argc, argv,"i:r:",
long_options, &long_index )) != -1) {
switch (opt) {
case 'i' : input = optarg;
break;
case 'r' : remote_node = atoi(optarg);
break;
default : fprintf(stderr, "Error parsing arguments!\n");
exit(EXIT_FAILURE);
}
}
if (remote_node == -1) {
fprintf(stderr, "You must specify a remote node!\n");
return EXIT_FAILURE;
}
if (input == NULL) {
fprintf(stderr, "You must specify an input file!\n");
return EXIT_FAILURE;
}
sci_error_t error;
uint32_t node_id;
/*
* Handle interrupts
*/
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = shutdown;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
/*
* Initialize dolphin
*/
// Initialize the dolphin library
SCIInitialize(NO_FLAGS, &error);
if (error != SCI_ERR_OK) {
fprintf(stderr,"SCIInitialize failed - Error code 0x%x\n",error);
return EXIT_FAILURE;
}
/* Get local nodeId */
SCIGetLocalNodeId(ADAPTER_NUM, &node_id, NO_FLAGS, &error);
if (error != SCI_ERR_OK) {
fprintf(stderr,"Could not find the local adapter %d\n", ADAPTER_NUM);
return EXIT_FAILURE;
}
fprintf(stderr, "Node id %d\n", node_id);
/*
* Run dolphin
*/
c = new DolphinClient(node_id, remote_node, BUFSIZE);
c->setup();
c->connect();
f = new FileReader(input);
c->run(f);
delete c;
return EXIT_SUCCESS;
}