Routine Name MatMPI_Commands(m_file, rank, MPI_COMM_WORLD)
Routine Location MatlabMPI\MatMPI_Commands.m
Routine Purpose ---
Routine Arguments { defscommands, m_file, MPI_COMM_WORLD, rank, unix_command }
Routine Outputs { defscommands, unix_command }
Routine Size 105 line(s)
Routine Comment
Click here
Parent Routines
Child Routines
Routine Body

001  function [defscommands , unix_command] = ...
002  MatMPI_Commands(m_file ,rank ,MPI_COMM_WORLD)
003  % MatMPI_Commands  -  Commands to launch a matlab script remotely.
004  %
005  %  [defscommands, unix_command] = ...
006  %    MatMPI_Commands(m_file,rank,MPI_COMM_WORLD)
007  %
008  
009  % Set newline string.
010  nl = sprintf('\n') ;
011  
012  % Create filename each Matlab job will run at startup.
013  defsbase = ['MatMPI / defs' num2str(rank)] ;
014  defsfile = [defsbase '.m'] ;
015  comm_mat_file = 'MatMPI / MPI_COMM_WORLD.mat' ;
016  outfile = ['MatMPI / ' m_file '.' num2str(rank) '.out'] ;
017  
018  % Get single quote character.
019  q = strrep(' '' ' ,' ' ,'') ;
020  
021  % Create Matlab MPI setup commands.
022  commands{1} = ['global MPI_COMM_WORLD ;' nl] ;
023  commands{2} = ['load ' q comm_mat_file q ' ;' nl] ;
024  commands{3} = ['MPI_COMM_WORLD.rank = ' num2str(rank) ' ;' nl] ;
025  commands{4} = ['delete(' q defsfile q ') ;' nl] ;
026  commands{5} = [m_file ' ;' nl] ;
027  
028  defscommands = '' ;
029  
030  % Get name of host.
031  machine_id = MPI_COMM_WORLD.machine_id(1 ,rank + 1) ;
032  machine = MPI_COMM_WORLD.machine_db.machine{1 ,machine_id} ;
033  remote_launch = MPI_COMM_WORLD.machine_db.remote_launch{1 ,machine_id} ;
034  remote_flags = MPI_COMM_WORLD.machine_db.remote_flags{1 ,machine_id} ;
035  matlab_command = MPI_COMM_WORLD.machine_db.matlab_command{1 ,machine_id} ;
036  
037  % Print name of machine we are launching on.
038  disp(['Launching MPI rank: ' num2str(rank) ' on: ' machine]) ;
039  
040  % Create base matlab command.
041  matlab_command = [matlab_command ' < ' defsfile ' > ' outfile ] ;
042  % matlab_command = [matlab_command ' -r ' defsfile ' -logfile ' outfile ' > /def/null'];
043  % matlab_command = [matlab_command ' -r ' defsfile ' -logfile ' outfile ];
044  % matlab_command = [matlab_command ' -r ' defsfile ' > ' outfile ];
045  
046  % Determine how to run script and where to send output.
047  host = getenv('HOST') ;
048  if (strcmp(machine ,host))
049      if (rank ==  0)
050          % Run defsfile scipt interactively.
051          defscommands = [commands{1} commands{2} commands{3} commands{5}] ;
052          unix_command = nl ;
053      else
054          % Write commands to a .m text file.
055          fid = fopen(defsfile ,'wt') ;
056          n_command = size(commands ,2) ;
057          for i_command = 1:n_command
058              fwrite(fid ,commands{i_command}) ;
059          end
060          fclose(fid) ;
061          
062          % Create command to run defsfile locally and pipe output to another file.
063          unix_command = [matlab_command ' &' nl 'touch MatMPI / pid.' machine '.$!' nl] ;
064      end
065  else
066      
067      % Write commands to a .m text file.
068      fid = fopen(defsfile ,'wt') ;
069      n_command = size(commands ,2) ;
070      for i_command = 1:n_command
071          fwrite(fid ,commands{i_command}) ;
072      end
073      fclose(fid) ;
074      
075      % Create command to run defsfile locally and pipe output to another file.
076      unix_command = [matlab_command ' &' nl 'touch MatMPI / pid.' machine '.$!' nl] ;
077      
078  end
079  
080  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
081  % MatlabMPI
082  % Dr. Jeremy Kepner
083  % MIT Lincoln Laboratory
084  % kepner@ll.mit.edu
085  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
086  % Copyright 2002 Massachusetts Institute of Technology
087  %
088  % Permission is herby granted, without payment, to copy, modify, display
089  % and distribute this software and its documentation, if any, for any
090  % purpose, provided that the above copyright notices and the following
091  % three paragraphs appear in all copies of this software.  Use of this
092  % software constitutes acceptance of these terms and conditions.
093  %
094  % IN NO EVENT SHALL MIT BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
095  % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
096  % THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF MIT HAS BEEN ADVISED OF THE
097  % POSSIBILITY OF SUCH DAMAGE.
098  %
099  % MIT SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING,
100  % BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
101  % FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
102  %
103  % THIS SOFTWARE IS PROVIDED "AS IS," MIT HAS NO OBLIGATION TO PROVIDE
104  % MAINTENANCE, SUPPORT, UPDATE, ENHANCEMENTS, OR MODIFICATIONS.
105