Hi. I am unable to run following code. Can anyone help me to know why this isn’t working? It’s written in openmpi. You can run it here codingame.com/playgrounds/349/introduction-to-mpi/hello-world (need to copy and paste)
```
#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
#define UPPER_LIMIT 4
#define master 0
int main(int argc, char *argv[])
{
int *data;
int process_id, total_process, temp_result;
int i, tag, final_result;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &process_id);
MPI_Comm_size(MPI_COMM_WORLD, &total_process);
MPI_Status status;
if ( total_process > UPPER_LIMIT )
{
if ( process_id == 0 )
printf("max allowed processes limit [%d] exceeded.\n", UPPER_LIMIT);
exit(0);
}
final_result = 0;
for ( i = 0; i < total_process; i++){
data[i] = (int)i;
}
int j;
for(j = 0; j < total_process; j++) {
printf("%d ", data[j]);
if(j==total_process-1)
printf("*** %d\n", process_id);
}
MPI_Scatter(data, total_process, MPI_INT, &temp_result, 1, MPI_INT, 0, MPI_COMM_WORLD);
if(process_id!=master){
temp_result = temp_result/process_id;
MPI_Reduce(&temp_result, &final_result, 1, MPI_INT, MPI_SUM, 1, MPI_COMM_WORLD);
}
if(final_result>0){
tag = process_id;
MPI_Send(&final_result, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
}
if(process_id==master){
MPI_Recv(&final_result, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
}
MPI_Finalize();
return 0;
}
```