⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix_multiply.c

📁 一个计算矩阵乘的程序,程序很简单,请大家帮忙检查下
💻 C
字号:
#include "mpi.h"#include <stdio.h>//count the multiply of martrix A and B//The number of processes of this program requires is size+1intmain (int argc, char *argv[]){  int i, j, rank, size;  float a[10][10], b[10][10], temp[10];  MPI_Status status;  MPI_Init (&argc, &argv);  MPI_Comm_rank (MPI_COMM_WORLD, &rank);  MPI_Comm_size (MPI_COMM_WORLD, &size);  if (rank != 0)    {      for (i = 0; i < 10; i += 1)	for (j = 0; j < 10; j += 1)	  {	    a[i][j] = 1.0;	    b[i][j] = 1.0;	  }      for (i = 0; i < 10; i += 1)	//i infers the column of c, it's to say in the result martrix	{	  temp[i] = 0;		// the whole name is c[rank][i]	  for (j = 0; j < 10; j += 1)	// j infers the column of a , it's to say the row of b	    {	      temp[i] += a[rank+1][j] * b[j][i];	    }	  MPI_Send (temp, 10, MPI_FLOAT, 0, rank, MPI_COMM_WORLD);	}    }  else    {      float c[10][10];      for (i = 0; i < 10; i += 1)	{	  MPI_Recv (temp, 10, MPI_FLOAT, MPI_ANY_SOURCE, MPI_ANY_TAG,			MPI_COMM_WORLD, &status);	  c[status.MPI_SOURCE-1][i] = temp[i];	}      for (i = 0; i < 10; i += 1)	{	  printf ("\n");	  for (j = 0; j < 10; j += 1)	    printf ("%f ", c[i][j]);	}    }  MPI_Finalize ();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -