insert_task_node_choice.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
  4. *
  5. * StarPU 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. * StarPU 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.h>
  17. #include <math.h>
  18. #include "helper.h"
  19. void func_cpu(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  20. {
  21. int node;
  22. int rank;
  23. starpu_codelet_unpack_args(_args, &node);
  24. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  25. FPRINTF_MPI("Expected node: %d - Actual node: %d\n", node, rank);
  26. assert(node == rank);
  27. }
  28. struct starpu_codelet mycodelet =
  29. {
  30. .cpu_funcs = {func_cpu},
  31. .nbuffers = 2,
  32. .modes = {STARPU_RW, STARPU_RW},
  33. .name = "insert_task_node_choice"
  34. };
  35. int main(int argc, char **argv)
  36. {
  37. int ret, rank, size, err, node;
  38. int x0=32;
  39. long x1=23;
  40. starpu_data_handle_t data_handlesx0;
  41. starpu_data_handle_t data_handlesx1;
  42. ret = starpu_init(NULL);
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  44. ret = starpu_mpi_init(&argc, &argv, 1);
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  46. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  47. MPI_Comm_size(MPI_COMM_WORLD, &size);
  48. if (rank != 0 && rank != 1) goto end;
  49. starpu_variable_data_register(&data_handlesx0, STARPU_MAIN_RAM, (uintptr_t)&x0, sizeof(x0));
  50. starpu_variable_data_register(&data_handlesx1, STARPU_MAIN_RAM, (uintptr_t)&x1, sizeof(x1));
  51. starpu_mpi_data_register(data_handlesx0, 100, 0);
  52. starpu_mpi_data_register(data_handlesx1, 200, 1);
  53. node = 0;
  54. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  55. STARPU_VALUE, &node, sizeof(node),
  56. STARPU_EXECUTE_ON_NODE, 0,
  57. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  58. 0);
  59. assert(err == 0);
  60. node = starpu_data_get_rank(data_handlesx1);
  61. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  62. STARPU_VALUE, &node, sizeof(node),
  63. STARPU_EXECUTE_ON_DATA, data_handlesx1,
  64. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  65. 0);
  66. assert(err == 0);
  67. node = 1; // Node 1 has a long which is bigger than a int
  68. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  69. STARPU_VALUE, &node, sizeof(node),
  70. STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1,
  71. 0);
  72. assert(err == 0);
  73. FPRINTF_MPI("Waiting ...\n");
  74. starpu_task_wait_for_all();
  75. starpu_data_unregister(data_handlesx0);
  76. starpu_data_unregister(data_handlesx1);
  77. end:
  78. starpu_mpi_shutdown();
  79. starpu_shutdown();
  80. return 0;
  81. }