-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraceInterleaver.c
85 lines (80 loc) · 2.1 KB
/
traceInterleaver.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
// Author: Atanu Barai <[email protected]>
// Purpose: Interleaves memory trace
// Last Edit Nov 26
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define MAX_CORES 16
int main(int argc, char *argv[])
{
char *line = NULL;
size_t len = 0;
ssize_t read;
unsigned long long i = 0, trace_trav_done[MAX_CORES];
int num_cores, core;
FILE *outfile;
FILE *infile[MAX_CORES];
char str[40];
if (argc != 2)
{
printf("%d of 1 arguments received\n", (argc - 1));
printf("Command Line Arguments: number of cores\n");
exit(1);
}
else
{
printf("%d of 1 arguments received\n", (argc - 1));
num_cores = atoi(argv[1]);
printf("Number of Cores: %d\n", num_cores);
}
for (core = 0; core < num_cores; core++)
{
trace_trav_done[core] = 0;
sprintf(str, "%dcores_trace_core%d.dat", num_cores, core);
//printf("%s\n",str);
infile[core] = fopen(str, "r");
if (infile[core] == NULL)
{
printf("Error in opening input file on %dth time!\n", core + 1);
exit(1);
}
}
sprintf(str, "InterleavedTrace%dCores.dat", num_cores);
outfile = fopen(str, "w");
if (outfile == NULL)
{
printf("Error in opening input file \n");
exit(1);
}
printf("Interleaving Start\n");
i = 0;
while (i < num_cores)
{
for (core = 0; core < num_cores; core++)
{
if ((read = getline(&line, &len, infile[core])) != -1)
{
fprintf(outfile, "%s", line);
//printf("%s", line);
}
else
{
if (trace_trav_done[core] == 0)
{
trace_trav_done[core] = 1;
++i;
}
}
}
}
printf("Interleaving Done. Releasing Resources\n");
if (line)
free(line);
fclose(outfile);
for (core = 0; core < num_cores; core++)
fclose(infile[core]);
printf("Resources Released\n");
return 0;
}