MulticoreBSP for C  Version 1.2
mcbsp-templates.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 by Albert-Jan N. Yzelman
3  *
4  * This file is part of MulticoreBSP in C --
5  * a port of the original Java-based MulticoreBSP.
6  *
7  * MulticoreBSP for C is distributed as part of the original
8  * MulticoreBSP and is free software: you can redistribute
9  * it and/or modify it under the terms of the GNU Lesser
10  * General Public License as published by the Free Software
11  * Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  * MulticoreBSP is distributed in the hope that it will be
14  * useful, but WITHOUT ANY WARRANTY; without even the
15  * implied warranty of MERCHANTABILITY or FITNESS FOR A
16  * PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General
20  * Public License along with MulticoreBSP. If not, see
21  * <http://www.gnu.org/licenses/>.
22  */
23 
31 #ifndef _HPP_MCBSP_TEMPLATES
32 #define _HPP_MCBSP_TEMPLATES
33 
34 #ifndef _HPP_MCBSP
35  #include "mcbsp.hpp"
36 #endif
37 
65 template< typename T >
66 void bsp_push_reg( T * const address, const size_t size = 1 ) {
67  bsp_push_reg( (void*)address, size * sizeof( T ) );
68 }
69 
102 template< typename T >
103 MCBSP_BYTESIZE_TYPE bsp_set_tagsize( const T &tag_type = T() ) {
104  MCBSP_BYTESIZE_TYPE size = static_cast< MCBSP_BYTESIZE_TYPE >( sizeof( tag_type ) );
105  bsp_set_tagsize( &size );
106  return size;
107 }
108 
150 template< typename T >
151 void bsp_put( const MCBSP_PROCESSOR_INDEX_DATATYPE pid, const void * const source,
152  T * const destination, const size_t offset = 0, const size_t size = 1 ) {
153  bsp_put( pid, source, (void*)destination, offset * sizeof( T ), size * sizeof( T ) );
154 }
155 
201 template< typename T >
202 void bsp_get( const MCBSP_PROCESSOR_INDEX_DATATYPE pid, const T * const source,
203  const size_t offset, void * const destination, const size_t size = 1 ) {
204  bsp_get( pid, (void*)source, offset * sizeof( T ), destination, size * sizeof( T ) );
205 }
206 
255 template< typename T >
256 void bsp_direct_get( const MCBSP_PROCESSOR_INDEX_DATATYPE pid, const T * const source,
257  const MCBSP_BYTESIZE_TYPE offset, void * const destination, const MCBSP_BYTESIZE_TYPE size = 1 ) {
258  bsp_direct_get( pid, (void*)source, offset * sizeof( T ), destination, size * sizeof( T ) );
259 }
260 
279 template< typename T >
280 void bsp_send( const MCBSP_PROCESSOR_INDEX_DATATYPE pid, const void * const tag,
281  const T * const payload, const size_t size = 1 ) {
282  bsp_send( pid, tag, (const void*)payload, size * sizeof( T ) );
283 }
284 
285 #ifdef MCBSP_ENABLE_HP_DIRECTIVES
286 
336 template< typename T >
337 void bsp_hpsend( const MCBSP_PROCESSOR_INDEX_DATATYPE pid, const void * const tag,
338  const T * const payload, const size_t size = 1 ) {
339  bsp_hpsend( pid, tag, (const void*)payload, size * sizeof( T ) );
340 }
341 #endif //MCBSP_ENABLE_HP_DIRECTIVES
342 
375 template< typename T >
376 void bsp_move( T * const payload, const size_t max_copy_size ) {
377  bsp_move( (void*)payload, max_copy_size * sizeof( T ) );
378 }
379 
380 //NOTE: there is no templated bsp_hpmove, as its intended use
381 // requires casting the retrieved pointers into the BMSP
382 // receive-buffer into the appropriate T*.
383 // Additionally, the type of T is typically only known
384 // after inspecting the tag; which is retrieved during
385 // the same call to bsp_hpmove.
386 
387 #ifdef ENABLE_FAKE_HP_DIRECTIVES
388 
444 template< typename T >
445 void bsp_hpput( const MCBSP_PROCESSOR_INDEX_DATATYPE pid, const void * const source,
446  T * const destination, const size_t offset = 0, const size_t size = 1 ) {
447  bsp_hpput( pid, source, (void*)destination, offset * sizeof( T ), size * sizeof( T ) );
448 }
449 
512 template< typename T >
513 void bsp_hpget( const MCBSP_PROCESSOR_INDEX_DATATYPE pid, const T * const source,
514  const size_t offset, void * const destination, const size_t size ) {
515  bsp_hpget( pid, (void*)source, offset * sizeof( T ), destination, size * sizeof( T ) );
516 }
517 
518 #endif //ENABLE_FAKE_HP_DIRECTIVES
519 
520 #endif
521