Im having troubles with the following code
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
//1 mostrar lista
//2 borrar elementos
//3 ordenar lista
//4 añadir elemento
int main(int argc,char**argv){
int rank;
int *list; //Lista
int *liste; //Lista encargados
int *perm; //Permutaciones
int *capa; //Capacidad
int size;
int i;
int aux;
const int root = 0;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
if(rank==root){
perm = (int*)malloc(size*sizeof(int));
capa = (int*)malloc(size*sizeof(int));
for(i=0;i<size;i++){
scanf("%d",&aux);
capa[i]=aux;
}
for(i=0;i<size;i++){
scanf("%d",&aux);
perm[i]=aux;
}
}
//printf("\n[%d]: Antes de Bcast: %d %d %d %d\n",rank,capa[0],capa[1],capa[2],capa[4]);
MPI_Bcast(&capa[0],size,MPI_INT,root,MPI_COMM_WORLD);
MPI_Bcast(&perm[0],size,MPI_INT,root,MPI_COMM_WORLD);
//MPI_Bcast(&aux,1,MPI_INT,root,MPI_COMM_WORLD);
printf("\n[%d]: Despues de Bcast capa: %d %d %d %d\n",rank,capa[0],capa[1],capa[2],capa[3]);
printf("\n[%d]: Despues de Bcast perm: %d %d %d %d\n",rank,perm[0],perm[1],perm[2],perm[3]);
MPI_Finalize();
return 0;
}
Well there is nothing special, Im just trying to Bcast two arrays of ints (for now Im trying with 4-lenght strings of ints, that why the last printfs are statics).
Anyway, I tried first just with the "capa" string and it worked, but when I tried it with both strings, Im getting a segmentation fault error but I dont know why, both string are the same size, the only differences are their values.
EDIT:
Just changed the code to this and worked:
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
//1 mostrar lista
//2 borrar elementos
//3 ordenar lista
//4 añadir elemento
int main(int argc,char**argv){
int rank;
int *list; //Lista
int *liste; //Lista encargados
int *perm; //Permutaciones
int *capa; //Capacidad
int size;
int i;
int aux;
const int root = 0;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
perm = (int*)malloc(size*sizeof(int));
capa = (int*)malloc(size*sizeof(int));
if(rank==root){
for(i=0;i<size;i++){
scanf("%d",&aux);
capa[i]=aux;
}
for(i=0;i<size;i++){
scanf("%d",&aux);
perm[i]=aux;
}
}
//printf("\n[%d]: Antes de Bcast: %d %d %d %d\n",rank,capa[0],capa[1],capa[2],capa[4]);
MPI_Bcast(&capa[0],size,MPI_INT,root,MPI_COMM_WORLD);
MPI_Bcast(&perm[0],size,MPI_INT,root,MPI_COMM_WORLD);
//MPI_Bcast(&aux,1,MPI_INT,root,MPI_COMM_WORLD);
printf("\n[%d]: Despues de Bcast capa: %d %d %d %d\n",rank,capa[0],capa[1],capa[2],capa[3]);
printf("\n[%d]: Despues de Bcast perm: %d %d %d %d\n",rank,perm[0],perm[1],perm[2],perm[3]);
MPI_Finalize();
return 0;
}