starpu_barrier.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017 CNRS
  4. * Copyright (C) 2017 Université de Bordeaux
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #define __COMMON_UTILS_H__
  18. #define _STARPU_MALLOC(p, s) do {p = malloc(s);} while (0)
  19. #define _STARPU_CALLOC(p, n, s) do {p = calloc(n, s);} while (0)
  20. #define _STARPU_REALLOC(p, s) do {p = realloc(p, s);} while (0)
  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 <common/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 <math.h>
  43. #include <common/barrier.h>
  44. #ifdef STARPU_HAVE_SIMGRID_MSG_H
  45. #include <simgrid/msg.h>
  46. #else
  47. #include <msg/msg.h>
  48. #endif
  49. #include <simgrid/modelchecker.h>
  50. #ifdef STARPU_HAVE_XBT_SYNCHRO_H
  51. #include <xbt/synchro.h>
  52. #else
  53. #include <xbt/synchro_core.h>
  54. #endif
  55. int
  56. _starpu_simgrid_thread_start(int argc, char *argv[])
  57. {
  58. return 0;
  59. }
  60. static void _starpu_clock_gettime(struct timespec *ts)
  61. {
  62. double now = MSG_get_clock();
  63. ts->tv_sec = floor(now);
  64. ts->tv_nsec = floor((now - ts->tv_sec) * 1000000000);
  65. }
  66. #include <common/barrier.c>
  67. #include <common/thread.c>
  68. #ifndef NTHREADS
  69. #define NTHREADS 2
  70. #endif
  71. #ifndef NITERS
  72. #define NITERS 1
  73. #endif
  74. struct _starpu_barrier barrier;
  75. int worker(int argc, char *argv[])
  76. {
  77. unsigned iter;
  78. for (iter = 0; iter < NITERS; iter++)
  79. {
  80. MC_assert(barrier.count <= NTHREADS);
  81. _starpu_barrier_wait(&barrier);
  82. }
  83. return 0;
  84. }
  85. int master(int argc, char *argv[])
  86. {
  87. unsigned i;
  88. _starpu_barrier_init(&barrier, NTHREADS);
  89. for (i = 0; i < NTHREADS; i++)
  90. {
  91. char *s;
  92. asprintf(&s, "%d\n", i);
  93. char **args = malloc(sizeof(char*)*2);
  94. args[0] = s;
  95. args[1] = NULL;
  96. MSG_process_create_with_arguments("test", worker, NULL, MSG_host_self(), 1, args);
  97. }
  98. return 0;
  99. }
  100. #undef main
  101. int main(int argc, char *argv[])
  102. {
  103. if (argc < 3)
  104. {
  105. fprintf(stderr,"usage: %s platform.xml host\n", argv[0]);
  106. exit(EXIT_FAILURE);
  107. }
  108. srand48(0);
  109. MSG_init(&argc, argv);
  110. #if SIMGRID_VERSION_MAJOR < 3 || (SIMGRID_VERSION_MAJOR == 3 && SIMGRID_VERSION_MINOR < 13)
  111. extern xbt_cfg_t _sg_cfg_set;
  112. xbt_cfg_set_int(_sg_cfg_set, "contexts/stack-size", 128);
  113. #else
  114. xbt_cfg_set_int("contexts/stack-size", 128);
  115. #endif
  116. MSG_create_environment(argv[1]);
  117. MSG_process_create("master", master, NULL, MSG_get_host_by_name(argv[2]));
  118. MSG_main();
  119. return 0;
  120. }