-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
68 lines (61 loc) · 1.36 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
63
64
65
66
67
68
#include <iostream>
#include <pthread.h>
#include "noeud.h"
#include <cstdio>
#include <cstdlib>
using namespace std;
void *exec_thread(void *arg) {
Noeud *noeud;
noeud = (Noeud *)arg;
while(run)
noeud->lireMessage();
return NULL;
}
int main(int argc, char *argv[]){ //(void){
int i,j,k,rc,numNoeud,w,*poids;
FILE *fp;
if (argc < 2){
std::cout<<"veuillez executer avec un fichier comme parametre d'entrée"<<endl;
return -1;
}
fp = fopen(argv[1],"r");
fscanf(fp,"%d\n",&numNoeud);
pthread_t *threads;
Noeud *noeuds;
Noeud *nbrs[numNoeud];
threads = (pthread_t *)malloc(numNoeud*sizeof(pthread_t));
noeuds = new Noeud[numNoeud];
poids = (int *)malloc(numNoeud*sizeof(int));
for(i=0;i<numNoeud;i++){
k=0;
for(j=0;j<numNoeud;j++){
fscanf(fp,"%d\t",&w);
if(w!=0){
poids[k]=w;
nbrs[k]=&noeuds[j];
k++;
if(j<i){
canalsortie e;
e.gauche = j;
e.droit= i;
touscanaux.insert(pair<int,canalsortie>(w,e));
}
}
}
fscanf(fp,"\n");
noeuds[i].init(k,poids,nbrs);
noeuds[i].ind=i;
}
fclose(fp);
run = 1;
for (i=0;i<numNoeud;i++){
rc = pthread_create(&threads[i],NULL,exec_thread,(void *) &noeuds[i]);
}
noeuds[0].BLOC1();
pthread_exit(NULL);
free(noeuds);
free(threads);
free(poids);
free(nbrs);
return 0;
}