]> Creatis software - CreaPhase.git/blob - octave_packages/openmpi_ext-1.0.2/mc_example.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / openmpi_ext-1.0.2 / mc_example.m
1 ## Copyright (C) 2009  Michael Cree <michael.creel@uab.es>
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 # mc_example: shows how Monte Carlo can be done using mpi, Does Monte
19 # Carlo on the OLS estimator. Uses montecarlo.m
20 #
21 # USAGE: from the command prompt, not the octave prompt, execute
22 # orterun -np 3 octave --eval mc_example
23 1;
24 function betahat = olswrapper(args)
25         n = args{1};
26         theta = args{2};
27         x = [ones(n,1) randn(n,1)];
28         y = x*theta + randn(n,1);
29         betahat = ols(y,x);
30         betahat = betahat';
31 endfunction
32
33
34 n = 30;
35 theta = [1;1];
36
37 reps = 10000;
38 f = "olswrapper";
39 args = {n, theta};
40 outfile = "mc_output";
41 n_pooled = 100;
42 verbose = false;
43 tic;
44  montecarlo(f, args, reps, outfile, n_pooled, false, verbose);
45 t=toc
46
47 # info = MPI_Init 
48 # tic;
49 # montecarlo(f, args, reps, outfile, n_pooled, verbose);
50 # disp("I am here!");
51 # t=toc
52 #  info = MPI_Finalize() 
53