I need to send an array of char and a counter to the master process. My idea was to define an mpi type and send it later to the master. The array is variable size and needs to be created from a char pointer. Basically the processes have this data structure:
struct WordCounter
{
char *word;
int word_count;
struct WordCounter *pNext; /* Pointer to the next word counter in the list */
};
What I need to do is to try to send char * word and int word count to the master, so char*word must be copied into an array of char without pointer. How should I define the new mpi data type?
My idea is to use this struct and commit it as Mpi data type, but how i should manage the construction? I can take the dimension of char *word and using inside the struct to commit.
struct WordAndCount
{
char word[n]; // n varies according to the length of the word
int count;
};
What im trying to do is:
MPI_Init(&argc,&argv);
int world_size,rank;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
MPI_Comm_rank (MPI_COMM_WORLD,&rank);
MPI_Datatype wordinfo,oldtype[1];
MPI_Aint offset[1],lw,extent;
int blockcounts[1];
offset[0] = 0;
oldtype[0] = MPI_CHAR;
blockcounts[0] = 1;
After this i can't go on, im a newbie with mpi, can you help me? Another thing is how i can copy the char pointer inside at the static array. I can do it with a simple for that loop the pointer and copy the char inside to array?
An example is:
Master builded his WordCounter that contains: Hello (word) 1(counter), Hi 2, etc... Process 1 builded his WordCounter that contains: Hello 3, hi 4. Process 2 builded his WordCounter that contains: hi 8, hello 3, sun 5.
Master needs to recive through a gather at first round hello 3 (from process1), hi 8 (from process 2). At second round hi 4 (from process 1) hello 3 (from process 2) and so on.