Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill old $Id$ command dating from CVS
[simgrid.git] / examples / gras / chrono / chrono.c
1 /* chrono - demo of GRAS benchmarking features                              */
2
3 /* Copyright (c) 2005 Martin Quinson, Arnaud Legrand. All rights reserved.  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "gras.h"
9 #include "xbt/log.h"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(Chrono, "Messages specific to this example");
12
13
14 /* Function prototypes */
15 int multiplier(int argc, char *argv[]);
16
17 int multiplier(int argc, char *argv[])
18 {
19   int i, j, k, l;
20   double *A, *B, *C;
21   int n = 100;
22   double start = 0.0;
23   double now = 0.0;
24
25   gras_init(&argc, argv);
26
27   A = malloc(n * n * sizeof(double));
28   B = malloc(n * n * sizeof(double));
29   C = malloc(n * n * sizeof(double));
30
31   start = now = gras_os_time();
32
33   INFO1("Begin matrix multiplication loop (time: %g)", start);
34
35   for (l = 0; l < 4; l++) {
36     now = gras_os_time();
37     GRAS_BENCH_ONCE_RUN_ONCE_BEGIN();
38     for (i = 0; i < n; i++)
39       for (j = 0; j < n; j++) {
40         A[i * n + j] = 2 / n;
41         B[i * n + j] = 1 / n;
42         C[i * n + j] = 0.0;
43       }
44
45     for (i = 0; i < n; i++)
46       for (j = 0; j < n; j++)
47         for (k = 0; k < n; k++)
48           C[i * n + j] += A[i * n + k] * B[k * n + j];
49
50     GRAS_BENCH_ONCE_RUN_ONCE_END();
51     now = gras_os_time() - now;
52     INFO2("Iteration %d : %g ", l, now);
53   }
54
55   now = gras_os_time() - start;
56   INFO2("End matrix multiplication loop (time: %g; Duration: %g)",
57         gras_os_time(), now);
58
59   start = now = gras_os_time();
60   INFO1("Begin malloc loop (time: %g)", start);
61   for (l = 0; l < 4; l++) {
62     now = gras_os_time();
63     GRAS_BENCH_ONCE_RUN_ONCE_BEGIN();
64     free(A);
65     A = malloc(n * n * sizeof(double));
66     GRAS_BENCH_ONCE_RUN_ONCE_END();
67     now = gras_os_time() - now;
68     INFO2("Iteration %d : %g ", l, now);
69   }
70
71   start = now = gras_os_time();
72   INFO1("Begin integer incrementation loop (time: %g)", start);
73   for (l = 0; l < 4; l++) {
74     GRAS_BENCH_ONCE_RUN_ONCE_BEGIN();
75     j++;
76     GRAS_BENCH_ONCE_RUN_ONCE_END();
77   }
78   free(A);
79   free(B);
80   free(C);
81
82   gras_exit();
83   return 0;
84 }