资源简介

基于MPI并行计算的高斯消元法程序,一个课程设计的任务。

资源截图

代码片段和文件信息

#include

#include

#include“mpi.h“

#include“stdio.h“

#include

const int rows = 3; /*the rows of matrix*/

const int cols = 3; /*the cols of matrix*/

int main(int argc char **argv)



{

int ijkmyidnumprocsanstag;

double  A[rows][cols]B[cols]X[rows]AB[rows][cols+1];

int masterpro;

double buf[cols+1];

double starttimeendtime;

double tmptotaltime;

srand((unsigned int)time(NULL));

MPI_Status status;

masterpro = 0;

MPI_Init(&argc&argv);

MPI_Comm_rank(MPI_COMM_WORLD&myid);

MPI_Comm_size(MPI_COMM_WORLD&numprocs);

if (myid==0)

    {

      starttime = MPI_Wtime();

      printf(“please input xishu“);

      for(i=0;i
         {

            for(j=0;j
                 {

                    scanf(“%lf“&A[i][j]);

                 }

          }

      printf(“please input changshu“);

for(i=0;i
        {

    scanf(“%lf“&B[i]);

  }

 for (i=0;i
          {



             AB[i][cols]=B[i];

             for(j=0;j
             AB[i][j]=A[i][j];

           }

       printf(“zengguang\n“);

       for(i=0;i
{

               for(j=0;j
               printf(“%.2f “AB[i][j]);

               printf(“\n“);

            }

   }

int x;

double coe;

for(x=0;x
   {

       MPI_Bcast(&AB[x][0]cols+1MPI_DOUBLE0MPI_COMM_WORLD);

       if(myid==0)

            {

              for(i=1;i
                {

                  for(k=x+1+i;k
                  MPI_Send(&AB[k][0]cols+1MPI_DOUBLEi0MPI_COMM_WORLD);

                }

               for(k=x+1;k
                 {

                   coe=AB[k][x]/AB[x][x];

                   for(j=x;j
                      {

                       AB[k][j]-=AB[x][j]*coe;

                      }

                  }

               for(i=1;i
                  {

                    for(k=x+1+i;k
                    {

                     MPI_Recv(&AB[k][0]cols+1MPI_DOUBLEi1MPI_COMM_WORLD&status);

                    }

                  }

   

评论

共有 条评论