Routine Name MatMPI_Comm_init(n_proc, machines)
Routine Location MatlabMPI\MatMPI_Comm_init.m
Routine Purpose ---
Routine Arguments { machines, MPI_COMM_WORLD, n_proc }
Routine Outputs { MPI_COMM_WORLD }
Routine Size 112 line(s)
Routine Comment
Click here
Parent Routines
Child Routines
Routine Body

001  function MPI_COMM_WORLD = MatMPI_Comm_init(n_proc ,machines)
002  % MatMPI_Comm_init  -  Creates generic communicator.
003  %
004  %   MPI_COMM_WORLD = MatMPI_Comm_init(n_proc,machines)
005  %
006  
007  % Get number of machines to launch on.
008  n_machines = size(machines ,2) ;
009  n_m = max(n_machines ,1) ;
010  
011  % Set default target machine.
012  host = getenv('HOST') ;
013  machine = host ;
014  
015  % Initialize comm.
016  MPI_COMM_WORLD.rank =- 1 ;
017  MPI_COMM_WORLD.size = n_proc ;
018  MPI_COMM_WORLD.save_message_flag = 0 ;
019  MPI_COMM_WORLD.group = (1:n_proc) - 1 ;
020  MPI_COMM_WORLD.machine_id = zeros(1 ,n_proc) ;
021  
022  % Initialize machine database.
023  machine_db.n_machine = n_m ;			% Number of machines.
024  machine_db.type = cell(1 ,n_m) ;		% Unix or Windows.
025  machine_db.machine = cell(1 ,n_m) ;		% Machine names.
026  machine_db.dir = cell(1 ,n_m) ;			% Communication directory.
027  machine_db.matlab_command = cell(1 ,n_m) ;	% Matlab command.
028  machine_db.remote_launch = cell(1 ,n_m) ;	% Remote launch command.
029  machine_db.remote_flags = cell(1 ,n_m) ;	% Remote launch flags.
030  machine_db.n_proc = zeros(1 ,n_m) ;		% # processes on this machine.
031  machine_db.id_start = zeros(1 ,n_m) ;		% Start index.
032  machine_db.id_stop = zeros(1 ,n_m) ;		% Stop index.
033  
034  % Start setting up machine id.
035  for i_rank = 0:n_proc - 1
036      i_machine = mod(i_rank ,n_m) + 1 ;
037      machine_db.n_proc(1 ,i_machine) = machine_db.n_proc(1 ,i_machine) + 1 ;
038  end
039  
040  % Get possibly user settings.
041  machine_db_settings = MatMPI_Comm_settings ;
042  
043  % Set machine_db values.
044  for i = 1:n_m
045      machine_db.type{1 ,i} = machine_db_settings.type ;
046      machine_db.machine{1 ,i} = host ;
047      machine_db.dir{1 ,i} = [pwd ' / MatMPI'] ;
048      machine_db.matlab_command{1 ,i} = machine_db_settings.matlab_command ;
049      machine_db.remote_launch{1 ,i} = machine_db_settings.remote_launch ;
050      machine_db.remote_flags{1 ,i} = machine_db_settings.remote_flags ;
051      if (i ==  1)
052          machine_db.id_start(1 ,i) = 1 ;
053          machine_db.id_stop(1 ,i) = machine_db.id_start(1 ,i) + machine_db.n_proc(1 ,i) - 1 ;
054      else
055          machine_db.id_start(1 ,i) = machine_db.id_stop(1 ,i - 1) + 1 ;
056          machine_db.id_stop(1 ,i) = machine_db.id_start(1 ,i) + machine_db.n_proc(1 ,i) - 1 ;
057      end
058      
059      id_start = machine_db.id_start(1 ,i) ;
060      id_stop = machine_db.id_stop(1 ,i) ;
061      
062      MPI_COMM_WORLD.machine_id(1 ,id_start:id_stop) = i ;
063      
064      % Check if there is a machines list.
065      if (n_machines > 0)
066          machine = machines{i} ;
067          machine_db.machine{1 ,i} = machine ;
068          
069          % Check if there is a directory appended.
070          dir_sep = findstr(machine ,':') ;
071          if (dir_sep)
072              machine_piece = machine(1 ,1:dir_sep - 1) ;
073              dir_piece = machine(1 ,(dir_sep + 1):end) ;
074              machine_db.machine{1 ,i} = machine_piece ;
075              machine_db.dir{1 ,i} = dir_piece ;
076          end
077      end
078  end
079  
080  % Add machine_db to communicator.
081  MPI_COMM_WORLD.machine_db = machine_db ;
082  
083  % Write out.
084  comm_mat_file = 'MatMPI / MPI_COMM_WORLD.mat' ;
085  save(comm_mat_file ,'MPI_COMM_WORLD') ;
086  
087  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
088  % MatlabMPI
089  % Dr. Jeremy Kepner
090  % MIT Lincoln Laboratory
091  % kepner@ll.mit.edu
092  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
093  % Copyright 2002 Massachusetts Institute of Technology
094  %
095  % Permission is herby granted, without payment, to copy, modify, display
096  % and distribute this software and its documentation, if any, for any
097  % purpose, provided that the above copyright notices and the following
098  % three paragraphs appear in all copies of this software.  Use of this
099  % software constitutes acceptance of these terms and conditions.
100  %
101  % IN NO EVENT SHALL MIT BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
102  % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
103  % THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF MIT HAS BEEN ADVISED OF THE
104  % POSSIBILITY OF SUCH DAMAGE.
105  %
106  % MIT SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING,
107  % BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
108  % FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
109  %
110  % THIS SOFTWARE IS PROVIDED "AS IS," MIT HAS NO OBLIGATION TO PROVIDE
111  % MAINTENANCE, SUPPORT, UPDATE, ENHANCEMENTS, OR MODIFICATIONS.
112