Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e3fa67a591698aa3dabfadef3ab9435e42561402
[simgrid.git] / include / xbt / parmap.h
1 /* A thread pool.                                          */
2
3 /* Copyright (c) 2007, 2009-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #ifndef _XBT_PARMAP_H
10 #define _XBT_PARMAP_H
11
12 #include "xbt/misc.h"           /* SG_BEGIN_DECL */
13 #include "xbt/function_types.h"
14 #include "xbt/dynar.h"
15
16 SG_BEGIN_DECL()
17
18 /** \addtogroup XBT_parmap
19   * \ingroup XBT_misc  
20   * \brief Parallel map.
21   *
22   * A function is applied to all elements of a dynar in parallel with n worker threads.
23   * The worker threads are persistent until the destruction of the parmap.
24   *
25   * If there are more than n elements in the dynar, the worker threads are allowed to fetch themselves remaining work
26   * with xbt_parmap_next() and execute it.
27   *
28   * \{
29   */
30
31 /** \brief Parallel map data type (opaque type) */
32 typedef struct s_xbt_parmap *xbt_parmap_t;
33
34 /** \brief Synchronization mode of the worker threads of a parmap. */
35 typedef enum {
36   XBT_PARMAP_POSIX,          /**< use POSIX synchronization primitives */
37   XBT_PARMAP_FUTEX,          /**< use Linux futex system call */
38   XBT_PARMAP_BUSY_WAIT,      /**< busy waits (no system calls, maximum CPU usage) */
39   XBT_PARMAP_DEFAULT         /**< futex if available, posix otherwise */
40 } e_xbt_parmap_mode_t;
41
42 XBT_PUBLIC(xbt_parmap_t) xbt_parmap_new(unsigned int num_workers, e_xbt_parmap_mode_t mode);
43 XBT_PUBLIC(void) xbt_parmap_destroy(xbt_parmap_t parmap);
44 XBT_PUBLIC(void) xbt_parmap_apply(xbt_parmap_t parmap, void_f_pvoid_t fun, xbt_dynar_t data);
45 XBT_PUBLIC(void*) xbt_parmap_next(xbt_parmap_t parmap);
46
47 #ifdef HAVE_MC
48 XBT_PUBLIC(xbt_parmap_t) xbt_parmap_mc_new(unsigned int num_workers, e_xbt_parmap_mode_t mode);
49
50 XBT_PUBLIC(int) xbt_parmap_mc_apply(xbt_parmap_t parmap, int_f_pvoid_pvoid_t fun, void *data, unsigned int length,
51                          void* ref_snapshot);
52 #endif
53 /** \} */
54
55 SG_END_DECL()
56 #endif