starpu_barrier.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #ifndef _GNU_SOURCE
  32. #define _GNU_SOURCE 1
  33. #endif
  34. // Assuming recent simgrid
  35. #define STARPU_HAVE_SIMGRID_MSG_H
  36. #define STARPU_HAVE_XBT_SYNCHRO_H
  37. #endif
  38. #include <unistd.h>
  39. #include <stdlib.h>
  40. #include <stdio.h>
  41. #include <limits.h>
  42. #include <common/barrier.h>
  43. #ifdef STARPU_HAVE_SIMGRID_MSG_H
  44. #include <simgrid/msg.h>
  45. #else
  46. #include <msg/msg.h>
  47. #endif
  48. #include <simgrid/modelchecker.h>
  49. #ifdef STARPU_HAVE_XBT_SYNCHRO_H
  50. #include <xbt/synchro.h>
  51. #else
  52. #include <xbt/synchro_core.h>
  53. #endif
  54. int
  55. _starpu_simgrid_thread_start(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
  56. {
  57. return 0;
  58. }
  59. #include <common/barrier.c>
  60. #include <common/thread.c>
  61. #ifndef NTHREADS
  62. #define NTHREADS 2
  63. #endif
  64. #ifndef NITERS
  65. #define NITERS 1
  66. #endif
  67. struct _starpu_barrier barrier;
  68. int worker(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
  69. {
  70. unsigned iter;
  71. for (iter = 0; iter < NITERS; iter++)
  72. {
  73. MC_assert(barrier.count <= NTHREADS);
  74. _starpu_barrier_wait(&barrier);
  75. }
  76. return 0;
  77. }
  78. int master(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
  79. {
  80. unsigned i;
  81. _starpu_barrier_init(&barrier, NTHREADS);
  82. for (i = 0; i < NTHREADS; i++)
  83. {
  84. char *s;
  85. asprintf(&s, "%d\n", i);
  86. char **args = malloc(sizeof(char*)*2);
  87. args[0] = s;
  88. args[1] = NULL;
  89. MSG_process_create_with_arguments("test", worker, NULL, MSG_host_self(), 1, args);
  90. }
  91. return 0;
  92. }
  93. #undef main
  94. int main(int argc, char *argv[])
  95. {
  96. if (argc < 3)
  97. {
  98. fprintf(stderr,"usage: %s platform.xml host\n", argv[0]);
  99. exit(EXIT_FAILURE);
  100. }
  101. srand48(0);
  102. MSG_init(&argc, argv);
  103. #if SIMGRID_VERSION_MAJOR < 3 || (SIMGRID_VERSION_MAJOR == 3 && SIMGRID_VERSION_MINOR < 13)
  104. extern xbt_cfg_t _sg_cfg_set;
  105. xbt_cfg_set_int(_sg_cfg_set, "contexts/stack-size", 128);
  106. #else
  107. xbt_cfg_set_int("contexts/stack-size", 128);
  108. #endif
  109. MSG_create_environment(argv[1]);
  110. MSG_process_create("master", master, NULL, MSG_get_host_by_name(argv[2]));
  111. MSG_main();
  112. return 0;
  113. }