块矩阵版本Fox’;MPI中的s矩阵乘法(使用C)

块矩阵版本Fox’;MPI中的s矩阵乘法(使用C),c,matrix,mpi,block,multiplication,C,Matrix,Mpi,Block,Multiplication,我很长一段时间都在使用这个程序,所以基本上我必须在一个pxp笛卡尔网格上乘以2nxn矩阵,p 四, -11.0-12.06.09.0 -11.0 12.0 2.0 4.0 8.06.012.011.0 6.04.0-10.01.0 2.0 11.0 1.0 7.0 3.01.0-2.04.0 1.0 9.0 11.0 3.0 6.01.0-1.05.0 我能够使用进程0将矩阵读入两个数组A和B,但在程序的其余部分我需要一些帮助 #include <mpi.h>

我很长一段时间都在使用这个程序,所以基本上我必须在一个pxp笛卡尔网格上乘以2nxn矩阵,p

<矩阵A>

<矩阵B>


四,

-11.0-12.06.09.0
-11.0 12.0 2.0 4.0
8.06.012.011.0
6.04.0-10.01.0
2.0 11.0 1.0 7.0
3.01.0-2.04.0
1.0 9.0 11.0 3.0
6.01.0-1.05.0

我能够使用进程0将矩阵读入两个数组A和B,但在程序的其余部分我需要一些帮助

    #include <mpi.h> 
    #include <stdio.h> 
    #include <stdlib.h> 

    int main( int argc, char *argv[] ) 
    { 
    int p, rank, k, n;
     float *A = NULL, *B=NULL;
     char filename[FILENAME_MAX];
     //MPI_Status status;
     FILE *file;
     MPI_Init( &argc, &argv );
     MPI_Comm_size( MPI_COMM_WORLD, &p );
     MPI_Comm_rank( MPI_COMM_WORLD, &rank );

     // asks for filename
     if ( rank == 0 ) { 
     printf("p=%d", p);
     printf("Enter filename: ");
     scanf("%s", filename);

     // file is opened
     file = fopen(filename, "r");
     fscanf( file, "%d", &n );
     printf( "\nMatrix size = %d\n", n ); 
     // As per the expected format of the file the size of the matrix comes first in the file
     } 
     // broadcasts the value of n to all the processes
     MPI_Bcast( &n, 1, MPI_INT, 0, MPI_COMM_WORLD );

     if ( n*n > p ) 
     {
     // since p perfectly divides the n x n matrixes assumed
     if ( rank == 0 ) 
     { 
     printf( "No. of processes must be at least %d\n", n*n );
     fclose( file );
     } 
     MPI_Finalize( );
     exit( 1 );
     }

     //  Read and print input data matrix A and B 
     if ( rank == 0 ) 
     {

     A = (float *) malloc( n*n*sizeof(float) );
     printf( "\nMatrix A:\n" );
     for ( k=0;k<n*n; k++ ) 
     { 
     fscanf( file, "%f", &A[k] );
     printf( "%7.1f", A[k] );
     if ( (k+1)%n == 0 ) printf( "\n" );
     }
     // reads matrix B
     B = (float *) malloc( n*n*sizeof(float) ); 
     printf( "\nMatrix B:\n" );
     for ( k=0;k<n*n; k++ ) 
     { 
     fscanf( file, "%f", &B[k] );
     printf( "%7.1f", B[k] );
     if ( (k+1)%n == 0 ) printf( "\n" );
     } fclose( file );

     }

     MPI_Finalize( ); return 0; 
     }
#包括
#包括
#包括
int main(int argc,char*argv[])
{ 
int p,秩,k,n;
浮点*A=NULL,*B=NULL;
字符文件名[filename_MAX];
//MPI_状态;
文件*文件;
MPI_Init(&argc,&argv);
MPI通信大小(MPI通信世界和p);
MPI通信等级(MPI通信世界和等级);
//询问文件名
如果(秩==0){
printf(“p=%d”,p);
printf(“输入文件名:”);
scanf(“%s”,文件名);
//文件已打开
file=fopen(文件名为“r”);
fscanf(文件“%d”和(&n);
printf(“\n矩阵大小=%d\n”,n);
//根据文件的预期格式,矩阵的大小在文件中排在第一位
} 
//将n的值广播到所有进程
MPI_Bcast(&n,1,MPI_INT,0,MPI_COMM_WORLD);
如果(n*n>p)
{
//因为p完美地划分了假定的nxn矩阵
如果(秩==0)
{ 
printf(“进程数必须至少为%d\n”,n*n);
fclose(文件);
} 
MPI_Finalize();
出口(1);
}
//读取并打印输入数据矩阵A和B
如果(秩==0)
{
A=(浮动*)malloc(n*n*sizeof(浮动));
printf(“\n矩阵A:\n”);

对于(k=0;kPlease格式化您的帖子并缩进您的代码。哦,实际上我刚刚加入这个网站,我会这样做并重新发布,您能帮我开始吗?