hello
I am trying to send an array of character but when i receive it in the other processor i receive it with garbage !!! any suggestion?

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

int main (int argc, char *argv[])
{  
	MPI_Status s;
   int size, rank;
   char line [128]; 
   //char* str="hjfjh";
   static const char filename[] = "file.txt";
   MPI_Init (&argc, &argv);
   MPI_Comm_size (MPI_COMM_WORLD, &size);
   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
   
   if (rank == 0) // Master process
   { 
 
   FILE *file = fopen ( filename, "r" );
   if ( file != NULL )
   {
     /* or other suitable maximum line size */
 
      while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
      {
         //fputs ( line, stdout ); /* write the line */
 
		  MPI_Send ((void *)&line, 1, MPI_CHAR, 1, 0xACE5, MPI_COMM_WORLD);     

	  }
      fclose ( file );
   }
   else
   {
      perror ( filename ); /* why didn't the file open? */
   }
  
   }

   else
   { 
	    printf ("Receiving data . . .\n");
		printf("\n\n line %s\n",line);
   
      {
		  MPI_Recv (&line, 1, MPI_CHAR, 0, 0xACE5, MPI_COMM_WORLD, &s);
          printf ("[%d] sent %s\n", 0, line);
      }
   }
 
   MPI_Finalize();
   return 0;
}
MPI_Send ((void *)&line, 1, MPI_CHAR, 1, 0xACE5, MPI_COMM_WORLD);

I think (can't test it unfortunately) should be:

MPI_Send (line, strlen(line)+1, MPI_CHAR, 1, 0xACE5, MPI_COMM_WORLD);

since line is a char array it is already a pointer.

http://cboard.cprogramming.com/c-programming/125718-mpi-send-message.html
http://forums.devshed.com/c-programming-42/mpi-send-message-693881.html
Any more places where people are wasting time repeating the same answers?

Help on forums is a finite resource, so for you to go around wasting that by getting the same answers from different people is pretty darn selfish IMO.

commented: I deem it "monte carlo posting", must be the latest thing... :( +4

http://cboard.cprogramming.com/c-programming/125718-mpi-send-message.html
http://forums.devshed.com/c-programming-42/mpi-send-message-693881.html
Any more places where people are wasting time repeating the same answers?

Help on forums is a finite resource, so for you to go around wasting that by getting the same answers from different people is pretty darn selfish IMO.

Sir, its not selfish , I know that i was wrong when i post it in more than one forum but i was in really deep need to answer my question ASAP
as i have a lot to do depending on that answer !!!

commented: well, since your time is so much more important, i guess it's okay then. -1
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.