001 function varargout = MPI_Bcast( source , tag , comm , varargin )
002 % MPI_Bcast - broadcast variables to everyone.
003 %
004 % [var1, var2, ...] = ...
005 % MPI_Bcast( source, tag, comm, var1, var2, ... )
006 %
007 % Broadcast variables to everyone in comm.
008 %
009 % Sender blocks until all the messages are received,
010 % unless MatMMPI_Save_messages(1) has been called.
011 %
012
013 % Get processor rank.
014 my_rank = MPI_Comm_rank(comm) ;
015 comm_size = MPI_Comm_size(comm) ;
016
017 % If not the source, then receive the data.
018 if (my_rank ~ = source)
019 varargout = MPI_Recv( source , tag , comm ) ;
020 end
021
022 % If the source, then send the data.
023 if (my_rank == source)
024
025 % Create data file.
026 buffer_file = MatMPI_Buffer_file(my_rank ,source ,tag ,comm) ;
027
028 % Save varargin to file.
029 save(buffer_file ,'varargin') ;
030
031 % Loop over everyone in comm and create link to data file.
032 link_command = '' ;
033 for i = 0:comm_size - 1
034 % Don't do source.
035 if (i ~ = source)
036
037 % Create buffer link name.
038 buffer_link = MatMPI_Buffer_file(my_rank ,i ,tag ,comm) ;
039
040 % Append to link_command.
041 link_command = [link_command 'ln - s ' buffer_file ' ' buffer_link ' ; '] ;
042 end
043 end
044
045 % Create symbolic link to data_file.
046 % unix(link_command);
047
048 % Write commands unix commands to .sh text file
049 % to fix Matlab's problem with very long commands sent to unix().
050 unix_link_file = ['MatMPI / Unix_Link_Commands_t' num2str(tag) '.sh'] ;
051 fid = fopen(unix_link_file ,'wt') ;
052 fwrite(fid ,link_command) ;
053 fclose(fid) ;
054 unix([' / bin / sh ' unix_link_file]) ;
055 delete(unix_link_file) ;
056
057 % Loop over everyone in comm and create lock file.
058 for i = 0:comm_size - 1
059 % Don't do source.
060 if (i ~ = source)
061 % Get lock file name.
062 lock_file = MatMPI_Lock_file(my_rank ,i ,tag ,comm) ;
063
064 % Create lock file.
065 fclose(fopen(lock_file ,'w')) ;
066 end
067 end
068
069
070 % Check if the message is to be saved.
071 if (not(comm.save_message_flag))
072
073 % Loop over lock files.
074 % Delete buffer_file when lock files are gone.
075 % Loop over everyone in comm and create lock file.
076 for i = 0:comm_size - 1
077 % Don't do source.
078 if (i ~ = source)
079 % Get lock file name.
080 lock_file = MatMPI_Lock_file(my_rank ,i ,tag ,comm) ;
081
082 % Spin on lock file until it is deleted.
083 loop = 0 ;
084 while exist(lock_file) ~ = 0
085 % pause(0.01);
086 loop = loop + 1 ;
087 end
088
089 end
090 end
091
092
093 % Delete buffer file.
094 if (not(comm.save_message_flag))
095 delete(buffer_file) ;
096 end
097
098 end
099
100 end
101
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 % MatlabMPI
104 % Dr. Jeremy Kepner
105 % MIT Lincoln Laboratory
106 % kepner@ll.mit.edu
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 % Copyright 2002 Massachusetts Institute of Technology
109 %
110 % Permission is herby granted, without payment, to copy, modify, display
111 % and distribute this software and its documentation, if any, for any
112 % purpose, provided that the above copyright notices and the following
113 % three paragraphs appear in all copies of this software. Use of this
114 % software constitutes acceptance of these terms and conditions.
115 %
116 % IN NO EVENT SHALL MIT BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
117 % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
118 % THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF MIT HAS BEEN ADVISED OF THE
119 % POSSIBILITY OF SUCH DAMAGE.
120 %
121 % MIT SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING,
122 % BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
123 % FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
124 %
125 % THIS SOFTWARE IS PROVIDED "AS IS," MIT HAS NO OBLIGATION TO PROVIDE
126 % MAINTENANCE, SUPPORT, UPDATE, ENHANCEMENTS, OR MODIFICATIONS.
127
|