starpu_barrier.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017 Université de Bordeaux
  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. #define __COMMON_UTILS_H__
  17. #define _STARPU_MALLOC(p, s) do {p = malloc(s);} while (0)
  18. #define _STARPU_CALLOC(p, n, s) do {p = calloc(n, s);} while (0)
  19. #define _STARPU_REALLOC(p, s) do {p = realloc(p, s);} while (0)
  20. //#define STARPU_ATTRIBUTE_UNUSED __attribute((__unused__))
  21. #define STARPU_DEBUG_PREFIX "[starpu]"
  22. #ifdef STARPU_VERBOSE
  23. # define _STARPU_DEBUG(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); fflush(stderr); }} while(0)
  24. #else
  25. # define _STARPU_DEBUG(fmt, ...) do { } while (0)
  26. #endif
  27. #define STARPU_UYIELD() ((void)0)
  28. #ifndef NOCONFIG
  29. #include <config.h>
  30. #else
  31. #define _GNU_SOURCE
  32. // Assuming recent simgrid
  33. #define STARPU_HAVE_SIMGRID_MSG_H
  34. #define STARPU_HAVE_XBT_SYNCHRO_H
  35. #endif
  36. #include <unistd.h>
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39. #include <limits.h>
  40. #include <common/barrier.h>
  41. #ifdef STARPU_HAVE_SIMGRID_MSG_H
  42. #include <simgrid/msg.h>
  43. #else
  44. #include <msg/msg.h>
  45. #endif
  46. #include <simgrid/modelchecker.h>
  47. #ifdef STARPU_HAVE_XBT_SYNCHRO_H
  48. #include <xbt/synchro.h>
  49. #else
  50. #include <xbt/synchro_core.h>
  51. #endif
  52. int
  53. _starpu_simgrid_thread_start(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
  54. {
  55. return 0;
  56. }
  57. #include <common/barrier.c>
  58. #include <common/thread.c>
  59. #ifndef NTHREADS
  60. #define NTHREADS 2
  61. #endif
  62. #ifndef NITERS
  63. #define NITERS 1
  64. #endif
  65. struct _starpu_barrier barrier;
  66. int worker(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
  67. {
  68. unsigned iter;
  69. for (iter = 0; iter < NITERS; iter++)
  70. {
  71. MC_assert(barrier.count <= NTHREADS);
  72. _starpu_barrier_wait(&barrier);
  73. }
  74. return 0;
  75. }
  76. int master(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
  77. {
  78. unsigned i;
  79. _starpu_barrier_init(&barrier, NTHREADS);
  80. for (i = 0; i < NTHREADS; i++)
  81. {
  82. char *s;
  83. asprintf(&s, "%d\n", i);
  84. char **args = malloc(sizeof(char*)*2);
  85. args[0] = s;
  86. args[1] = NULL;
  87. MSG_process_create_with_arguments("test", worker, NULL, MSG_host_self(), 1, args);
  88. }
  89. return 0;
  90. }
  91. #undef main
  92. int main(int argc, char *argv[])
  93. {
  94. if (argc < 3)
  95. {
  96. fprintf(stderr,"usage: %s platform.xml host\n", argv[0]);
  97. exit(EXIT_FAILURE);
  98. }
  99. srand48(0);
  100. MSG_init(&argc, argv);
  101. #if SIMGRID_VERSION_MAJOR < 3 || (SIMGRID_VERSION_MAJOR == 3 && SIMGRID_VERSION_MINOR < 13)
  102. extern xbt_cfg_t _sg_cfg_set;
  103. xbt_cfg_set_int(_sg_cfg_set, "contexts/stack-size", 128);
  104. #else
  105. xbt_cfg_set_int("contexts/stack-size", 128);
  106. #endif
  107. MSG_create_environment(argv[1]);
  108. MSG_process_create("master", master, NULL, MSG_get_host_by_name(argv[2]));
  109. MSG_main();
  110. return 0;
  111. }