Logo AND Algorithmique Numérique Distribuée

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