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, "Messages specific for this msg example");
12 #define _unused(x) ((void)x)
14 void matrices_initialisation(double ** p_a, double ** p_b, double ** p_c, size_t m, size_t k_a, size_t k_b, size_t n,
15 size_t row, size_t col)
23 double *a = malloc(sizeof(double) * m * k_a);
26 perror("Error allocation Matrix A");
30 double *b = malloc(sizeof(double) * k_b * n);
33 perror("Error allocation Matrix B");
37 double *c = malloc(sizeof(double) * m * n);
39 perror("Error allocation Matrix C");
47 // size_tialisation of the matrices
49 for( z=0; z<k_a; z++){
53 a[x*lda+z] = (double)(z+col*n);
57 for( z=0; z<k_b; z++){
62 b[z*ldb+y] = (double)(y);
73 void matrices_allocation( double ** p_a, double ** p_b, double ** p_c, size_t m, size_t k_a, size_t k_b, size_t n)
75 double *a = malloc(sizeof(double) * m * k_a);
78 perror("Error allocation Matrix A");
82 double *b = malloc(sizeof(double) * k_b * n);
85 perror("Error allocation Matrix B");
89 double *c = malloc(sizeof(double) * m * n);
91 perror("Error allocation Matrix C");
100 void blocks_initialisation( double ** p_a_local, double ** p_b_local, size_t m, size_t B_k, size_t n)
106 double *a_local = malloc(sizeof(double) * m * B_k);
109 perror("Error allocation Matrix A");
113 double *b_local = malloc(sizeof(double) * B_k * n);
116 perror("Error allocation Matrix B");
120 *p_a_local = a_local;
121 *p_b_local = b_local;
123 // size_tialisation of the matrices
125 for( z=0; z<B_k; z++){
126 a_local[x*lda+z] = 0.0;
129 for( z=0; z<B_k; z++){
131 b_local[z*ldb+y] = 0.0;
136 void check_result(double *c, double *a, double *b, size_t m, size_t n, size_t k_a, size_t k_b,
137 size_t row, size_t col, size_t size_row, size_t size_col)
148 /* these variable could be use to check the result in function of the
149 * matrix initialization */
151 /*Display for checking */
153 XBT_INFO("Value get : %f excepted %zu multiply by y\n", c[((int)m/2)*ldc+1],size_row*k_a );
155 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) ;
159 /* WARNING this could be lead to some errors ( precision with double )*/
161 if ( fabs(c[x*ldc + y] - size_row*k_a) > 0.0000001)
163 if ( fabs(c[x*ldc + y] - y*(size_col*m)*((size_col*m)-1)/2) > 0.0000001)
167 XBT_INFO( "%f\t%zu, y : %zu x : %zu \n", c[x*ldc+y], size_row*k_a, y, x);
169 XBT_INFO( "%f\t%zu, y : %zu x : %zu \n", c[x*ldc+y], y*(size_col*m)*((size_col*m)-1)/2, y, x);
175 XBT_INFO("result check: ok\n");
178 XBT_INFO("result check not ok\nWARNING the test could be lead to some errors ( precision with double )\n");