5 Replies - 612 Views - Last Post: 16 June 2009 - 11:39 PM Rate Topic: -----

#1 x_man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-June 09

How can i finish this flowchart by this program

Posted 16 June 2009 - 10:57 AM

#include <conio.h>
#include< mpi.h> 
 #includ<iostream.h>
 #include<math.h> 
 #include<windows.h> 
 #defineROOT0 
 
 usingnamespace std; 
 
 void main(INT argc, CHAR* argv[]) 
 { 
		 int i,j; 
		 int r; 
		 int a[6][6],b[6][6],x[6][6],q[6][6];x[i][j];q[i][j]; 
 	 INT *matrix1; 
 	INT *matrix2; 
 	INT *row; 
 	 INT *result; 
 	 INT small_result; 
 	 INT iRank; 
 	 INT   iNtasks; 
 	 BOOL flag = TRUE; 
 	 INT n;   / / rows in matrix   
 	 INT m;   / / colls in matrix 
 	INT nm[2]; //sending buffer for n,m 
 	MPI_Init(&argc,&argv); 
 	 MPI_Comm_rank(MPI_COMM_WORLD, &iRank); 
 	 MPI_Comm_size(MPI_COMM_WORLD, &iNumTasks); 
 	 / /  creating  matrix 
 	if (iRank == ROOT) 
 	 { 
 	 	 cout<<"NumTasks="<<iNumTasks; 
 	 	 do 
 	 	 { 
 			 cout<<"Enter n,m"<<endl; 
 	 	 cin>>n>>m; 
 	 	 if(n> (iNumTasks)) 
 	 	 	cout<<"n != iNumTasks, iNumTasks = "<<iNumTasks<<" Repeat plz!"<<endl; 
 	 	 else flag = FALSE; 
 	 	 } 
 			 while  (flag); 
 	 	 matrix1 = (INT *) malloc (sizeof(INT)*n*m); 
 	 	 matrix2 = (INT *) malloc (sizeof   (INT)*n*m); 
 	 	result = (INT *) malloc (sizeof(INT)*n); 
 	 	cout<<"generating data"<<endl; 
 	 	 / / generating  matrix  
 	 	 for ( i=0;i<n;i++) 
 	 		for ( j=0;j<m;j++) 
	 	 	 	 matrix[i][j]=INT(i+j); 
 	 	 nm[0]=n; 
 	 	nm[1]=m; 
 	 	cout<<"generating data end"<<endl; 
 	 } 
 	 / / send nm in nm [] using  bcast 
 	MPI_Bcast(&nm   , MPI_INT, ROOT, MPI_COMM_WORLD); 
 	 { 
 	 	 i=nm[0]; 
 	 	 j=nm[1]; 
 		row = (INT *) malloc (sizeof(INT)*m); 
 	 } 
 	 MPI_Barrier(MPI_COMM_WORLD); 
	   / / sending  parts of matrix 
	MPI_Scatter(a[i][j], m, MPI_INT,&matrix1, m, MPI_INT, ROOT ,   MPI_COMM_WORLD); 
 	if (iRank ==0 ) 
 	 	 cout<<"mpi_scatter matrix done"<<endl; 
 	 / / sending  rows of matrix 
 	 MPI_Barrier(MPI_COMM_WORLD); 
 	 MPI_Scatter (b[i][j] ,m , MPI_INT ,matrix2, m, MPI_INT,ROOT  ,MPI_COMM_WORLD); 
	   if   (iRank==0) 
 	 	 cout << "mpi_scatter   matrix   done " <<endl; 
 	 MPI _ Barier (MPI_COMM_WORLD); 
 	 { 
 	 	 small_result  =  0; 
	   for  ( i=0;i<n;i++) 
					{ 
 
					 for   (j=0;j<m;j++) 
 	 		   { 
 	 			 small_result=a[i][j]+b[i][j];
									  q[i][j]+x[i][j];  
 	 			}										} 
 	 } 
 	 if   (iRank==0 ) 
 	 	 cout << "calculation   done"<< endl; 
 	 / / Gathering  small_result to result[] 
 	 MPI_Barrier (MPI_COMM_WORLD); 
 	 MPI_Gather (&small_result,m,MPI_INT,result,m,MPI_INT,ROOT,MPI_COMM_WORLD); 
 	 if   (iRank==0) 
 	 	 cout << "gather done"<<endl; 
 	 if   (iRank==0) 
 	 { 
 	 	 / / matrix 1
 	 	 for   (i=0;i<n;i++) 
	   	 { 
 	 	 	 for (j=0;j<m;j++) 
 	 	 	 	 cout<<c[i][j]<<" "; 
 	 	 	 cout<<endl; 
 	 	 } 
 	 	 / / matrix 2
 	 	 cout<<endl; 
 	 	 for (j=0;j<n;j++) 
 	 	 	 cout<<c[i][j]<<endl; 
 	 	 cout<<endl; 
 	 	 / / result  matrix 
 	 	for (j=0;j<n;j++) 
 
 	 	 	 cout<<result[i][j]<<endl; 
				  cout<<endl; 
			   	 } 
				  MPI_Finalize(); 
 
 }


