Napisałem program, który przesyła dwuwymiarową tablicę między procesami. Tablice wyświetla tylko proces root, a sam program po jej wyświetleniu wyrzuca mi błąd
YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]){
MPI_Init(&argc,&argv);
int rank, num_procs;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
int i, j;
int tab_size;
double **tab;
if(rank == 0){
FILE *fp;
double a, b;
fp = fopen("dane.txt", "r");
fscanf(fp, "%d", &tab_size);
tab = malloc(tab_size * sizeof(double*));
for(i = 0; i < tab_size; ++i){
tab[i] = malloc(2 * sizeof(double));
fscanf(fp ,"%lf %lf", &a, &b);
tab[i][0] = a;
tab[i][1] = b;
}
close(fp);
}
MPI_Bcast(&tab_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
if(rank != 0 ){
tab = malloc(tab_size * sizeof(double*));
if( rank != 0 ){
for(i = 0; i < tab_size; ++i){
tab[i] = malloc(2 * sizeof(double));
}
}
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Bcast(&tab, tab_size*2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
for(i = 0; i < tab_size; i++)
printf("%d : %lf, %lf\n", rank, tab[i][0], tab[i][1]);
for(i=0; i<tab_size; i++)
free(tab[i]);
free(tab);
MPI_Finalize();
return 0;
}