]> Creatis software - CreaPhase.git/blobdiff - octave_packages/openmpi_ext-1.0.2/hello2dimmat.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / openmpi_ext-1.0.2 / hello2dimmat.m
diff --git a/octave_packages/openmpi_ext-1.0.2/hello2dimmat.m b/octave_packages/openmpi_ext-1.0.2/hello2dimmat.m
new file mode 100644 (file)
index 0000000..36ed497
--- /dev/null
@@ -0,0 +1,33 @@
+  MPI_SUCCESS =0;
+  MPI_Init();
+
+  # the string NEWORLD is just a label could be whatever you want    
+  CW = MPI_Comm_Load("NEWORLD");
+  my_rank = MPI_Comm_rank(CW);
+  p = MPI_Comm_size(CW);
+  mytag = 48;
+
+
+  if (my_rank != 0)
+#        Generate a random matrix
+       message=rand(444440,8);
+#        load message
+#       rankvect is the vector containing the list of rank  destination process
+     rankvect = 0;
+     [info] = MPI_Send(message,rankvect,mytag,CW);
+  else
+        for source = 1:p-1
+          disp("We are at rank 0 that is master etc..");
+          [messager, info] = MPI_Recv(source,mytag,CW);
+          
+#      You could also save each result and make comparisons if you don't trust MPI
+          disp("Rank 0 is the master receiving ... :");
+            if (info == MPI_SUCCESS)
+              disp('OK!');
+          endif
+          endfor
+  end   
+
+
+   MPI_Finalize();