#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <mpi.h>
int main(int argc, char **argv)
{
int size;
int rank;
int tag;
int chunksize;
int letters[26];
int start;
int lineCount;
int result[26];
int Addletters[26];
unsigned char c;
char *data;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank==0){
FILE *file;
file = fopen("WarAndPeace.txt", "r");
while ((c = getc(file)) != EOF){
if ( isalpha (c)) {
lineCount++;
}
}
fclose(file);
data = (char*)malloc(sizeof(char) * lineCount);
chunksize = lineCount/size;
int remainder = lineCount%size;
file = fopen("WarAndPeace.txt", "r");
int n=0;
while ((c = getc(file)) != EOF){
if ( isalpha (c)) {
data[n] = tolower(c);
n++;
}
}
fclose(file);
for(int i= 1; i<size; i++){
start = i*chunksize;
MPI_Send(&(data[start]), chunksize, MPI_BYTE, i, tag, MPI_COMM_WORLD);
if(i == (size-1)){
chunksize + remainder;
}
}
for(int i= 1; i<size; i++){
MPI_Recv(&result, 1, MPI_BYTE, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(int i=0; i<26; i++){
Addletters[i]+=result[i];
}
}
for(int c=0; c<26; c++){
printf("%c \t %d\n", c + 'a', Addletters[c]);
}
}else{
MPI_Recv(&data, chunksize, MPI_BYTE, 0, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(int i=0; i<chunksize; i++){
if(data[i]>='a' && data[i]<='z'){
letters[data[i]-'a']++;
}
}
MPI_Send(&letters, 1, MPI_BYTE,0,tag,MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}
[tl-03:3093864] *** An error occurred in MPI_Recv
[tl-03:3093864] *** reported by process [1716191233,3]
[tl-03:3093864] *** on communicator MPI_COMM_WORLD
[tl-03:3093864] *** MPI_ERR_COUNT: invalid count argument
[tl-03:3093864] *** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
[tl-03:3093864] *** and potentially your MPI job)
[tl-03:3093851] PMIX ERROR: UNREACHABLE in file ../../../src/server/pmix_server.c at line 2193
[tl-03:3093851] 1 more process has sent help message help-mpi-errors.txt / mpi_errors_are_fatal
[tl-03:3093851] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages
i am trying to count the occurence of letters in a text file. In this programme, i have to read the text file in rank 0 which is what i have done and also i have to send chunks of the data to the other processors . The other processes should be able to count the letters and send them back . please tell me where i am going wrong Thanks in advance