'srun: error: distribution type `em' is not recognized

I wrote a c program for this equation,

enter image description here

I am trying to write down a mpi programming for the above formula.

#include <stdio.h>
#include <math.h>
#include<mpi.h>
double sum(int n);

int main(void){
int my_rank,comm_sz, n=1024;
double local_sum, total_sum;
int source;
int local_n;
MPI_Init(NULL,NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);

local_n=n/comm_sz;
local_sum=sum(local_n);

if ( my_rank != 0) {
 MPI_Send (&local_sum , 1, MPI_DOUBLE , 0, 0, MPI_COMM_WORLD ) ;
}

else{
 total_sum = local_sum;
 for(source=1;source<comm_sz;source++){
 MPI_Recv (&local_sum , 1, MPI_DOUBLE , source , 0, MPI_COMM_WORLD , MPI_STATUS_IGNORE ) ;
 total_sum+=local_sum;
}
}
MPI_Finalize();
return 0;

}

double sum(int n){
int i;
double cal_sum=0;
for (i =0;i <= n;i++) {
  cal_sum = cal_sum + 4*(pow (-1, i))/((2*i)+1);
}
return cal_sum;
}

run time Error:

srun: error: distribution type `em' is not recognized

Any idea when I get this error?

My srun command: srun -p node -n 4 -N 1 -pty -mem 1000 -t 10:00 bash



Solution 1:[1]

I think you can deduce the error simply by reading the error message and checking the corresponding part in your code.

Error Message:

[node070:100103] *** An error occurred in MPI_Recv
[node070:100103] *** MPI_ERR_RANK: invalid rank

Look at MPI_Recv in your code and you can see that you are receiving from rank n. There is no rank n. The maximum rank number you can get when size n is n-1.

MPI_Recv (&sum , 1, MPI_DOUBLE , n , 0, MPI_COMM_WORLD , MPI_STATUS_IGNORE ) ;

You should replace n with i in your MPI_Recv.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1