資源簡(jiǎn)介
MPI源文件:Cannon并行實(shí)現(xiàn)及加速比分析
代碼片段和文件信息
/*
Cannon并行算法及其加速比分析【源代碼】
*/
#include?
#include?
#include?
#include?
#include?
#include?
/*?全局變量聲明?*/
float?**A?**B?**C?**D;???????????/*?總矩陣C?=?A?*?B?*/
float?*a?*b?*c?*tmp_a?*tmp_b;?/*?a、b、c表分塊,tmp_a、tmp_b表緩沖區(qū)?*/
int?dg?dl?dl2p?sp;????????????/*?dg:總矩陣維數(shù);dl:矩陣塊維數(shù);dl2=dl*dl;p:處理器個(gè)數(shù);sp=sqrt(p)?*/
int?my_rank?my_row?my_col;??????/*?my_rank:處理器ID;(my_rowmy_col):處理器邏輯陣列坐標(biāo)?*/
double?sTimepTime;
MPI_Status?status;
/*
?*函數(shù)名:?get_index
?*功能:處理器邏輯陣列坐標(biāo)至rank號(hào)的轉(zhuǎn)換
?*輸入:坐標(biāo)、邏輯陣列維數(shù)
?*輸出:rank號(hào)
?*/
int?get_index(int?row?int?col?int?sp)
{
???return?((row+sp)%sp)*sp?+?(col+sp)%sp;
}
//計(jì)算串行時(shí)間
void?chuanXing()
{
int?ijk;
double?t1t2;
t1=MPI_Wtime();
for(i=0;?i for(j=0;?j for(k=0;?k D[i][j]=A[i][k]*B[k][j];
t2=MPI_Wtime();
sTime=t2-t1;
}
/*
?*函數(shù)名:random_A_B
?*功能:隨機(jī)生成矩陣A和B
?*/
void?random_A_B()
{
???int?ij;
????srand((unsigned?int)tim
評(píng)論
共有 條評(píng)論