1 /* Copyright (c) 2012, 2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "Matrix_init.h"
11 XBT_LOG_NEW_DEFAULT_CATEGORY(MM_init,
12 "Messages specific for this msg example");
13 #define _unused(x) ((void)x)
16 void matrices_initialisation( double ** p_a, double ** p_b, double ** p_c,
17 size_t m, size_t k_a, size_t k_b, size_t n,
18 size_t row, size_t col)
28 a = malloc(sizeof(double) * m * k_a);
31 perror("Error allocation Matrix A");
35 b = malloc(sizeof(double) * k_b * n);
38 perror("Error allocation Matrix B");
42 c = malloc(sizeof(double) * m * n);
44 perror("Error allocation Matrix C");
52 // size_tialisation of the matrices
54 for( z=0; z<k_a; z++){
58 a[x*lda+z] = (double)(z+col*n);
62 for( z=0; z<k_b; z++){
67 b[z*ldb+y] = (double)(y);
78 void matrices_allocation( double ** p_a, double ** p_b, double ** p_c,
79 size_t m, size_t k_a, size_t k_b, size_t n)
84 a = malloc(sizeof(double) * m * k_a);
87 perror("Error allocation Matrix A");
91 b = malloc(sizeof(double) * k_b * n);
94 perror("Error allocation Matrix B");
98 c = malloc(sizeof(double) * m * n);
100 perror("Error allocation Matrix C");
110 void blocks_initialisation( double ** p_a_local, double ** p_b_local,
111 size_t m, size_t B_k, size_t n)
116 double * a_local, *b_local;
118 a_local = malloc(sizeof(double) * m * B_k);
121 perror("Error allocation Matrix A");
125 b_local = malloc(sizeof(double) * B_k * n);
128 perror("Error allocation Matrix B");
132 *p_a_local = a_local;
133 *p_b_local = b_local;
135 // size_tialisation of the matrices
137 for( z=0; z<B_k; z++){
138 a_local[x*lda+z] = 0.0;
141 for( z=0; z<B_k; z++){
143 b_local[z*ldb+y] = 0.0;
148 void check_result(double *c, double *a, double *b,
149 size_t m, size_t n, size_t k_a, size_t k_b,
150 size_t row, size_t col,
151 size_t size_row, size_t size_col)
162 /* these variable could be use to check the result in function of the
163 * matrix initialization */
166 /*Display for checking */
168 XBT_INFO("Value get : %f excepted %zu multiply by y\n", c[((int)m/2)*ldc+1],size_row*k_a );
170 XBT_INFO("Value get : %f excepted %zu multiply by y\n", c[((int)m/2)*ldc+1], 1*(size_col*m)*((size_col*m)-1)/2) ;
174 /* WARNING this could be lead to some errors ( precision with double )*/
176 if ( fabs(c[x*ldc + y] - size_row*k_a) > 0.0000001)
178 if ( fabs(c[x*ldc + y] - y*(size_col*m)*((size_col*m)-1)/2) > 0.0000001)
182 XBT_INFO( "%f\t%zu, y : %zu x : %zu \n",
183 c[x*ldc+y], size_row*k_a, y, x);
185 XBT_INFO( "%f\t%zu, y : %zu x : %zu \n",
186 c[x*ldc+y], y*(size_col*m)*((size_col*m)-1)/2, y, x);
192 XBT_INFO("result check: ok\n");
195 XBT_INFO("result check not ok\n"
196 "WARNING the test could be lead to some "
197 "errors ( precision with double )\n");