Cholesky算法的MPI并行C语言实现
包含以下内容:
(1)Cholesky的所用的正定矩阵的生成算法
(2)Cholesky的串行算法实现
(3)Cholesky的MPI并行算法实现
(4)完整的设计报告
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-11-10 14:32 Cholesky MPI并行C语言实现
文件 7936 2015-11-10 14:20 Cholesky MPI并行C语言实现cholesky.c
文件 1854464 2015-11-10 14:28 Cholesky MPI并行C语言实现Cholesky并行分解-实验报告.doc
/*
* INFO
* File: cholesky.c
* Date: 2015-10-21
* Author: Team of Zhangguoqing
*
* EXEC:
* Build: mpicc -o cholesky -lm cholesky.c
* Run: mpiexec -np numprocess ./cholesky matrix-order
* Note: matrix-order = m * numprocess
* Verify: http://www.yunsuanzi.com/matrixcomputations/solvecholeskyfactorization.html
*
* */
#include
#include
#include
#include
#include “mpi.h“
//Macro Definition
#define RANDMAX 10
void initMatrix(double *matrix int row int col)
{
int i j;
for(i=0; i
for(j=0; j matrix[i*col+j]=0;
}
}
}
void printMatrix(double *matrix int row int col)
{
int i j;
for(i=0; i
for(j=0; j printf(“%10.4f“ matrix[i*col+j]);
}
printf(“
“);
}
}
void printTriangleMatrix(double *matrix int order)
{
int i j;
for(i=0; i for(j=0; j<=i; j++){
printf(“%10.4f“ matrix[i*order+j]);
}
printf(“
“);
}
}
/*
* Function Purpose:
* Generate a positive random (semi-)definite matrices
*
* Method:
* Given an arbitrary matrix A compute M = AT * A
* AT means A‘s transposition (constructing a Cholesky decomposition)
*
* Reference:
* http://stackoverflow.com/questions/619335/a-simple-algorithm-for-generating-positive-semidefinite-matrices
*
* */
void generate(double *matrix int order)
{
int i j k;
double *ori_matrix = (double*)malloc(sizeof(double)*order*order);
double *tra_matrix = (double*)malloc(sizeof(double)*order*order);
//Generate origin matrix
printf(“##### Generate %d*%d semi-definite matrix #####
“ order order);
srand(time(0));
for(i=0; i for(j=0; j ori_matrix[i*order+j]=(double)(rand()%RANDMAX) + 1;
}
}
printf(“
Rand Arbitrary Matrix:
“);
printMatrix(ori_matrix order order);
//Transpose ori_matrix tra_matrix
for(i=0; i for(j=0; j tra_matrix[j*order+i] = ori_matrix[i*order+j];
}
}
printf(“
Transpose matrix:
“);
printMatrix(tra_matrix orderorder);
//matrix = ori_matrix * tra_matrix
for(i=0; i for(j=0; j for(k=0; k matrix[i*order+j] = matrix[i*order+j] + tra_matrix[i*order+k] * ori_matrix[k*order+j];
}
}
}
printf(“
Semi-definite Matrix one-dimension:
“);
printMatrix(matrix orderorder);
free(ori_matrix);
free(tra_matrix);
}
void serial_cholesky(double *A_matrix int order)
{
int i j k;
double sum;
double *matrix = (double*)malloc(sizeof(double)*order*order);
for(i=0;i for(j=0;j matrix[i*order+j] = A_matrix[i*order+j];
}
}
for(j=0; j sum = 0.0;
for(k=0; k sum += matrix[j*order+k] * matrix[j*order+k];
}
matrix[j*order+j] = matrix[j*order+j] - sum;
matrix[j*order+j] = sqrt(matrix[
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-11-10 14:32 Cholesky MPI并行C语言实现
文件 7936 2015-11-10 14:20 Cholesky MPI并行C语言实现cholesky.c
文件 1854464 2015-11-10 14:28 Cholesky MPI并行C语言实现Cholesky并行分解-实验报告.doc
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)