MulticoreBSP for C  Version 2.0.4
mcbsp-templates.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013
3  *
4  * File created by A. N. Yzelman, 2013.
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 
60 #ifndef _HPP_MCBSP_TEMPLATES
61 #define _HPP_MCBSP_TEMPLATES
62 
63 #ifndef _HPP_MCBSP
64  #include "mcbsp.hpp"
65 #endif
66 
96 template< typename T >
97 void bsp_push_reg( T * const address, const size_t size = 1 ) {
98  bsp_push_reg( static_cast< void * >(address), size * sizeof( T ) );
99 }
100 
134 template< typename T >
135 bsp_size_t bsp_set_tagsize( const T &tag_type = T() ) {
136  bsp_size_t size = static_cast< bsp_size_t >( sizeof( tag_type ) );
137  bsp_set_tagsize( &size );
138  return size;
139 }
140 
184 template< typename T >
185 void bsp_put( const bsp_pid_t pid, const void * const source,
186  T * const destination, const size_t offset = 0, const size_t size = 1 ) {
187  bsp_put( pid, source, static_cast< const void * >(destination), offset * sizeof(T), size * sizeof(T) );
188 }
189 
237 template< typename T >
238 void bsp_get( const bsp_pid_t pid, const T * const source,
239  const size_t offset, void * const destination, const size_t size = 1 ) {
240  bsp_get( pid, static_cast< const void * >(source), offset * sizeof(T), destination, size * sizeof(T) );
241 }
242 
293 template< typename T >
294 void bsp_direct_get( const bsp_pid_t pid, const T * const source,
295  const bsp_size_t offset, void * const destination, const bsp_size_t size = 1 ) {
296  bsp_direct_get( pid, static_cast< const void * >(source), offset * sizeof(T), destination, size * sizeof(T) );
297 }
298 
317 template< typename T >
318 void bsp_send( const bsp_pid_t pid, const void * const tag,
319  const T * const payload, const size_t size = 1 ) {
320  bsp_send( pid, tag, static_cast< const void * >(payload), size * sizeof(T) );
321 }
322 
323 #ifdef MCBSP_ENABLE_HP_DIRECTIVES
324 
376 template< typename T >
377 void bsp_hpsend( const bsp_pid_t pid, const void * const tag,
378  const T * const payload, const size_t size = 1 ) {
379  bsp_hpsend( pid, tag, static_cast< const void * >(payload), size * sizeof(T) );
380 }
381 #endif //MCBSP_ENABLE_HP_DIRECTIVES
382 
417 template< typename T >
418 void bsp_move( T * const payload, const size_t max_copy_size = 1 ) {
419  bsp_move( static_cast< void * >(payload), max_copy_size * sizeof(T) );
420 }
421 
422 //NOTE: there is no templated bsp_hpmove, as its intended use
423 // requires casting the retrieved pointers into the BMSP
424 // receive-buffer into the appropriate T*.
425 // Additionally, the type of T is typically only known
426 // after inspecting the tag; which is retrieved during
427 // the same call to bsp_hpmove.
428 
429 #if defined ENABLE_FAKE_HP_DIRECTIVES || defined MCBSP_ENABLE_HP_DIRECTIVES
430 
488 template< typename T >
489 void bsp_hpput( const bsp_pid_t pid, const void * const source,
490  const T * const destination, const size_t offset = 0, const size_t size = 1 ) {
491  bsp_hpput( pid, source, static_cast< const void * >(destination), offset * sizeof(T), size * sizeof(T) );
492 }
493 
558 template< typename T >
559 void bsp_hpget( const bsp_pid_t pid, const T * const source,
560  const size_t offset, void * const destination, const size_t size ) {
561  bsp_hpget( pid, static_cast< void * >(source), offset * sizeof(T), destination, size * sizeof(T) );
562 }
563 
564 #endif //ENABLE_FAKE_HP_DIRECTIVES
565 
566 #endif
567 
void bsp_direct_get(const bsp_pid_t pid, const T *const source, const bsp_size_t offset, void *const destination, const bsp_size_t size=1)
Get data from a remote memory location.
Definition: mcbsp-templates.hpp:294
void bsp_send(const bsp_pid_t pid, const void *const tag, const T *const payload, const size_t size=1)
Sends a message to a remote thread.
Definition: mcbsp-templates.hpp:318
void bsp_get(const bsp_pid_t pid, const T *const source, const size_t offset, void *const destination, const size_t size=1)
Get data from a remote memory location.
Definition: mcbsp-templates.hpp:238
bsp_pid_t MCBSP_FUNCTION_PREFIX() pid(void)
void bsp_put(const bsp_pid_t pid, const void *const source, T *const destination, const size_t offset=0, const size_t size=1)
Put data in a remote memory location.
Definition: mcbsp-templates.hpp:185
void bsp_move(T *const payload, const size_t max_copy_size=1)
Retrieves the payload from the first message in the queue of incoming messages, and removes that mess...
Definition: mcbsp-templates.hpp:418
bsp_size_t bsp_set_tagsize(const T &tag_type=T())
Sets the tag size of inter-thread messages.
Definition: mcbsp-templates.hpp:135
void bsp_hpget(const bsp_pid_t pid, const T *const source, const size_t offset, void *const destination, const size_t size)
Get data from a remote memory location.
Definition: mcbsp-templates.hpp:559
void bsp_hpput(const bsp_pid_t pid, const void *const source, const T *const destination, const size_t offset=0, const size_t size=1)
Put data in a remote memory location.
Definition: mcbsp-templates.hpp:489
size_t bsp_size_t
Data type used to refer to memory region sizes.
Definition: bsp.h:256
void bsp_push_reg(T *const address, const size_t size=1)
Registers a memory area for communication.
Definition: mcbsp-templates.hpp:97
unsigned int bsp_pid_t
Data type used for thread IDs.
Definition: bsp.h:252
void bsp_hpsend(const bsp_pid_t pid, const void *const tag, const T *const payload, const size_t size=1)
This is a non-buffering and non-blocking send request.
Definition: mcbsp-templates.hpp:377