01 function [message_rank , message_tag] = MPI_Probe( source , tag , comm )
02 % MPI_Probe - Returns a list of all messages waiting to be received.
03 %
04 % [message_rank, message_tag] = MPI_Probe( source, tag, comm )
05 %
06 % Source and tag can be an integer or a wildcard '*'.
07 %
08
09 % Get processor rank.
10 my_rank = MPI_Comm_rank(comm) ;
11
12 % Get lock file names.
13 lock_file = MatMPI_Lock_file(source ,my_rank ,tag ,comm) ;
14
15 % Check to see if there are any messages.
16 message_files = dir(lock_file) ;
17 n_files = length(message_files) ;
18
19 % Create single qoute.
20 q = strrep(' '' ' ,' ' ,'') ;
21
22 % Check if there are any files
23 if (n_files < 1)
24 % Set default (negative) return values.
25 message_rank = '' ;
26 message_tag = '' ;
27 else
28 % Create arrays to store rank and tag.
29 message_rank = zeros(n_files ,1) ;
30 message_tag = message_rank ;
31
32 % Set strings to search for (THIS IS VERY BAD, SHOULD HIDE THIS).
33 source_str = 'p' ;
34 dest_str = ['_p' num2str(my_rank) '_t'] ;
35 tag_str = '_lock.mat' ;
36 source_len = length(source_str) ;
37 dest_len = length(dest_str) ;
38 tag_len = length(tag_str) ;
39
40 % Step through each file name and strip out rank and tag.
41 for i_file = 1:n_files
42
43 % Get file name.
44 file_name = message_files(i_file).name ;
45
46 % Find location of each of the strings.
47 source_pos = findstr(file_name ,source_str) ;
48 dest_pos = findstr(file_name ,dest_str) ;
49 tag_pos = findstr(file_name ,tag_str) ;
50
51 % If we have found the location than extract rank and tag.
52 if (source_pos & dest_pos & tag_pos)
53
54 message_rank(i_file) = str2num(file_name(1 ,(source_len + 1):(dest_pos - 1))) ;
55 message_tag(i_file) = str2num(file_name(1 ,(dest_pos + dest_len):(tag_pos - 1))) ;
56
57 end
58
59 end
60
61 end
62
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 % MatlabMPI
65 % Dr. Jeremy Kepner
66 % MIT Lincoln Laboratory
67 % kepner@ll.mit.edu
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 % Copyright 2002 Massachusetts Institute of Technology
70 %
71 % Permission is herby granted, without payment, to copy, modify, display
72 % and distribute this software and its documentation, if any, for any
73 % purpose, provided that the above copyright notices and the following
74 % three paragraphs appear in all copies of this software. Use of this
75 % software constitutes acceptance of these terms and conditions.
76 %
77 % IN NO EVENT SHALL MIT BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
78 % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
79 % THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF MIT HAS BEEN ADVISED OF THE
80 % POSSIBILITY OF SUCH DAMAGE.
81 %
82 % MIT SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING,
83 % BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
84 % FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
85 %
86 % THIS SOFTWARE IS PROVIDED "AS IS," MIT HAS NO OBLIGATION TO PROVIDE
87 % MAINTENANCE, SUPPORT, UPDATE, ENHANCEMENTS, OR MODIFICATIONS.
88
89
|