]> Creatis software - CreaPhase.git/blob - octave_packages/openmpi_ext-1.0.2/hellosparsemat.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / openmpi_ext-1.0.2 / hellosparsemat.m
1   MPI_Init();
2   # the string NEWORLD is just a label could be whatever you want  
3   CW = MPI_Comm_Load("NEWORLD");
4   my_rank = MPI_Comm_rank(CW);
5   p = MPI_Comm_size(CW);
6 # tag[0] ----> type of octave_value
7 # tag[1] ----> array of three elements 1) num of rows 2) number of columns 3) number of non zero elements
8 # tag[2] ---->  vector of rowindex
9 # tag[3] ---->  vector of columnindex
10 # tag[4] ---->  vector of  non zero elements
11 # These tags will be generated after mytag by the MPI_Send and MPI_Recv (see source code)
12
13   mytag = 48;
14
15
16
17
18 # This is just to fill the sparse matrix
19   M=5;
20   N=5;
21   D=0.9;
22     message = sprand (M, N, D);
23 #  load message
24  
25
26  
27   if (my_rank != 0)
28       dest = 0;
29 #       rankvect is the vector containing the list of rank  destination process
30      rankvect(1,1) = 0;
31      [info] = MPI_Send(message,rankvect,mytag,CW);
32      disp("This is flag for sending the message --")
33      info
34   else
35         for source = 1:p-1
36           messager='';
37           disp("We are at rank 0 that is master etc..");
38           [messager, info] = MPI_Recv(source,mytag,CW);
39           disp("Rank 0 is the master receiving ... :");
40           if (messager/message)
41                 disp('OK!');
42           endif
43       messager
44           endfor
45   end   
46
47    MPI_Finalize();