-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
executable file
·62 lines (57 loc) · 1.21 KB
/
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <pthread.h>
#include "node.cpp"
using namespace std;
void *run_thread(void *arg) {
Node *node;
node = (Node *)arg;
while(run)
node->readMessage();
return NULL;
}
int main(void){
int i,j,k,rc,numNodes,w,*weights;
FILE *fp;
fp = fopen("input.txt","r");
fscanf(fp,"%d\n",&numNodes);
pthread_t *threads;
Node *nodes;
Node *nbrs[numNodes];
threads = (pthread_t *)malloc(numNodes*sizeof(pthread_t));
nodes = new Node[numNodes];
weights = (int *)malloc(numNodes*sizeof(int));
for(i=0;i<numNodes;i++){
k=0;
for(j=0;j<numNodes;j++){
fscanf(fp,"%d\t",&w);
if(w!=0){
weights[k]=w;
nbrs[k]=&nodes[j];
k++;
if(j<i){
edgeInput e;
e.left = j;
e.right= i;
allEdges.insert(pair<int,edgeInput>(w,e));
}
}
}
fscanf(fp,"\n");
nodes[i].init(k,weights,nbrs);
nodes[i].ind=i;
}
fclose(fp);
run = 1;
for (i=0;i<numNodes;i++){
rc = pthread_create(&threads[i],NULL,run_thread,(void *) &nodes[i]);
}
nodes[0].wakeup();
pthread_exit(NULL);
free(nodes);
free(threads);
free(weights);
free(nbrs);
return 0;
}