ALP User Documentation  0.8.preview
Algebraic Programming User Documentation
exec.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2021 Huawei Technologies Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
27 #ifndef _H_GRB_EXEC_BASE
28 #define _H_GRB_EXEC_BASE
29 
30 #include <stdexcept>
31 #include <string>
32 
33 #include <graphblas/backends.hpp>
34 #include <graphblas/rc.hpp>
35 
36 #ifndef _GRB_NO_STDIO
37  #include <iostream>
38 #endif
39 
40 
41 namespace grb {
42 
46  template< typename InputType, typename OutputType >
47  using AlpTypedFunc = void ( * )( const InputType &, OutputType & );
48 
52  template< typename OutputType >
53  using AlpUntypedFunc = void ( * )( const void *, size_t, OutputType & );
54 
87  enum EXEC_MODE {
88 
95  AUTOMATIC = 0,
96 
104 
114 
115  };
116 
140  template< enum EXEC_MODE mode, enum Backend backend >
141  class Launcher {
142 
143  public :
144 
208  const size_t process_id = 0,
209  const size_t nprocs = 1,
210  const std::string hostname = "localhost",
211  const std::string port = "0"
212  ) {
213  // spec does not specify any constrants on hostname and port
214  // so accept (and ignore) anything
215  (void) hostname;
216  (void) port;
217 
218 #ifndef _GRB_NO_EXCEPTIONS
219  // sanity checks on process_id and nprocs
220  if( nprocs == 0 ) {
221  throw std::invalid_argument( "Total number of user processes must be "
222  "strictly larger than zero." );
223  }
224  if( process_id >= nprocs ) {
225  throw std::invalid_argument( "Process ID must be strictly smaller than "
226  "total number of user processes." );
227  }
228 #endif
229  }
230 
317  template< typename T, typename U >
319  AlpTypedFunc< T, U > alp_program,
320  const T &data_in,
321  U &data_out,
322  const bool broadcast = false
323  ) const {
324  (void) alp_program;
325  (void) data_in;
326  (void) data_out;
327  (void) broadcast;
328  // stub implementation, should be overridden by specialised backend,
329  // so return error code
330  return PANIC;
331  }
332 
372  template< typename U >
374  AlpUntypedFunc< U > alp_program,
375  const void * data_in,
376  const size_t in_size,
377  U &data_out,
378  const bool broadcast = false
379  ) const {
380  (void) alp_program;
381  (void) data_in;
382  (void) in_size;
383  (void) data_out;
384  (void) broadcast;
385  return PANIC;
386  }
387 
431  static RC finalize() {
432  return PANIC;
433  }
434 
435  }; // end class `Launcher'
436 
437 } // end namespace ``grb''
438 
439 #endif // end _H_GRB_EXEC_BASE
440 
Defines the ALP error codes.
RC exec(AlpTypedFunc< T, U > alp_program, const T &data_in, U &data_out, const bool broadcast=false) const
Executes a given ALP program using the user processes encapsulated by this launcher group.
Definition: exec.hpp:318
This file contains a register of all backends that are either implemented, under implementation,...
RC
Return codes of ALP primitives.
Definition: rc.hpp:47
void(*)(const InputType &, OutputType &) AlpTypedFunc
Type definition for an ALP function with input type information.
Definition: exec.hpp:47
Automatic mode.
Definition: exec.hpp:95
RC exec(AlpUntypedFunc< U > alp_program, const void *data_in, const size_t in_size, U &data_out, const bool broadcast=false) const
Executes a given ALP program using the user processes encapsulated by this launcher group.
Definition: exec.hpp:373
From MPI mode.
Definition: exec.hpp:113
Manual mode.
Definition: exec.hpp:103
Launcher(const size_t process_id=0, const size_t nprocs=1, const std::string hostname="localhost", const std::string port="0")
Constructs a new grb::Launcher.
Definition: exec.hpp:207
void(*)(const void *, size_t, OutputType &) AlpUntypedFunc
Type definition for an ALP function without input type information.
Definition: exec.hpp:53
EXEC_MODE
The various ways in which the grb::Launcher can be used to execute an ALP program.
Definition: exec.hpp:87
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:477
Generic fatal error code.
Definition: rc.hpp:68
A group of user processes that together execute ALP programs.
Definition: exec.hpp:141
static RC finalize()
Releases all ALP resources.
Definition: exec.hpp:431