starpu_barrier.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <math.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, char *argv[])
  56. {
  57. return 0;
  58. }
  59. static void _starpu_clock_gettime(struct timespec *ts)
  60. {
  61. double now = MSG_get_clock();
  62. ts->tv_sec = floor(now);
  63. ts->tv_nsec = floor((now - ts->tv_sec) * 1000000000);
  64. }
  65. #include <common/barrier.c>
  66. #include <common/thread.c>
  67. #ifndef NTHREADS
  68. #define NTHREADS 2
  69. #endif
  70. #ifndef NITERS
  71. #define NITERS 1
  72. #endif
  73. struct _starpu_barrier barrier;
  74. int worker(int argc, char *argv[])
  75. {
  76. unsigned iter;
  77. for (iter = 0; iter < NITERS; iter++)
  78. {
  79. MC_assert(barrier.count <= NTHREADS);
  80. _starpu_barrier_wait(&barrier);
  81. }
  82. return 0;
  83. }
  84. int master(int argc, char *argv[])
  85. {
  86. unsigned i;
  87. _starpu_barrier_init(&barrier, NTHREADS);
  88. for (i = 0; i < NTHREADS; i++)
  89. {
  90. char *s;
  91. asprintf(&s, "%d\n", i);
  92. char **args = malloc(sizeof(char*)*2);
  93. args[0] = s;
  94. args[1] = NULL;
  95. MSG_process_create_with_arguments("test", worker, NULL, MSG_host_self(), 1, args);
  96. }
  97. return 0;
  98. }
  99. #undef main
  100. int main(int argc, char *argv[])
  101. {
  102. if (argc < 3)
  103. {
  104. fprintf(stderr,"usage: %s platform.xml host\n", argv[0]);
  105. exit(EXIT_FAILURE);
  106. }
  107. srand48(0);
  108. MSG_init(&argc, argv);
  109. #if SIMGRID_VERSION_MAJOR < 3 || (SIMGRID_VERSION_MAJOR == 3 && SIMGRID_VERSION_MINOR < 13)
  110. extern xbt_cfg_t _sg_cfg_set;
  111. xbt_cfg_set_int(_sg_cfg_set, "contexts/stack-size", 128);
  112. #else
  113. xbt_cfg_set_int("contexts/stack-size", 128);
  114. #endif
  115. MSG_create_environment(argv[1]);
  116. MSG_process_create("master", master, NULL, MSG_get_host_by_name(argv[2]));
  117. MSG_main();
  118. return 0;
  119. }