-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
128 lines (106 loc) · 3.37 KB
/
main.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
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
119
120
121
122
123
124
125
126
127
/*!
\file
\brief The entry point of the triangle counting code
*/
#include "tc.h"
int _floor(double x) {
return (int)x;
}
int isPerfectSquare(int x) {
if (x==1) return 1;
int t, l, h;
l = 0;
h = _floor(x/2);
t = l + _floor((h-l)/2);
while (h-l >= 15) {
if (t*t == x)
return 1;
t = l + _floor((h-l)/2);
if (t*t < x)
l = t;
else
h = t;
}
for (int i=l; i<=h; i++)
if (i*i == x)
return 1;
return 0;
}
/*************************************************************************
* The entry point
**************************************************************************/
int main(int argc, char *argv[])
{
int64_t ntriangles=0;
params_t *params;
vault_t *vault;
params = getcmdline_params(argc, argv);
/* Initialize MPI */
MPI_Init(¶ms->argc, ¶ms->argv);
int mype, npes;
MPI_Comm_size(MPI_COMM_WORLD, &npes);
MPI_Comm_rank(MPI_COMM_WORLD, &mype);
//if (_floor(sqrt(npes))*_floor(sqrt(npes))!=npes) {
if (!isPerfectSquare(npes)) {
printf("#ranks should be a perfect square!\n");
MPI_Finalize();
exit(0);
}
vault = loadData(params);
setvbuf(stdout, NULL, _IOLBF, 0);
if (mype == 0) {
printf("\n-----------------\n");
if (params->iftype != 1)
printf("infile: %s\n", params->infile);
else
printf("generating RMAT file with scale %d..\n", params->scale);
printf("per proc #nvtxs: %d\n", vault->graph->nvtxs);
printf("tctype: %s, otype: %s\n", tctypenames[params->tctype], otypenames[params->otype]);
printf("\n");
}
/* perform various non-timed initializations */
srand(params->seed);
/* count triangles... */
switch (params->tctype) {
case TCTYPE_MAPJIK2D:
MPI_Barrier(MPI_COMM_WORLD);
if (mype==0)
gk_startwctimer(vault->timer_global);
ntriangles = mpitc_MapJIK2D(params, vault);
MPI_Barrier(MPI_COMM_WORLD);
if (mype==0)
gk_stopwctimer(vault->timer_global);
break;
default:
errexit("Unknown tctype of %d\n", params->tctype);
}
if (mype == 0) {
printf("#triangles: %"PRId64"; rate: %.4lf MT/sec\n", ntriangles,
((double)ntriangles)/((double)1e6*gk_getwctimer(vault->timer_2)));
printf("wall clock time:\t%.3lfs\n", gk_getwctimer(vault->timer_global));
if (gk_getwctimer(vault->timer_1) > 0)
printf("pre-processing:\t\t%.3lfs\n", gk_getwctimer(vault->timer_1));
if (gk_getwctimer(vault->timer_2) > 0)
printf("triangle counting:\t%.3lfs\n", gk_getwctimer(vault->timer_2));
if (gk_getwctimer(vault->timer_3) > 0)
printf(" timer_3: %.3lfs\n", gk_getwctimer(vault->timer_3));
if (gk_getwctimer(vault->timer_4) > 0)
printf(" timer_4: %.3lfs\n", gk_getwctimer(vault->timer_4));
if (gk_getwctimer(vault->timer_5) > 0)
printf(" timer_5: %.3lfs\n", gk_getwctimer(vault->timer_5));
if (gk_getwctimer(vault->timer_6) > 0)
printf(" timer_6: %.3lfs\n", gk_getwctimer(vault->timer_6));
printf("\n-----------------\n");
printf("RUNRESULT: %s %s %d %"PRId64" %.4lf %.3lf %.3lf %.3lf\n",
params->infile,
tctypenames[params->tctype],
params->scale,
ntriangles,
((double)ntriangles)/((double)1e6*gk_getwctimer(vault->timer_2)),
gk_getwctimer(vault->timer_global),
gk_getwctimer(vault->timer_1),
gk_getwctimer(vault->timer_2)
);
}
MPI_Finalize();
}