Logo AND Algorithmique Numérique Distribuée

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