#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();
}
How can i finish this flowchart by this program
Page 1 of 15 Replies - 549 Views - Last Post: 16 June 2009 - 11:39 PM
#1
How can i finish this flowchart by this program
Posted 16 June 2009 - 10:57 AM
Replies To: How can i finish this flowchart by this program
#2
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.
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.
#3
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;
}
#4
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
#5
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
#6
Re: How can i finish this flowchart by this program
Posted 16 June 2009 - 11:39 PM
Topics Merged, don't double post.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|