MulticoreBSP for C  Version 2.0.4
bsp.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013
3  *
4  * File created by A. N. Yzelman, 2007-2012.
5  *
6  * This file is part of MulticoreBSP in C --
7  * a port of the original Java-based MulticoreBSP.
8  *
9  * MulticoreBSP for C is distributed as part of the original
10  * MulticoreBSP and is free software: you can redistribute
11  * it and/or modify it under the terms of the GNU Lesser
12  * General Public License as published by the Free Software
13  * Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  * MulticoreBSP is distributed in the hope that it will be
16  * useful, but WITHOUT ANY WARRANTY; without even the
17  * implied warranty of MERCHANTABILITY or FITNESS FOR A
18  * PARTICULAR PURPOSE. See the GNU Lesser General Public
19  * License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General
22  * Public License along with MulticoreBSP. If not, see
23  * <http://www.gnu.org/licenses/>.
24  */
25 
59 #ifndef _HPP_MCBSP
60 #define _HPP_MCBSP
61 
62 extern "C" {
63  #include "bsp.h"
64  #include "mcbsp-affinity.h"
65  #include "mcbsp-resiliency.h"
66 }
67 
68 #include <limits>
69 
70 
76 namespace mcbsp {
77 
105  class BSP_program {
106 
107  private:
108 
110  size_t P;
111 
112  protected:
113 
118  BSP_program() : P( std::numeric_limits< size_t >::max() ) {}
119 
125  virtual void spmd() = 0;
126 
146  virtual BSP_program * newInstance() = 0;
147 
169  virtual void destroyInstance( BSP_program * const instance );
170 
171  public:
172 
190  void begin( const bsp_pid_t P = bsp_nprocs() );
191 
193  virtual ~BSP_program();
194  };
195 
196 }
197 
198 #endif
199 
static bsp_pid_t bsp_nprocs(void)
Returns the number of available processors or processes, depending on whether we are inside or outsid...
Definition: bsp.h:745
Abstract class which a user can extend to write BSP programs.
Definition: bsp.hpp:105
BSP_program()
Base constructor is only accessible by self, derived instances, and friends.
Definition: bsp.hpp:118
virtual ~BSP_program()
Abstract classes should have virtual destructors.
virtual void spmd()=0
The parallel SPMD code to be implemented by user.
virtual void destroyInstance(BSP_program *const instance)
Code that destroys instances creatured using the newInstance() function.
void begin(const bsp_pid_t P=bsp_nprocs())
Initialises and starts the current BSP program.
unsigned int bsp_pid_t
Data type used for thread IDs.
Definition: bsp.h:252
virtual BSP_program * newInstance()=0
Creates a new instance of the implementing class, which will be used by new threads spawned by bsp_be...