Logo AND Algorithmique Numérique Distribuée

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