# include<stdio.h> # include \"/usr/include/sys/types.h\" # include \"/usr/include/sys/shm.h\" # include \"/usr/include/sys/ipc.h\" # include \"/usr/include/sys/sem.h\" # include\"forkjoin.h\" # include\"sharedlib.h\" int main() { int Mat[10][10]; int Vect[10]; int *resVect; int MatRow,MatCol; int iVal[100],kVal[100]; int iCount,jCount,kCount; int shmid1,shmid2; int Index=0,nProc,shmid[6],id; printf(\"Enter Number of Rows :\"); scanf(\"%d\",&MatRow); nProc=MatRow; printf(\"Enter Number of Columns :\"); scanf(\"%d\",&MatCol); resVect=(int *)sshared(sizeof(int)*MatRow,&shmid[0]); printf(\"\\n Enter Elements of Matrix ...\\n\"); for(iCount=0;iCount<MatRow;iCount++) { for(jCount=0;jCount<MatCol;jCount++) { printf(\"Mat[%d][%d] :\",iCount,jCount); scanf(\"%d\",&Mat[iCount][jCount]); } resVect[iCount]=0; } printf(\"\\n Enter Elements of Vector ...\\n\"); for(iCount=0;iCount<MatCol;iCount++) { printf(\"Vect[%d] :\",iCount); scanf(\"%d\",&Vect[iCount]); } for(iCount=0;iCount<MatRow;iCount++) { for(kCount=0;kCount<MatCol;kCount++) { iVal[Index] = iCount; kVal[Index] = kCount; Index++; } } printf(\"\\n Matrix ... \\n\"); for(iCount=0;iCount<MatRow;iCount++) { for(jCount=0;jCount<MatCol;jCount++) { printf(\"%d\\t\",Mat[iCount][jCount]); } printf(\"\\n\"); } printf(\"\\n Vector ... \\n\"); for(iCount=0;iCount<MatCol;iCount++) { printf(\"%d\\n\",Vect[iCount]); } id=process_fork(nProc); for(Index=id;Index<MatRow*MatCol;Index+=nProc) { iCount=iVal[Index]; kCount=kVal[Index]; resVect[iCount] += Mat[iCount][kCount]*Vect[kCount]; } process_join(nProc,id); printf(\"\\nMultiplication of Matrix and Vector is ...\\n\"); for(iCount=0;iCount<MatRow;iCount++) { printf(\"%d \\n\",resVect[iCount]); } return 0; }