Exemplo n.º 1
0
int tMPI_Cart_sub(tMPI_Comm comm, int *remain_dims, tMPI_Comm *newcomm)
{
    int myrank;
    int ndims=0;
    int *dims=NULL;
    int *periods=NULL;
    int *oldcoords=NULL;
    int i;
    int ndims_notused=1;
    int color_notused=0;

#ifdef TMPI_TRACE
    tMPI_Trace_print("tMPI_Cart_sub(%p, %p, %p)", comm, remain_dims, newcomm);
#endif
    tMPI_Comm_rank(comm, &myrank);
    if ( comm->cart )
    {
        oldcoords=(int*)tMPI_Malloc(sizeof(int)*comm->cart->ndims);
        dims=(int*)tMPI_Malloc(sizeof(int)*comm->cart->ndims);
        periods=(int*)tMPI_Malloc(sizeof(int)*comm->cart->ndims);

        /* get old coordinates */
        tMPI_Cart_coords(comm, myrank, comm->cart->ndims, oldcoords);

        for(i=0;i<comm->cart->ndims;i++)
        {
            if (remain_dims[i])
            {
                /* for the remaining dimensions, copy dimensionality data */
                dims[ndims]=comm->cart->dims[i];
                periods[ndims]=comm->cart->periods[i];
                ndims++;
            }
            else
            {
                /* base color on not used coordinates. We keep a 
                   ndims_notused index multiplier.*/
                color_notused += oldcoords[i]*ndims_notused;
                ndims_notused *= comm->cart->dims[i];
            }
        }
    }

    /* key=myrank, because we want the order to remain the same */
    tMPI_Comm_split(comm, color_notused, myrank, newcomm);
    tMPI_Cart_init(newcomm, ndims, dims, periods);

    if (oldcoords)
        free(oldcoords);
    if (dims)
        free(dims);
    if (periods)
        free(periods);

    return TMPI_SUCCESS;
}
Exemplo n.º 2
0
int tMPI_Cart_create(tMPI_Comm comm_old, int ndims, int *dims, int *periods,
                     int reorder, tMPI_Comm *comm_cart)
{
    int myrank = tMPI_Comm_seek_rank(comm_old, tMPI_Get_current());
    int key    = myrank;
    int color  = 0;
    int Ntot   = 1;
    int i;


#ifdef TMPI_TRACE
    tMPI_Trace_print("tMPI_Cart_create(%p, %d, %p, %p, %d, %p)", comm_old,
                     ndims, dims, periods, reorder, comm_cart);
#endif
    if (!comm_old)
    {
        return tMPI_Error(comm_old, TMPI_ERR_COMM);
    }
    /* calculate the total number of procs in cartesian comm */
    for (i = 0; i < ndims; i++)
    {
        Ntot *= dims[i];
    }
    /* refuse to create if there's not enough procs */
    if (comm_old->grp.N < Ntot)
    {
        *comm_cart = TMPI_COMM_NULL;
#if 1
        return tMPI_Error(comm_old, TMPI_ERR_CART_CREATE_NPROCS);
#endif
    }

    if (key >= Ntot)
    {
        key = TMPI_UNDEFINED;
    }

    if (reorder)
    {
        tMPI_Cart_map(comm_old, ndims, dims, periods, &key);
    }

    if (key == TMPI_UNDEFINED)
    {
        color = TMPI_UNDEFINED;
    }

    tMPI_Comm_split(comm_old, color, key, comm_cart);

    tMPI_Cart_init(comm_cart, ndims, dims, periods);

    return TMPI_SUCCESS;
}