MulticoreBSP for C  Version 2.0.4
mcbsp.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012
3  *
4  * File created by Albert-Jan N. Yzelman.
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 
26 #ifndef _HPP_MCBSP_INTERNAL
27 #define _HPP_MCBSP_INTERNAL
28 
29 #define MCBSP_CPLUSPLUS
30 
31 #include <iostream>
32 
33 //for documentation of the public parts, see mcbsp.hpp
34 
35 extern "C" {
36  #include "mcbsp.h"
37  #include "mcutil.h"
38 }
39 
40 namespace mcbsp {
41 
54  void mcbsp_cpp_callback();
55 
56  class BSP_program {
57 
58  private:
59 
60  size_t P;
61 
62  protected:
63 
64  BSP_program() : P( static_cast< size_t >(-1) ) {}
65 
66  virtual void spmd() = 0;
67 
68  virtual BSP_program * newInstance() = 0;
69 
70  virtual void destroyInstance( BSP_program * const instance );
71 
72  public:
73 
74  void begin( const bsp_pid_t P = bsp_nprocs() );
75 
76  virtual ~BSP_program();
77 
78  friend void mcbsp_cpp_callback();
79  };
80 
81 }
82 
83 #endif
84 
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
friend void mcbsp_cpp_callback()
This function enables C++ wrapping of MulticoreBSP for C.
Abstract class which a user can extend to write BSP programs.
Definition: bsp.hpp:105
BSP_program()
Definition: mcbsp.hpp:64
virtual ~BSP_program()
Abstract classes should have virtual destructors.
void mcbsp_cpp_callback()
This function enables C++ wrapping of MulticoreBSP for C.
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...