Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
eb31f9a8823519a5c9d621703eda5ef21a55e476
[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 = 500;
24   double start = 0.0;
25
26   gras_init(&argc, argv, NULL);
27
28   A = malloc(n*n*sizeof(double));
29   B = malloc(n*n*sizeof(double));
30   C = malloc(n*n*sizeof(double));
31
32   INFO1("Before computation: %lg", start=gras_os_time());
33
34   for(l=0; l<4; l++) {
35     GRAS_BENCH_ONCE_RUN_ONCE_BEGIN();
36     for(i=0; i<n; i++)
37       for(j=0; j<n; j++) {
38         A[i*n+j]=2/n;
39         B[i*n+j]=1/n;
40         C[i*n+j]=0.0;
41       }
42     
43     for(i=0; i<n; i++)
44       for(j=0; j<n; j++)
45         for(k=0; k<n; k++)      
46           C[i*n+j] += A[i*n+k]*B[k*n+j];
47     
48     GRAS_BENCH_ONCE_RUN_ONCE_END();
49   }
50
51   start = gras_os_time()-start;
52   INFO2("After computation: %lg; Duration: %lg ", gras_os_time(), start);
53
54   return 0;
55 }