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;
}