-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_dynamic_threads.c
79 lines (57 loc) · 1.57 KB
/
main_dynamic_threads.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include "listworkload.h"
#include "connectedComponents.h"
#include "bfs.h"
#include "buffer.h"
#include "dynamic_threads.h"
global_vars_Dynamic gvD;
JobScheduler *js;
int M;
int main(int argc,char* argv[]) {
int err,i;
edge ed;
if(argc < 5){ //1.graph call, 2.Graph, 3.Workload 4.Number Of Threads 5.M:numofjobs per thread execution
printf("Correct syntax is: %s <input_file> <workload_file> <threads_number> <thread_jobs_per_time>\n", argv[0]);
return -1;
}
M = atoi(argv[4]);
js = initialize_scheduler(atoi(argv[3]));
err=initStructs(argv,&ed);
if(err<0)
return -1;
/////////////////////////////////////////////////////////////////
for(i=0;i<(js->threadsnum);i++){
int *arg = malloc(sizeof(int));
if ( arg == NULL ) {
fprintf(stderr, "Couldn't allocate memory for thread arg.\n");
exit(EXIT_FAILURE);
}
*arg = i;
if( pthread_create( &(js->tids[i]) , NULL , worker , arg) < 0) { //create workers
printf("could not create thread\n");
return -1;
}
}
int exit;
while((exit=submit_jobs()) == 1){
execute_all_jobs();
wait_all_task_finish();
//print results!
execute_print();
}
workers_exit();
for(i=0;i<(js->threadsnum);i++)
pthread_join(js->tids[i],NULL);
printf("End of workload reached\n");
destroyStructs();//destroy all structs.
destroy_scheduler();
return 0;
}