mpi line with matrix exchange

This commit is contained in:
Fabio Salvini
2016-11-13 13:11:24 +01:00
parent df121930ad
commit 14541623a4
3 changed files with 73 additions and 28 deletions

View File

@@ -1,9 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
/*
* Create a matrix stored in a single array.
*/
double *create_sa_matrix(int rows, int cols) {
double *x;
@@ -11,21 +8,26 @@ double *create_sa_matrix(int rows, int cols) {
return x;
}
/*
* Destroy a single array matrix.
*/
void destroy_sa_matrix(double *x) {
free(x);
}
/*
* Get the index for the single array matrix
* that correspond to the given row and column.
*/
int sa_index(int cols, int r, int c) {
return r * cols + c;
}
void print_sa_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[sa_index(cols, i, j)]);
}
printf("\n");
}
fflush(stdout);
}
double **create_matrix(int rows, int cols) {
int i;
double **x;

View File

@@ -17,11 +17,27 @@ typedef struct borders {
} borders;
/*
* Create a matrix stored in a single array.
*/
double *create_sa_matrix(int rows, int cols);
/*
* Destroy a single array matrix.
*/
void destroy_sa_matrix(double *x);
/*
* Get the index for the single array matrix
* that correspond to the given row and column.
*/
int sa_index(int cols, int r, int c);
/*
* Print a single array matrix.
*/
void print_sa_matrix(double *x, int rows, int cols);
double **create_matrix(int rows, int cols);
void destroy_matrix(double **x, int rows);
void print_matrix(double **x, int rows, int cols);