hi there .. whats wrong with th e following code?

#include<mpi.h>
#include<stdio.h>
#include<math.h>

 void main(int argc, char **argv)
{


int rank, row, i, j,s,p ;
int n;
int oldrow,oldcol,newrow,newcol;
MPI_Status status;
int z;
int delta_x,delta_y;
int temp_map[60][40];
int map[60][40];
int col;
z=oldrow,oldcol,newrow,newcol;

temp_map=0;
map=0;
	

	printf("pls enter the row value\n");
	scanf("%d", &n);
	printf("you have enter the row %d\n",n);

	for (i=0; i<n; i++)
	{
		printf("pls enter row value %d:", i+1);
		scanf("%d", &row[i]);
	}

	printf("u hav input the numbers:\n");
	for (i=0; i<n; i++)
	{
		printf("%d\n", row[i]);
	}


	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &p);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);


s=n/p;
	if(rank==0)
	{
		for(i=0,row=0;i<48;i++,row=row+10);
		

		MPI_Send(&oldrow,s,MPI_INT,i,246,MPI_COMM_WORLD);

		for(i=0;i<40;i++)
			for(j=0;j<60;j++)
				temp_map[i][j]=0;

			for(i=0;i<(60*40);i++)
			{
			MPI_Recv(&oldrow,oldcol,newrow,newcol,1,MPI_INT,i,246,MPI_COMM_WORLD, &status);
			
			if((newrow<0)||(newrow<=40)||(newcol<0)||(newcol<=60));
			temp_map[newrow][newcol]=map[oldrow][oldcol];
			}

			for (i<0;i<40;i++)
				for(j=0;j<60;j++)
					map[i][j]=temp_map[i][j];

	}

	else 

		MPI_Recv(&oldrow,0,MPI_INT,i,246,MPI_COMM_WORLD,&status);

		for(oldrow=row;oldrow<(row+10);oldrow++)
			for(oldcol=col;oldcol<60;oldcol++)
			{
				newrow=oldrow+delta_x;
				newcol=oldcol+delta_y;

				MPI_Send(&oldrow,&oldcol,&newrow&newcol,0,MPI_INT,i,246,MPI_COMM_WORLD);
				
			}

MPI_Finalize();

	}

Recommended Answers

All 2 Replies

i sure wish you'd use CODE tags, when you post code, please. it will help me to help you if i can read your code.

anyhow... check your line:

for(i=0,row=0;i<48;i++,row=row+10);

it has a semicolon after it. so

MPI_Send(&oldrow,s,MPI_INT,i,246,MPI_COMM_WORLD);

is only executed once.

there may be other problems, i dunno. but i expect that's a big one.

> void main(int argc, char **argv)
main returns an int.

> int map[60][40];
The for loops which access this seem to think it's a [40][60] array.

> MPI_Recv(&oldrow,oldcol,newrow,newcol,1,MPI_INT,i,246,MPI_COMM_WORLD, &status);
1. where does 246 come from, it looks like a magic number to me.
2. newrow and newcol are uninitialised.

> if((newrow<0)||(newrow<=40)||(newcol<0)||(newcol<=60));
1. If newrow is < 0, is it also <= 40 ?
2. That ; at the end of the line does no good either.
3. newrow and newcol (as well as being uninitialised) are also constant in these loops.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.