source: soft/giet_vm/giet_libs/barrier.h @ 455

Last change on this file since 455 was 368, checked in by alain, 10 years ago

1) Introducing the SBT barrier (Sliced Binary Tree)

in the barrier.h library.

2) Introducing a new remote_malloc.h library.

  • Property svn:executable set to *
File size: 4.6 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////
2// File     : barrier.h         
3// Date     : 01/04/2012
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The barrier.c and barrier.h files are part of the GIET-VM nano-kernel.
8// This user-level library provides a synchronisation service between several
9// tasks sharing the same address space in a parallel multi-tasks application.
10//
11// There is actually two types of barriers:
12// 1) The "giet_barrier_t" is a simple sense-reversing barrier.
13//    It can be safely used several times (in a loop for example),
14//    but it does not scale, and should not be used when the number
15//    of tasks is larger than few tens.
16//
17// 2) The giet_sbt_barrier_t" can be used in multi-clusters architectures,
18//    and is implemented as a physically distributed Sliced-Binary-Tree (SBT).
19//    WARNING: The following placement constraints must be respected:
20//    - The number of tasks must be a power of 2.
21//    - There is one task per processor in a given cluster.
22//    - The involved clusters form a mesh[N][N] or a mesh[N][N/2]
23//    - The lower left involved cluster is cluster(0,0) 
24//
25// Neither the barrier_init(), nor the barrier_wait() function require a syscall.
26// For both types of barriers, the barrier initialisation should be done by
27// one single task.
28///////////////////////////////////////////////////////////////////////////////////
29
30#ifndef _BARRIER_H_
31#define _BARRIER_H_
32
33#include "hard_config.h"
34
35///////////////////////////////////////////////////////////////////////////////////
36///////////////////////////////////////////////////////////////////////////////////
37//  simple barrier structure and access functions
38///////////////////////////////////////////////////////////////////////////////////
39///////////////////////////////////////////////////////////////////////////////////
40
41typedef struct giet_barrier_s
42{
43    char         name[32];   // barrier name
44    unsigned int sense;      // barrier state (toggle)
45    unsigned int ntasks;     // total number of expected tasks
46    unsigned int count;      // number of not arrived tasks
47} giet_barrier_t;
48
49///////////////////////////////////////////////////
50extern void barrier_init( giet_barrier_t* barrier,
51                          unsigned int    ntasks );   
52
53////////////////////////////////////////////////////
54extern void barrier_wait( giet_barrier_t* barrier );
55
56///////////////////////////////////////////////////////////////////////////////////
57//////////////////////////////////////////////////////////////////////////////////
58// SBT barrier structures and access functions
59//////////////////////////////////////////////////////////////////////////////////
60//////////////////////////////////////////////////////////////////////////////////
61
62typedef struct sbt_node_s
63{
64    unsigned int       arity;           // number of children (must be 2 or 4)
65    unsigned int       count;           // number of not arrived children
66    unsigned int       sense;           // barrier state (toggle)
67    unsigned int       level;           // hierarchical level (0 is bottom)
68    struct sbt_node_s* parent;          // pointer on parent node (NULL for root)
69    struct sbt_node_s* child0;          // pointer on children node
70    struct sbt_node_s* child1;          // pointer on children node
71} sbt_node_t;
72
73#define SBT_NODE_SIZE  32
74
75typedef struct giet_sbt_barrier_s
76{
77    char            name[32];                 // barrier name
78    unsigned int    ntasks;                   // total number of expected tasks
79    sbt_node_t*     node[X_SIZE][Y_SIZE][9];  // array of pointers on SBT nodes
80} giet_sbt_barrier_t;
81
82///////////////////////////////////////////////////////////
83extern void sbt_barrier_init( giet_sbt_barrier_t*  barrier,
84                              unsigned int         ntasks );   
85
86/////////////////////////////////////////////////////////////
87extern void sbt_barrier_wait( giet_sbt_barrier_t*  barrier );
88
89/////////////////////////////////////////////
90void sbt_build( giet_sbt_barrier_t*  barrier,
91                unsigned int         x,
92                unsigned int         y,
93                unsigned int         level, 
94                sbt_node_t*          parent );
95
96///////////////////////////////////////
97void sbt_decrement( sbt_node_t* node );
98
99///////////////////////////////////
100void sbt_release( sbt_node_t* node,
101                  unsigned int expected );
102
103
104
105#endif
106
107// Local Variables:
108// tab-width: 4
109// c-basic-offset: 4
110// c-file-offsets:((innamespace . 0)(inline-open . 0))
111// indent-tabs-mode: nil
112// End:
113// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
114
Note: See TracBrowser for help on using the repository browser.