]> Creatis software - CreaPhase.git/blob - octave_packages/openmpi_ext-1.0.2/hellostruct.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / openmpi_ext-1.0.2 / hellostruct.m
1 ## Copyright (C) 2009  Riccardo Corradini <riccardocorradini@yahoo.it>
2 ## under the terms of the GNU General Public License.
3 ##
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2 of the License, or
7 ## (at your option) any later version.
8 ##
9 ## This program 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
12 ## GNU General Public License for more details.
13 ##
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
16
17
18 # if you have 4 cores or a network of 4 computers with a ssh connection with no password and same openmpi 1.3.3 installation
19 # type at the terminal mpirun -np 4 octave --eval hellostruct
20
21
22   MPI_Init();
23   # the string NEWORLD is just a label could be whatever you want 
24   CW = MPI_Comm_Load("NEWORLD");
25
26    
27
28   my_rank = MPI_Comm_rank(CW);
29   p = MPI_Comm_size(CW);
30   # TAG is very important to identify the message
31   TAG = 1;
32
33
34   message="";
35   if (my_rank != 0)
36      message = struct('f1', {1 3; 2 4}, 'f2', 25);
37      # Could be a vector containing the list of ranks identifiers; 
38      rankvect = 0;
39      [info] = MPI_Send(message,rankvect,TAG,CW);
40   else
41         for source = 1:p-1
42           disp("We are at rank 0 that is master etc..");
43           [message, info] = MPI_Recv(source,TAG,CW);
44           message
45         endfor
46   end   
47   MPI_Finalize();
48