欢迎来到天天文库
浏览记录
ID:54974907
大小:42.50 KB
页数:4页
时间:2020-04-25
《操作系统概念LAB4—矩阵相乘—实验报告.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、LAB4实验报告实验目的:1.矩阵相乘实验内容:给定两个矩阵A和B,其中A是具有M行、K列的矩阵,B为K行、N列矩阵,A和B的矩阵积为C,C为M行,N列。矩阵C中第i行、第j列的元素Ci,j就是矩阵A第i行每个元素和矩阵B第j列每个元素乘积的和。本实验的目的是通过对矩阵乘法是多线程实现,让学生加深对线程的理解与调用。实验步骤:在Linux操作系统上,利用Linux处理多线程的优点,编写程序用多线程实现矩阵乘法。实现A、B两个矩阵的乘法,并输出计算结果。实验代码如下:#include#include#include#i
2、nclude#include#include#defineRANGE100#defineM2#defineK2#defineN2voidgene_matrix();voidread_matrix();intmatrixA[M][N]={{1,1},{2,2}};intmatrixB[N][M]={{4,14},{5,25}};intarr[M][M][N];intres[M][N]={0};void*func(void*arg);main(){clock_tstart=clock();inti,j,k,cnt,c
3、nt2;pthread_ttids[N];for(i=0;i4、",i,j,res[i][j]);}clock_tfinish=clock();printf("n",(long)(finish-start)/1E6);}void*func(void*arg){intk=*(int*)arg;inti,j;printf("Enterfunc");for(i=0;i5、){FILE*file1,*file2;if((file1=fopen("/home/timelong/Desktop/matrixA","wt"))==NULL){perror("fopen");exit(1);}if((file2=fopen("/home/timelong/Desktop/matrixB","wt"))==NULL){perror("fopen");exit(1);}inti,j;srand((unsigned)time(NULL));for(i=0;i6、()%RANGE);fprintf(file1,"");}fclose(file1);for(i=0;i7、"/home/timelong/Desktop/matrixB","rt"))==NULL){perror("fopen");exit(1);}inti,j;for(i=0;i
4、",i,j,res[i][j]);}clock_tfinish=clock();printf("n",(long)(finish-start)/1E6);}void*func(void*arg){intk=*(int*)arg;inti,j;printf("Enterfunc");for(i=0;i5、){FILE*file1,*file2;if((file1=fopen("/home/timelong/Desktop/matrixA","wt"))==NULL){perror("fopen");exit(1);}if((file2=fopen("/home/timelong/Desktop/matrixB","wt"))==NULL){perror("fopen");exit(1);}inti,j;srand((unsigned)time(NULL));for(i=0;i6、()%RANGE);fprintf(file1,"");}fclose(file1);for(i=0;i7、"/home/timelong/Desktop/matrixB","rt"))==NULL){perror("fopen");exit(1);}inti,j;for(i=0;i
5、){FILE*file1,*file2;if((file1=fopen("/home/timelong/Desktop/matrixA","wt"))==NULL){perror("fopen");exit(1);}if((file2=fopen("/home/timelong/Desktop/matrixB","wt"))==NULL){perror("fopen");exit(1);}inti,j;srand((unsigned)time(NULL));for(i=0;i6、()%RANGE);fprintf(file1,"");}fclose(file1);for(i=0;i7、"/home/timelong/Desktop/matrixB","rt"))==NULL){perror("fopen");exit(1);}inti,j;for(i=0;i
6、()%RANGE);fprintf(file1,"");}fclose(file1);for(i=0;i7、"/home/timelong/Desktop/matrixB","rt"))==NULL){perror("fopen");exit(1);}inti,j;for(i=0;i
7、"/home/timelong/Desktop/matrixB","rt"))==NULL){perror("fopen");exit(1);}inti,j;for(i=0;i
此文档下载收益归作者所有