Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9170cef81615fbc1ead5fe00ad1b6101c45a60fc
[simgrid.git] / examples / gras / chrono / chrono2.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 #include <cblas.h>
14 void cblas_dgemm(const enum CBLAS_ORDER Order,
15                  const enum CBLAS_TRANSPOSE TransA,
16                  const enum CBLAS_TRANSPOSE TransB, const int M,
17                  const int N, const int K, const double alpha,
18                  const double *A, const int lda, const double *B,
19                  const int ldb, const double beta, double *C,
20                  const int ldc);
21
22
23 /* Function prototypes */
24 static int mat_mult(int n)
25 {
26   int i,j,k,l;
27   double *A,*B,*C;
28   double start = 0.0;
29   double now = 0.0;
30
31   A = malloc(n*n*sizeof(double));
32   B = malloc(n*n*sizeof(double));
33   C = malloc(n*n*sizeof(double));
34
35   start=now=gras_os_time();
36
37   INFO1("Matrix size: %d",n);
38 /*   INFO1("Before computation: %lg", start); */
39
40   for(l=0; l<40; l++) {
41     now=gras_os_time();
42     GRAS_BENCH_ONCE_RUN_ONCE_BEGIN();
43     for(i=0; i<n; i++)
44       for(j=0; j<n; j++) {
45         A[i*n+j]=2/n;
46         B[i*n+j]=1/n;
47         C[i*n+j]=0.0;
48       }
49
50     cblas_dgemm(CblasRowMajor,
51                 CblasNoTrans, CblasNoTrans, n, n, n,
52                 1.0, A, n, B, n, 0.0, C, n);    
53     GRAS_BENCH_ONCE_RUN_ONCE_END();
54     now=gras_os_time()-now;
55 /*     INFO2("Iteration %d : %lg ", l, now); */
56   }
57
58   now=gras_os_time()-start;
59   INFO1("Duration: %lg ", now);
60
61   free(A);
62   free(B);
63   free(C);
64 }
65
66 int multiplier (int argc,char *argv[])
67 {
68   gras_init(&argc, argv);
69
70   mat_mult(10);
71   mat_mult(20);
72   mat_mult(30);
73   mat_mult(40);
74   mat_mult(50);
75   mat_mult(75);
76   mat_mult(100);
77   mat_mult(300);
78   mat_mult(500);
79   mat_mult(750);
80   mat_mult(1000);
81
82   return 0;
83 }