starpu_barrier.c 3.2 KB

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