Salome HOME
Copyright update 2022
[tools/yacsgen.git] / Examples / paco3 / components.py
1 # -*- coding: utf-8 *-
2 # Copyright (C) 2009-2022  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import os
22
23 #import context from ..
24 exec(compile(open("../pacocontext.py").read(), "../pacocontext.py", 'exec'))
25 from module_generator import Generator,Module,Service,PACOComponent
26
27 cwd=os.getcwd()
28
29 master_body="""
30   // Init data
31   Ports::Param_Double_Port::seq_double data;
32   data.length(10);
33   for (double i=0; i< 10; i++) 
34     data[i] = i; 
35   _master_port_port->configure_port_method_put(10);
36   _master_port_port->put(data);
37
38   Ports::Param_Double_Port::seq_double * results;
39   _master_port_port->get_results(results);
40   std::cerr << "Master receive a sequence of length = " << results->length() << std::endl;
41   for (int i = 0; i < results->length(); i++)
42     std::cerr << "Master receive data : " << (*results)[i] << std::endl;
43   delete results;
44 """
45
46 worker_body="""
47   // Réception des données
48   Ports::Param_Double_Port::seq_double * data = _worker_port_port->get_data();
49   std::cerr << "Node " << getMyRank() << " receive a sequence of length = " << data->length() << std::endl;
50   for (int i = 0; i < data->length(); i++)
51     std::cerr << "Node " << getMyRank() << " receive data : " << (*data)[i] << std::endl;
52   delete data;
53
54   // Envoi des données
55   data = new Ports::Param_Double_Port::seq_double();
56   data->length(5);
57   for (double i=0; i< 5; i++) 
58   {
59     (*data)[i] = i + i + (getMyRank() * 20);
60   }
61   _worker_port_port->configure_set_data(5, 5*getTotalNode(), 5*getMyRank());
62   _worker_port_port->set_data(data);
63   delete data;
64 """
65
66 c1=PACOComponent("MASTER",
67                  "dummy",
68                  services=[
69                    Service("StartMaster",
70                            parallel_outstream=[("master_port", "Param_Double_Port")],
71                            body=master_body,
72                            impl_type="parallel"
73                           ),
74                 ],
75                )
76
77 c2=PACOComponent("WORKER",
78                  "mpi",
79                  services=[
80                    Service("StartWorker",
81                            parallel_instream=[("worker_port", "Param_Double_Port")],
82                            body=worker_body,
83                            impl_type="parallel"
84                           ),
85                 ],
86                )
87
88
89 g=Generator(Module("DSC_PARALLEL_PARAM",components=[c1, c2],prefix="./install"),context)
90 g.generate()
91 g.bootstrap()
92 g.configure()
93 g.make()
94 g.install()
95 g.make_appli("appli", restrict=["KERNEL"], altmodules={"GUI":GUI_ROOT_DIR,
96                                 "YACS":YACS_ROOT_DIR}, sys_modules=SYS_MODULES)
97