function MatMPI_Delete_all()
% MatMPI_Delete_all  -  Deletes leftover MatlabMPI files.
% 
%  MatMPI_Delete_all()
%
%

  % First load MPI_COMM_WORLD.
  load 'MatMPI/MPI_COMM_WORLD.mat';

  % Set newline string.
  nl = sprintf('\n');
  % Get single quote character.
  q = strrep(' '' ',' ','');

  % Get number of machines.
  n_m = MPI_COMM_WORLD.machine_db.n_machine;

  % Loop backwards over each machine.
  for i_m=n_m:-1:1

    % Get number of processes to launch on this machine.
    n_proc_i_m = MPI_COMM_WORLD.machine_db.n_proc(1,i_m);

    if (n_proc_i_m >= 1)

      % Get communication directory.
      comm_dir = MPI_COMM_WORLD.machine_db.dir{1,i_m};

      % Delete buffer and lock files in this directory.
      delete([comm_dir '/p*_p*_t*_buffer.mat']);
      delete([comm_dir '/p*_p*_t*_lock.mat']);
    end

  end

  % Delete MatMPI directory.
  delete('MatMPI/*');
  delete('MatMPI');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MatlabMPI
% Dr. Jeremy Kepner
% MIT Lincoln Laboratory
% kepner@ll.mit.edu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright 2002 Massachusetts Institute of Technology
% 
% Permission is herby granted, without payment, to copy, modify, display
% and distribute this software and its documentation, if any, for any
% purpose, provided that the above copyright notices and the following
% three paragraphs appear in all copies of this software.  Use of this
% software constitutes acceptance of these terms and conditions.
%
% IN NO EVENT SHALL MIT BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
% SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
% THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF MIT HAS BEEN ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
% 
% MIT SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING,
% BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
% FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
%
% THIS SOFTWARE IS PROVIDED "AS IS," MIT HAS NO OBLIGATION TO PROVIDE
% MAINTENANCE, SUPPORT, UPDATE, ENHANCEMENTS, OR MODIFICATIONS.

