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

📄 matrix_mult_slave.c

📁 A Parallel program to multiply two matrices using Parallel Virtual Machine(PVM).Also a document to i
💻 C
字号:
#include<stdio.h>#include<pvm3.h>#include<malloc.h>main(){	int rows,ncola,ncolb,mtype,mtid,stid,retcode,*a,*b,*c,nelements,i,j,k;	FILE *fp;	mtype = 1;        if ((fp = fopen("matrix.log", "w")) == NULL){                        printf("Can't Open Output File \n");         }	stid = pvm_mytid();	mtid = pvm_parent();	retcode = pvm_recv(mtid,mtype);	retcode = pvm_upkint(&rows,1,1);	retcode = pvm_upkint(&ncola,1,1);	retcode = pvm_upkint(&ncolb,1,1);	a = (int*)malloc(rows*ncola*sizeof(int));	b = (int*)malloc(ncola*ncolb*sizeof(int));	retcode = pvm_upkint(a,rows*ncola,1);	retcode = pvm_upkint(b,ncola*ncolb,1);	fprintf(fp,"rows = %d\tcola=%d\tcolb=%d",rows,ncola,ncolb);	c = (int*)malloc(ncola*ncolb*sizeof(int));		for(i = 0; i < rows; i++)	for(j = 0; j < ncolb; j++){		c[i * ncolb+j] = 0;		for(k = 0; k < ncola; k++)			c[i*ncolb+j]+=a[i*ncola+k]*b[k*ncolb+j];	}		fprintf(fp,"\n the resulting matrix in the processor %d is",stid);	for(i = 0; i<rows;i++)        for(j = 0; j <ncolb;j++)       	fprintf(fp,"%d  ",c[i*ncolb+j]);        fprintf(fp,"\n");		mtype = 2;	nelements = rows*ncolb;	retcode = pvm_initsend(PvmDataDefault);	retcode = pvm_pkint(&nelements,1,1);	retcode = pvm_pkint(&c[0],nelements,1);	retcode = pvm_send(mtid,mtype);	pvm_exit();	}

⌨️ 快捷键说明

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