mpi_comm.c
//Create wrap-around cartesian MPI topology
//Parameter dims is a 2D array with the size of the grid of processes.
Create wrap-around cartesian MPI topology
Parameter dims is a 2D array with the size of the grid of processes.
Create wrap - around cartesian MPI topology Parameter dims is a 2D array with the size of the grid of processes .
int init_mpi_cart(int* dims)
{
    int rank_id;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank_id);
    int cyclic[2] = {1, 1};
    MPI_Cart_create(MPI_COMM_WORLD, 2, dims, cyclic, 1, &CARTESIAN_COMM);
    int coords[2];
    memset(coords, '\0', sizeof(coords));
    if (CARTESIAN_COMM != MPI_COMM_NULL)
    {
        MPI_Cart_coords(CARTESIAN_COMM, rank_id, 2, coords);
        MPI_Cart_rank(CARTESIAN_COMM, coords, &rank_id);
    }
    else
    {
        printf("Could not properly set CARTESIAN_COMM_WORLD\n");
        MPI_Finalize();
        return EXIT_FAILURE;
    }
    return rank_id;
}
int init_mpi_cart ( int * dims ) { int rank_id ; MPI_Comm_rank ( MPI_COMM_WORLD , & rank_id ) ; int cyclic [ 2 ] = { 1 , 1 } ; MPI_Cart_create ( MPI_COMM_WORLD , 2 , dims , cyclic , 1 , & CARTESIAN_COMM ) ; int coords [ 2 ] ; memset ( coords , ' \0 ' , sizeof ( coords ) ) ; if ( CARTESIAN_COMM != MPI_COMM_NULL ) { MPI_Cart_coords ( CARTESIAN_COMM , rank_id , 2 , coords ) ; MPI_Cart_rank ( CARTESIAN_COMM , coords , & rank_id ) ; } else { printf ( " \n " ) ; MPI_Finalize ( ) ; return EXIT_FAILURE ; } return rank_id ; }
Create wrap-around cartesian MPI topology
Parameter dims is a 2D array with the size of the grid of processes.
Create wrap - around cartesian MPI topology Parameter dims is a 2D array with the size of the grid of processes .
//wrap-around //convert rank_id from COMM_WORLD to CARTESIAN