starpu_mpi_datatype.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu_mpi_datatype.h>
  17. /*
  18. * MPI_* functions usually requires both a pointer to the first element of
  19. * a datatype and the datatype itself, so we need to provide both.
  20. */
  21. typedef int (*handle_to_datatype_func)(starpu_data_handle, MPI_Datatype *);
  22. typedef void *(*handle_to_ptr_func)(starpu_data_handle);
  23. /*
  24. * Vector
  25. */
  26. static int handle_to_datatype_vector(starpu_data_handle data_handle, MPI_Datatype *datatype)
  27. {
  28. unsigned nx = starpu_get_vector_nx(data_handle);
  29. size_t elemsize = starpu_get_vector_elemsize(data_handle);
  30. MPI_Type_contiguous(nx*elemsize, MPI_BYTE, datatype);
  31. MPI_Type_commit(datatype);
  32. return 0;
  33. }
  34. static void *handle_to_ptr_vector(starpu_data_handle data_handle)
  35. {
  36. return (void *)starpu_get_vector_local_ptr(data_handle);
  37. }
  38. /*
  39. * Generic
  40. */
  41. static handle_to_datatype_func handle_to_datatype_funcs[STARPU_NINTERFACES_ID] = {
  42. [STARPU_BLAS_INTERFACE_ID] = NULL,
  43. [STARPU_BLOCK_INTERFACE_ID] = NULL,
  44. [STARPU_VECTOR_INTERFACE_ID] = handle_to_datatype_vector,
  45. [STARPU_CSR_INTERFACE_ID] = NULL,
  46. [STARPU_CSC_INTERFACE_ID] = NULL,
  47. [STARPU_BCSCR_INTERFACE_ID] = NULL
  48. };
  49. static handle_to_ptr_func handle_to_ptr_funcs[STARPU_NINTERFACES_ID] = {
  50. [STARPU_BLAS_INTERFACE_ID] = NULL,
  51. [STARPU_BLOCK_INTERFACE_ID] = NULL,
  52. [STARPU_VECTOR_INTERFACE_ID] = handle_to_ptr_vector,
  53. [STARPU_CSR_INTERFACE_ID] = NULL,
  54. [STARPU_CSC_INTERFACE_ID] = NULL,
  55. [STARPU_BCSCR_INTERFACE_ID] = NULL
  56. };
  57. int starpu_mpi_handle_to_datatype(starpu_data_handle data_handle, MPI_Datatype *datatype)
  58. {
  59. unsigned id = starpu_get_handle_interface_id(data_handle);
  60. handle_to_datatype_func func = handle_to_datatype_funcs[id];
  61. STARPU_ASSERT(func);
  62. return func(data_handle, datatype);
  63. }
  64. void *starpu_mpi_handle_to_ptr(starpu_data_handle data_handle)
  65. {
  66. unsigned id = starpu_get_handle_interface_id(data_handle);
  67. handle_to_ptr_func func = handle_to_ptr_funcs[id];
  68. STARPU_ASSERT(func);
  69. return func(data_handle);
  70. }