Hi to all,
In the example code below I was wondering how to Scatter
Code:
struct chromosome{
double fitness;
double genes[NUM_OF_GENES];
double up_limit[NUM_OF_GENES];
double low_limit[NUM_OF_GENES];
};
struct chromosome old_chrome[NUM_OF_CHROMES];
how I bcast old_chrome element
Code:
/* Set up the 4 blocks */
int blockCounts[4] = {1,NUM_OF_GENES,NUM_OF_GENES,NUM_OF_GENES};
MPI_Datatype types[4];
MPI_Aint displace[4];
MPI_Datatype myStructType;
int base;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
/* init types and displace with addresses of items. */
MPI_Address(old_chrome,displace);
MPI_Address(old_chrome[0].genes,displace+1 );
MPI_Address(old_chrome[0].up_limit, displace+2);
MPI_Address(old_chrome[0].low_limit, displace+3);
types[0] = MPI_DOUBLE;
types[1] = MPI_DOUBLE;
types[2] = MPI_DOUBLE;
types[3] = MPI_DOUBLE;
base = displace[0];
for(i=0; i<4; i++)
{
displace[i] -= base;
}
MPI_Type_struct(4, blockCounts, displace, types, &myStructType);
MPI_Type_commit(&myStructType);
if(rank == 0)
{
initialize();
}
MPI_Bcast(&old_chrome,NUM_OF_CHROMES, myStructType, 0, MPI_COMM_WORLD);
BUT now i want to scater the array genes[] in a way that each node has only 3.
I tried something like this
Code:
MPI_Scatter(&old_chrome[i].genes[0],3,MPI_DOUBLE, &temp_chrome[i].genes[0],3,MPI_DOUBLE,0,MPI_COMM_WORLD);
in a for i=0... NUM_OF_CHROMES loop but not works Any help?