Is This A Good Question/Topic? 0
  • +

Replies To: How can i finish this flowchart by this program

#2 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: How can i finish this flowchart by this program

Posted 16 June 2009 - 11:47 AM

Nobody out here is going to solve your problem completely and hand it over to you.
Attempt it yourself and post whatever you've done here and we'll help you with the rest of the flowchart.
If you've never worked with flowcharts before, click here.
Was This Post Helpful? 0
  • +
  • -

#3 computerfox  Icon User is offline

  • straight vegetarian kid

Reputation: 50
  • View blog
  • Posts: 3,772
  • Joined: 29-January 09

Re: How can i finish this flowchart by this program

Posted 16 June 2009 - 12:10 PM

void yourAnswer(){
while(0==0){
cout<<"So what seems to be the problem...\n";
cout<<"We here at DIC don't do your work for you...\n";
cout<<"We only help with code presented...\n";
cout<<"Please edit your post with your code and specific question...\n";
cout<<"Thank you...\n";
}
return;
}


Was This Post Helpful? 0
  • +
  • -

#4 x_man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-June 09

Re: How can i finish this flowchart by this program

Posted 16 June 2009 - 11:09 PM

#include <conio.h>
#include< mpi.h> 
 #includ<iostream.h>
 #include<math.h> 
 #include<windows.h> 
 #defineROOT0 
 
 usingnamespace std; 
 
 void main(INT argc, CHAR* argv[]) 
 { 
		 int i,j; 
		 int r; 
		 int a[6][6],b[6][6],x[6][6],q[6][6];x[i][j];q[i][j]; 
 	 INT *matrix1; 
 	INT *matrix2; 
 	INT *row; 
 	 INT *result; 
 	 INT small_result; 
 	 INT iRank; 
 	 INT   iNtasks; 
 	 BOOL flag = TRUE; 
 	 INT n;   / / rows in matrix   
 	 INT m;   / / colls in matrix 
 	INT nm[2]; //sending buffer for n,m 
 	MPI_Init(&argc,&argv); 
 	 MPI_Comm_rank(MPI_COMM_WORLD, &iRank); 
 	 MPI_Comm_size(MPI_COMM_WORLD, &iNumTasks); 
 	 / /  creating  matrix 
 	if (iRank == ROOT) 
 	 { 
 	 	 cout<<"NumTasks="<<iNumTasks; 
 	 	 do 
 	 	 { 
 			 cout<<"Enter n,m"<<endl; 
 	 	 cin>>n>>m; 
 	 	 if(n> (iNumTasks)) 
 	 	 	cout<<"n != iNumTasks, iNumTasks = "<<iNumTasks<<" Repeat plz!"<<endl; 
 	 	 else flag = FALSE; 
 	 	 } 
 			 while  (flag); 
 	 	 matrix1 = (INT *) malloc (sizeof(INT)*n*m); 
 	 	 matrix2 = (INT *) malloc (sizeof   (INT)*n*m); 
 	 	result = (INT *) malloc (sizeof(INT)*n); 
 	 	cout<<"generating data"<<endl; 
 	 	 / / generating  matrix  
 	 	 for ( i=0;i<n;i++) 
 	 		for ( j=0;j<m;j++) 
	 	 	 	 matrix[i][j]=INT(i+j); 
 	 	 nm[0]=n; 
 	 	nm[1]=m; 
 	 	cout<<"generating data end"<<endl; 
 	 } 
 	 / / send nm in nm [] using  bcast 
 	MPI_Bcast(&nm   , MPI_INT, ROOT, MPI_COMM_WORLD); 
 	 { 
 	 	 i=nm[0]; 
 	 	 j=nm[1]; 
 		row = (INT *) malloc (sizeof(INT)*m); 
 	 } 
 	 MPI_Barrier(MPI_COMM_WORLD); 
	   / / sending  parts of matrix 
	MPI_Scatter(a[i][j], m, MPI_INT,&matrix1, m, MPI_INT, ROOT ,   MPI_COMM_WORLD); 
 	if (iRank ==0 ) 
 	 	 cout<<"mpi_scatter matrix done"<<endl; 
 	 / / sending  rows of matrix 
 	 MPI_Barrier(MPI_COMM_WORLD); 
 	 MPI_Scatter (b[i][j] ,m , MPI_INT ,matrix2, m, MPI_INT,ROOT  ,MPI_COMM_WORLD); 
	   if   (iRank==0) 
 	 	 cout << "mpi_scatter   matrix   done " <<endl; 
 	 MPI _ Barier (MPI_COMM_WORLD); 
 	 { 
 	 	 small_result  =  0; 
	   for  ( i=0;i<n;i++) 
					{ 
 
					 for   (j=0;j<m;j++) 
 	 		   { 
 	 			 small_result=a[i][j]+b[i][j];
									  q[i][j]+x[i][j];  
 	 			}										} 
 	 } 
 	 if   (iRank==0 ) 
 	 	 cout << "calculation   done"<< endl; 
 	 / / Gathering  small_result to result[] 
 	 MPI_Barrier (MPI_COMM_WORLD); 
 	 MPI_Gather (&small_result,m,MPI_INT,result,m,MPI_INT,ROOT,MPI_COMM_WORLD); 
 	 if   (iRank==0) 
 	 	 cout << "gather done"<<endl; 
 	 if   (iRank==0) 
 	 { 
 	 	 / / matrix 1
 	 	 for   (i=0;i<n;i++) 
	   	 { 
 	 	 	 for (j=0;j<m;j++) 
 	 	 	 	 cout<<c[i][j]<<" "; 
 	 	 	 cout<<endl; 
 	 	 } 
 	 	 / / matrix 2
 	 	 cout<<endl; 
 	 	 for (j=0;j<n;j++) 
 	 	 	 cout<<c[i][j]<<endl; 
 	 	 cout<<endl; 
 	 	 / / result  matrix 
 	 	for (j=0;j<n;j++) 
 
 	 	 	 cout<<result[i][j]<<endl; 
				  cout<<endl; 
			   	 } 
				  MPI_Finalize(); 
 
 }


Mod edit - Please :code:
Was This Post Helpful? 0
  • +
  • -

#5 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1105
  • View blog
  • Posts: 6,918
  • Joined: 07-September 06

Re: How can i finish this flowchart by this program

Posted 16 June 2009 - 11:21 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,449
  • Joined: 10-May 07

Re: How can i finish this flowchart by this program

Posted 16 June 2009 - 11:39 PM

Topics Merged, don't double post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1