Heap memory for matrix and elapsed time

This commit is contained in:
Fabio Salvini
2016-11-12 21:53:11 +01:00
parent 85c3977901
commit 784416b7ca
8 changed files with 115 additions and 37 deletions

34
utils/utils.c Normal file
View File

@@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
double **create_matrix(int rows, int cols) {
int i;
double **x;
x = (double **) malloc(rows * sizeof(double));
for (i = 0; i < rows; i++) {
x[i] = (double *) malloc(cols * sizeof(double));
}
return x;
}
void destroy_matrix(double **x, int rows) {
int i;
for (i = 0; i < rows; i++) {
free(x[i]);
}
free(x);
}
void print_matrix(double **x, int rows, int cols) {
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);
}

22
utils/utils.h Normal file
View File

@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
/* #define ENABLE_LOG */
#ifdef ENABLE_LOG
# define LOG(x) x
#else
# define LOG(x) (void) 0
#endif
typedef struct borders {
double north;
double east;
double south;
double west;
} borders;
double **create_matrix(int rows, int cols);
void print_matrix(double **x, int rows, int cols);
void destroy_matrix(double **x, int rows);