123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /*
- * StarPU
- * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * See the GNU Lesser General Public License in COPYING.LGPL for more details.
- */
- #include <starpu_mpi_datatype.h>
- /*
- * MPI_* functions usually requires both a pointer to the first element of
- * a datatype and the datatype itself, so we need to provide both.
- */
- typedef int (*handle_to_datatype_func)(starpu_data_handle, MPI_Datatype *);
- typedef void *(*handle_to_ptr_func)(starpu_data_handle);
- /*
- * Blas
- */
- static int handle_to_datatype_blas(starpu_data_handle data_handle, MPI_Datatype *datatype)
- {
- unsigned nx = starpu_get_blas_nx(data_handle);
- unsigned ny = starpu_get_blas_ny(data_handle);
- unsigned ld = starpu_get_blas_local_ld(data_handle);
- size_t elemsize = starpu_get_blas_elemsize(data_handle);
- MPI_Type_vector(ny, nx*elemsize, ld*elemsize, MPI_BYTE, datatype);
- MPI_Type_commit(datatype);
- return 0;
- }
- static void *handle_to_ptr_blas(starpu_data_handle data_handle)
- {
- return (void *)starpu_get_blas_local_ptr(data_handle);
- }
- /*
- * Vector
- */
- static int handle_to_datatype_vector(starpu_data_handle data_handle, MPI_Datatype *datatype)
- {
- unsigned nx = starpu_get_vector_nx(data_handle);
- size_t elemsize = starpu_get_vector_elemsize(data_handle);
- MPI_Type_contiguous(nx*elemsize, MPI_BYTE, datatype);
- MPI_Type_commit(datatype);
- return 0;
- }
- static void *handle_to_ptr_vector(starpu_data_handle data_handle)
- {
- return (void *)starpu_get_vector_local_ptr(data_handle);
- }
- /*
- * Generic
- */
- static handle_to_datatype_func handle_to_datatype_funcs[STARPU_NINTERFACES_ID] = {
- [STARPU_BLAS_INTERFACE_ID] = handle_to_datatype_blas,
- [STARPU_BLOCK_INTERFACE_ID] = NULL,
- [STARPU_VECTOR_INTERFACE_ID] = handle_to_datatype_vector,
- [STARPU_CSR_INTERFACE_ID] = NULL,
- [STARPU_CSC_INTERFACE_ID] = NULL,
- [STARPU_BCSCR_INTERFACE_ID] = NULL
- };
- static handle_to_ptr_func handle_to_ptr_funcs[STARPU_NINTERFACES_ID] = {
- [STARPU_BLAS_INTERFACE_ID] = handle_to_ptr_blas,
- [STARPU_BLOCK_INTERFACE_ID] = NULL,
- [STARPU_VECTOR_INTERFACE_ID] = handle_to_ptr_vector,
- [STARPU_CSR_INTERFACE_ID] = NULL,
- [STARPU_CSC_INTERFACE_ID] = NULL,
- [STARPU_BCSCR_INTERFACE_ID] = NULL
- };
- int starpu_mpi_handle_to_datatype(starpu_data_handle data_handle, MPI_Datatype *datatype)
- {
- unsigned id = starpu_get_handle_interface_id(data_handle);
- handle_to_datatype_func func = handle_to_datatype_funcs[id];
- STARPU_ASSERT(func);
- return func(data_handle, datatype);
- }
- void *starpu_mpi_handle_to_ptr(starpu_data_handle data_handle)
- {
- unsigned id = starpu_get_handle_interface_id(data_handle);
- handle_to_ptr_func func = handle_to_ptr_funcs[id];
-
- STARPU_ASSERT(func);
- return func(data_handle);
- }
|