Logo AND Algorithmique Numérique Distribuée

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