Added C functions for linear algebra, to be converted to kraken and used as benchmark

This commit is contained in:
Chris Fadden
2015-03-18 18:35:00 -04:00
parent a268f1b768
commit d2fc32d0fb
12 changed files with 386 additions and 58 deletions

View File

@@ -0,0 +1,84 @@
#include <stdlib.h>
/*********************
* Matrix Transpose
*
* No real concept of vector transpose
* in this kraken implementation
* *******************/
void transpose(int m, int n, double** A)
{
int i, j;
/******************************
* Allocate memory for tmp array
* ***************************/
double** A_trans;
A_trans = malloc(sizeof(double*) * m);
for(i = 0; i < m; i++)
{
A_trans[i] = malloc(sizeof(double) * n);
}
/*********************
* Copy A into tmp
********************/
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
A_trans[i][j] = A[i][j];
}//end j loop
}//end i loop
/***************
* Transpose operation
***************/
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
A[i][j] = A_trans[j][i];
}//end j loop
}//end i loop
/**********
* Free Memory
* *******/
for(i = 0; i < m; i++)
free(A_trans[i]);
free(A_trans);
}//end transpose function
void multiply(int m, int n, int q, double** A, double** B, double**C)
{
//Kraken: check if C is empty, then allocate memory
return;
}
void printMatrix(int m, int n, double** A)
{
int i, j;
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
printf("%f ",A[i][j]);
}//end j loop
printf("\n");
}//end i loop
printf("\n");
}//end print function

View File

@@ -0,0 +1,31 @@
#include <stdio.h>
#include "ChrisMatrix.h"
int main(int argc, char** argv)
{
double** A;
int m = 3;
int n = 3;
int i, j;
A = malloc(sizeof(double*) * m);
for(i = 0; i < m; i++)
A[i] = malloc(sizeof(double) * n);
int k = 0;
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
A[i][j] = k;
k++;
}//end j loop
}//end i loop
printMatrix(m, n, A);
transpose(m,n,A);
printMatrix(m,n,A);
printf("Hello World\n");
return 0;
}