JacobiHPC/src/utils.c

57 lines
996 B
C
Raw Normal View History

2016-11-19 14:04:05 +01:00
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
2016-12-13 18:43:33 +01:00
float *create_sa_matrix(int rows, int cols) {
float *x;
2016-11-19 14:04:05 +01:00
2016-12-13 18:43:33 +01:00
x = (float *) malloc(rows * cols * sizeof(float));
2016-11-19 14:04:05 +01:00
return x;
}
2016-12-13 18:43:33 +01:00
void destroy_sa_matrix(float *x) {
2016-11-19 14:04:05 +01:00
free(x);
}
2016-12-13 18:43:33 +01:00
void print_sa_matrix(float *x, int rows, int cols) {
2016-11-19 14:04:05 +01:00
int i, j;
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("%f\t", x[IDX(cols, i, j)]);
}
printf("\n");
}
fflush(stdout);
}
2016-12-13 18:43:33 +01:00
float **create_matrix(int rows, int cols) {
2016-11-19 14:04:05 +01:00
int i;
2016-12-13 18:43:33 +01:00
float **x;
2016-11-19 14:04:05 +01:00
2016-12-13 18:43:33 +01:00
x = (float **) malloc(rows * sizeof(float));
2016-11-19 14:04:05 +01:00
for (i = 0; i < rows; i++) {
2016-12-13 18:43:33 +01:00
x[i] = (float *) malloc(cols * sizeof(float));
2016-11-19 14:04:05 +01:00
}
return x;
}
2016-12-13 18:43:33 +01:00
void destroy_matrix(float **x, int rows) {
2016-11-19 14:04:05 +01:00
int i;
for (i = 0; i < rows; i++) {
free(x[i]);
}
free(x);
}
2016-12-13 18:43:33 +01:00
void print_matrix(float **x, int rows, int cols) {
2016-11-19 14:04:05 +01:00
int i, j;
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("%f\t", x[i][j]);
}
printf("\n");
}
fflush(stdout);
}