1 using System;
2 using System.Drawing;
3 using System.Collections;
4 using System.ComponentModel;
5 using System.Windows.Forms;
6 using System.Data;
7 using Microsoft.Win32;
8 using System.IO;
9 using System.Threading;
10 using System.Diagnostics;
11 
12 namespace wmpiexec
13 {
14 	/// <summary>
15 	/// Summary description for Form1.
16 	/// </summary>
17 	public class wmpiexec : System.Windows.Forms.Form
18 	{
19 		private System.Windows.Forms.Label application_label;
20 		private System.Windows.Forms.Button application_browse_button;
21 		private System.Windows.Forms.Label nproc_label;
22 		private System.Windows.Forms.NumericUpDown nproc_numericUpDown;
23 		private System.Windows.Forms.Label wdir_label;
24 		private System.Windows.Forms.TextBox wdir_textBox;
25 		private System.Windows.Forms.Button wdir_browse_button;
26 		private System.Windows.Forms.Label hosts_label;
27 		private System.Windows.Forms.TextBox hosts_textBox;
28 		private System.Windows.Forms.Button hosts_reset_button;
29 		private System.Windows.Forms.Label configfile_label;
30 		private System.Windows.Forms.TextBox configfile_textBox;
31 		private System.Windows.Forms.Button configfile_browse_button;
32 		private System.Windows.Forms.Label mpich1_label;
33 		private System.Windows.Forms.TextBox mpich1_textBox;
34 		private System.Windows.Forms.Button mpich1_browse_button;
35 		private System.Windows.Forms.Label env_label;
36 		private System.Windows.Forms.TextBox env_textBox;
37 		private System.Windows.Forms.Label drive_map_label;
38 		private System.Windows.Forms.TextBox drive_map_textBox;
39 		private System.Windows.Forms.Label channel_label;
40 		private System.Windows.Forms.ComboBox channel_comboBox;
41 		private System.Windows.Forms.Button save_job_button;
42 		private System.Windows.Forms.Button load_job_button;
43 		private System.Windows.Forms.Button execute_button;
44 		private System.Windows.Forms.Button break_button;
45 		private System.Windows.Forms.RichTextBox output_richTextBox;
46 		private System.Windows.Forms.ComboBox application_comboBox;
47 		private System.Windows.Forms.Button show_command_button;
48 		private System.Windows.Forms.TextBox command_line_textBox;
49 		private System.Windows.Forms.RadioButton application_radioButton;
50 		private System.Windows.Forms.RadioButton configfile_radioButton;
51 		private System.Windows.Forms.RadioButton mpich1_radioButton;
52 		private System.Windows.Forms.CheckBox show_bottom_checkBox;
53 		private System.Windows.Forms.TextBox extra_options_textBox;
54 		private System.Windows.Forms.Label extra_options_label;
55 		private System.Windows.Forms.CheckBox popup_checkBox;
56 		private System.Windows.Forms.Button jumpshot_button;
57 		private System.Windows.Forms.CheckBox log_checkBox;
58 		/// <summary>
59 		/// Required designer variable.
60 		/// </summary>
61 		private System.ComponentModel.Container components = null;
62 
63 		private RunCommandDelegate run_command;
64 		private IAsyncResult last_execute_result;
65 		private Process process;
66 		private string thread_command;
67 		private string thread_mpiexec_command;
68 		private string thread_mpiexec_command_args;
69 		private bool thread_popup;
70 		private TextReader thread_output_stream;
71 		private TextReader thread_error_stream;
72 		private TextWriter thread_input_stream;
RunCommandDelegate(string command, string mpiexec_command, string mpiexec_command_args, bool popup)73 		delegate void RunCommandDelegate(string command, string mpiexec_command, string mpiexec_command_args, bool popup);
ReadOutputDelegate(TextReader stream)74 		delegate void ReadOutputDelegate(TextReader stream);
ReadErrorDelegate(TextReader stream)75 		delegate void ReadErrorDelegate(TextReader stream);
WriteInputDelegate(TextWriter stream)76 		delegate void WriteInputDelegate(TextWriter stream);
AppendTextDelegate(string str)77 		delegate void AppendTextDelegate(string str);
SetProcessDelegate(Process p)78 		delegate void SetProcessDelegate(Process p);
ResetExecuteButtonsDelegate()79 		delegate void ResetExecuteButtonsDelegate();
80 
81 		private string mpiexec_command, mpiexec_command_args;
82 		private int expanded_dialog_difference;
83 
wmpiexec()84 		public wmpiexec()
85 		{
86 			//
87 			// Required for Windows Form Designer support
88 			//
89 			InitializeComponent();
90 
91 			expanded_dialog_difference = mpich1_browse_button.Bottom - show_bottom_checkBox.Bottom + 8;
92 			//MessageBox.Show(string.Format("difference = {0}", mpich1_browse_button.Bottom - show_bottom_checkBox.Bottom));
93 
94 			run_command = null;
95 			last_execute_result = null;
96 			UpdateExtraControls(show_bottom_checkBox.Checked);
97 			EnableApplicationControls();
98 			DisableConfigfileControls();
99 			DisableMPICH1Controls();
100 		}
101 
102 		/// <summary>
103 		/// Clean up any resources being used.
104 		/// </summary>
Dispose( bool disposing )105 		protected override void Dispose( bool disposing )
106 		{
107 			if( disposing )
108 			{
109 				if (components != null)
110 				{
111 					components.Dispose();
112 				}
113 			}
114 			base.Dispose( disposing );
115 		}
116 
117 		#region Windows Form Designer generated code
118 		/// <summary>
119 		/// Required method for Designer support - do not modify
120 		/// the contents of this method with the code editor.
121 		/// </summary>
InitializeComponent()122 		private void InitializeComponent()
123 		{
124 			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(wmpiexec));
125 			this.application_label = new System.Windows.Forms.Label();
126 			this.application_browse_button = new System.Windows.Forms.Button();
127 			this.nproc_label = new System.Windows.Forms.Label();
128 			this.nproc_numericUpDown = new System.Windows.Forms.NumericUpDown();
129 			this.wdir_label = new System.Windows.Forms.Label();
130 			this.wdir_textBox = new System.Windows.Forms.TextBox();
131 			this.wdir_browse_button = new System.Windows.Forms.Button();
132 			this.hosts_label = new System.Windows.Forms.Label();
133 			this.hosts_textBox = new System.Windows.Forms.TextBox();
134 			this.hosts_reset_button = new System.Windows.Forms.Button();
135 			this.configfile_label = new System.Windows.Forms.Label();
136 			this.configfile_textBox = new System.Windows.Forms.TextBox();
137 			this.configfile_browse_button = new System.Windows.Forms.Button();
138 			this.mpich1_label = new System.Windows.Forms.Label();
139 			this.mpich1_textBox = new System.Windows.Forms.TextBox();
140 			this.mpich1_browse_button = new System.Windows.Forms.Button();
141 			this.env_label = new System.Windows.Forms.Label();
142 			this.env_textBox = new System.Windows.Forms.TextBox();
143 			this.drive_map_label = new System.Windows.Forms.Label();
144 			this.drive_map_textBox = new System.Windows.Forms.TextBox();
145 			this.channel_label = new System.Windows.Forms.Label();
146 			this.channel_comboBox = new System.Windows.Forms.ComboBox();
147 			this.save_job_button = new System.Windows.Forms.Button();
148 			this.load_job_button = new System.Windows.Forms.Button();
149 			this.execute_button = new System.Windows.Forms.Button();
150 			this.break_button = new System.Windows.Forms.Button();
151 			this.output_richTextBox = new System.Windows.Forms.RichTextBox();
152 			this.application_comboBox = new System.Windows.Forms.ComboBox();
153 			this.show_command_button = new System.Windows.Forms.Button();
154 			this.command_line_textBox = new System.Windows.Forms.TextBox();
155 			this.application_radioButton = new System.Windows.Forms.RadioButton();
156 			this.configfile_radioButton = new System.Windows.Forms.RadioButton();
157 			this.mpich1_radioButton = new System.Windows.Forms.RadioButton();
158 			this.show_bottom_checkBox = new System.Windows.Forms.CheckBox();
159 			this.extra_options_textBox = new System.Windows.Forms.TextBox();
160 			this.extra_options_label = new System.Windows.Forms.Label();
161 			this.popup_checkBox = new System.Windows.Forms.CheckBox();
162 			this.jumpshot_button = new System.Windows.Forms.Button();
163 			this.log_checkBox = new System.Windows.Forms.CheckBox();
164 			((System.ComponentModel.ISupportInitialize)(this.nproc_numericUpDown)).BeginInit();
165 			this.SuspendLayout();
166 			//
167 			// application_label
168 			//
169 			this.application_label.Location = new System.Drawing.Point(24, 8);
170 			this.application_label.Name = "application_label";
171 			this.application_label.Size = new System.Drawing.Size(64, 23);
172 			this.application_label.TabIndex = 1;
173 			this.application_label.Text = "Application";
174 			//
175 			// application_browse_button
176 			//
177 			this.application_browse_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
178 			this.application_browse_button.Location = new System.Drawing.Point(480, 8);
179 			this.application_browse_button.Name = "application_browse_button";
180 			this.application_browse_button.Size = new System.Drawing.Size(24, 21);
181 			this.application_browse_button.TabIndex = 3;
182 			this.application_browse_button.Text = "...";
183 			this.application_browse_button.Click += new System.EventHandler(this.application_browse_button_Click);
184 			//
185 			// nproc_label
186 			//
187 			this.nproc_label.Location = new System.Drawing.Point(24, 32);
188 			this.nproc_label.Name = "nproc_label";
189 			this.nproc_label.Size = new System.Drawing.Size(112, 23);
190 			this.nproc_label.TabIndex = 3;
191 			this.nproc_label.Text = "Number of processes";
192 			//
193 			// nproc_numericUpDown
194 			//
195 			this.nproc_numericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
196 			this.nproc_numericUpDown.Location = new System.Drawing.Point(456, 32);
197 			this.nproc_numericUpDown.Maximum = new System.Decimal(new int[] {
198 																				10000,
199 																				0,
200 																				0,
201 																				0});
202 			this.nproc_numericUpDown.Minimum = new System.Decimal(new int[] {
203 																				1,
204 																				0,
205 																				0,
206 																				0});
207 			this.nproc_numericUpDown.Name = "nproc_numericUpDown";
208 			this.nproc_numericUpDown.Size = new System.Drawing.Size(48, 20);
209 			this.nproc_numericUpDown.TabIndex = 4;
210 			this.nproc_numericUpDown.Value = new System.Decimal(new int[] {
211 																			  1,
212 																			  0,
213 																			  0,
214 																			  0});
215 			//
216 			// wdir_label
217 			//
218 			this.wdir_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
219 			this.wdir_label.Location = new System.Drawing.Point(24, 368);
220 			this.wdir_label.Name = "wdir_label";
221 			this.wdir_label.Size = new System.Drawing.Size(96, 24);
222 			this.wdir_label.TabIndex = 5;
223 			this.wdir_label.Text = "working directory";
224 			//
225 			// wdir_textBox
226 			//
227 			this.wdir_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
228 				| System.Windows.Forms.AnchorStyles.Right)));
229 			this.wdir_textBox.Location = new System.Drawing.Point(152, 368);
230 			this.wdir_textBox.Name = "wdir_textBox";
231 			this.wdir_textBox.Size = new System.Drawing.Size(328, 20);
232 			this.wdir_textBox.TabIndex = 13;
233 			this.wdir_textBox.Text = "";
234 			//
235 			// wdir_browse_button
236 			//
237 			this.wdir_browse_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
238 			this.wdir_browse_button.Location = new System.Drawing.Point(480, 368);
239 			this.wdir_browse_button.Name = "wdir_browse_button";
240 			this.wdir_browse_button.Size = new System.Drawing.Size(24, 20);
241 			this.wdir_browse_button.TabIndex = 14;
242 			this.wdir_browse_button.Text = "...";
243 			this.wdir_browse_button.Click += new System.EventHandler(this.wdir_browse_button_Click);
244 			//
245 			// hosts_label
246 			//
247 			this.hosts_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
248 			this.hosts_label.Location = new System.Drawing.Point(24, 392);
249 			this.hosts_label.Name = "hosts_label";
250 			this.hosts_label.Size = new System.Drawing.Size(32, 23);
251 			this.hosts_label.TabIndex = 8;
252 			this.hosts_label.Text = "hosts";
253 			//
254 			// hosts_textBox
255 			//
256 			this.hosts_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
257 				| System.Windows.Forms.AnchorStyles.Right)));
258 			this.hosts_textBox.Location = new System.Drawing.Point(152, 392);
259 			this.hosts_textBox.Name = "hosts_textBox";
260 			this.hosts_textBox.Size = new System.Drawing.Size(312, 20);
261 			this.hosts_textBox.TabIndex = 15;
262 			this.hosts_textBox.Text = "";
263 			//
264 			// hosts_reset_button
265 			//
266 			this.hosts_reset_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
267 			this.hosts_reset_button.Location = new System.Drawing.Point(464, 392);
268 			this.hosts_reset_button.Name = "hosts_reset_button";
269 			this.hosts_reset_button.Size = new System.Drawing.Size(40, 20);
270 			this.hosts_reset_button.TabIndex = 16;
271 			this.hosts_reset_button.Text = "reset";
272 			this.hosts_reset_button.Click += new System.EventHandler(this.hosts_reset_button_Click);
273 			//
274 			// configfile_label
275 			//
276 			this.configfile_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
277 			this.configfile_label.Location = new System.Drawing.Point(24, 524);
278 			this.configfile_label.Name = "configfile_label";
279 			this.configfile_label.Size = new System.Drawing.Size(88, 16);
280 			this.configfile_label.TabIndex = 11;
281 			this.configfile_label.Text = "configuration file";
282 			//
283 			// configfile_textBox
284 			//
285 			this.configfile_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
286 				| System.Windows.Forms.AnchorStyles.Right)));
287 			this.configfile_textBox.Location = new System.Drawing.Point(152, 522);
288 			this.configfile_textBox.Name = "configfile_textBox";
289 			this.configfile_textBox.Size = new System.Drawing.Size(320, 20);
290 			this.configfile_textBox.TabIndex = 22;
291 			this.configfile_textBox.Text = "";
292 			//
293 			// configfile_browse_button
294 			//
295 			this.configfile_browse_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
296 			this.configfile_browse_button.Location = new System.Drawing.Point(480, 522);
297 			this.configfile_browse_button.Name = "configfile_browse_button";
298 			this.configfile_browse_button.Size = new System.Drawing.Size(24, 20);
299 			this.configfile_browse_button.TabIndex = 23;
300 			this.configfile_browse_button.Text = "...";
301 			this.configfile_browse_button.Click += new System.EventHandler(this.configfile_browse_button_Click);
302 			//
303 			// mpich1_label
304 			//
305 			this.mpich1_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
306 			this.mpich1_label.Location = new System.Drawing.Point(24, 548);
307 			this.mpich1_label.Name = "mpich1_label";
308 			this.mpich1_label.Size = new System.Drawing.Size(128, 16);
309 			this.mpich1_label.TabIndex = 14;
310 			this.mpich1_label.Text = "mpich1 configuration file";
311 			//
312 			// mpich1_textBox
313 			//
314 			this.mpich1_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
315 				| System.Windows.Forms.AnchorStyles.Right)));
316 			this.mpich1_textBox.Location = new System.Drawing.Point(152, 546);
317 			this.mpich1_textBox.Name = "mpich1_textBox";
318 			this.mpich1_textBox.Size = new System.Drawing.Size(320, 20);
319 			this.mpich1_textBox.TabIndex = 25;
320 			this.mpich1_textBox.Text = "";
321 			//
322 			// mpich1_browse_button
323 			//
324 			this.mpich1_browse_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
325 			this.mpich1_browse_button.Location = new System.Drawing.Point(480, 546);
326 			this.mpich1_browse_button.Name = "mpich1_browse_button";
327 			this.mpich1_browse_button.Size = new System.Drawing.Size(24, 20);
328 			this.mpich1_browse_button.TabIndex = 26;
329 			this.mpich1_browse_button.Text = "...";
330 			this.mpich1_browse_button.Click += new System.EventHandler(this.mpich1_browse_button_Click);
331 			//
332 			// env_label
333 			//
334 			this.env_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
335 			this.env_label.Location = new System.Drawing.Point(24, 416);
336 			this.env_label.Name = "env_label";
337 			this.env_label.Size = new System.Drawing.Size(120, 23);
338 			this.env_label.TabIndex = 17;
339 			this.env_label.Text = "environment variables";
340 			//
341 			// env_textBox
342 			//
343 			this.env_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
344 				| System.Windows.Forms.AnchorStyles.Right)));
345 			this.env_textBox.Location = new System.Drawing.Point(152, 416);
346 			this.env_textBox.Name = "env_textBox";
347 			this.env_textBox.Size = new System.Drawing.Size(352, 20);
348 			this.env_textBox.TabIndex = 17;
349 			this.env_textBox.Text = "";
350 			//
351 			// drive_map_label
352 			//
353 			this.drive_map_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
354 			this.drive_map_label.Location = new System.Drawing.Point(24, 440);
355 			this.drive_map_label.Name = "drive_map_label";
356 			this.drive_map_label.Size = new System.Drawing.Size(88, 23);
357 			this.drive_map_label.TabIndex = 19;
358 			this.drive_map_label.Text = "drive mappings";
359 			//
360 			// drive_map_textBox
361 			//
362 			this.drive_map_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
363 				| System.Windows.Forms.AnchorStyles.Right)));
364 			this.drive_map_textBox.Location = new System.Drawing.Point(152, 440);
365 			this.drive_map_textBox.Name = "drive_map_textBox";
366 			this.drive_map_textBox.Size = new System.Drawing.Size(352, 20);
367 			this.drive_map_textBox.TabIndex = 18;
368 			this.drive_map_textBox.Text = "";
369 			//
370 			// channel_label
371 			//
372 			this.channel_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
373 			this.channel_label.Location = new System.Drawing.Point(24, 464);
374 			this.channel_label.Name = "channel_label";
375 			this.channel_label.Size = new System.Drawing.Size(48, 23);
376 			this.channel_label.TabIndex = 21;
377 			this.channel_label.Text = "channel";
378 			//
379 			// channel_comboBox
380 			//
381 			this.channel_comboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
382 			this.channel_comboBox.Items.AddRange(new object[] {
383 																  "sock",
384 																  "nemesis",
385 																  "shm",
386 																  "ssm",
387 																  "mt",
388 																  "default",
389 																  "auto"});
390 			this.channel_comboBox.Location = new System.Drawing.Point(424, 464);
391 			this.channel_comboBox.Name = "channel_comboBox";
392 			this.channel_comboBox.Size = new System.Drawing.Size(80, 21);
393 			this.channel_comboBox.TabIndex = 19;
394 			this.channel_comboBox.Text = "default";
395 			//
396 			// save_job_button
397 			//
398 			this.save_job_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
399 			this.save_job_button.Location = new System.Drawing.Point(429, 56);
400 			this.save_job_button.Name = "save_job_button";
401 			this.save_job_button.TabIndex = 8;
402 			this.save_job_button.Text = "Save Job";
403 			this.save_job_button.Click += new System.EventHandler(this.save_job_button_Click);
404 			//
405 			// load_job_button
406 			//
407 			this.load_job_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
408 			this.load_job_button.Location = new System.Drawing.Point(352, 56);
409 			this.load_job_button.Name = "load_job_button";
410 			this.load_job_button.TabIndex = 7;
411 			this.load_job_button.Text = "Load Job";
412 			this.load_job_button.Click += new System.EventHandler(this.load_job_button_Click);
413 			//
414 			// execute_button
415 			//
416 			this.execute_button.Location = new System.Drawing.Point(8, 56);
417 			this.execute_button.Name = "execute_button";
418 			this.execute_button.TabIndex = 5;
419 			this.execute_button.Text = "Execute";
420 			this.execute_button.Click += new System.EventHandler(this.execute_button_Click);
421 			//
422 			// break_button
423 			//
424 			this.break_button.Enabled = false;
425 			this.break_button.Location = new System.Drawing.Point(88, 56);
426 			this.break_button.Name = "break_button";
427 			this.break_button.TabIndex = 6;
428 			this.break_button.Text = "Break";
429 			this.break_button.Click += new System.EventHandler(this.break_button_Click);
430 			//
431 			// output_richTextBox
432 			//
433 			this.output_richTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
434 				| System.Windows.Forms.AnchorStyles.Left)
435 				| System.Windows.Forms.AnchorStyles.Right)));
436 			this.output_richTextBox.Font = new System.Drawing.Font("Lucida Console", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
437 			this.output_richTextBox.Location = new System.Drawing.Point(8, 104);
438 			this.output_richTextBox.Name = "output_richTextBox";
439 			this.output_richTextBox.Size = new System.Drawing.Size(496, 224);
440 			this.output_richTextBox.TabIndex = 11;
441 			this.output_richTextBox.Text = "";
442 			this.output_richTextBox.WordWrap = false;
443 			this.output_richTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.output_richTextBox_KeyPress);
444 			//
445 			// application_comboBox
446 			//
447 			this.application_comboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
448 				| System.Windows.Forms.AnchorStyles.Right)));
449 			this.application_comboBox.Location = new System.Drawing.Point(88, 8);
450 			this.application_comboBox.Name = "application_comboBox";
451 			this.application_comboBox.Size = new System.Drawing.Size(392, 21);
452 			this.application_comboBox.TabIndex = 2;
453 			//
454 			// show_command_button
455 			//
456 			this.show_command_button.Location = new System.Drawing.Point(8, 80);
457 			this.show_command_button.Name = "show_command_button";
458 			this.show_command_button.Size = new System.Drawing.Size(96, 23);
459 			this.show_command_button.TabIndex = 9;
460 			this.show_command_button.Text = "Show Command";
461 			this.show_command_button.Click += new System.EventHandler(this.show_command_button_Click);
462 			//
463 			// command_line_textBox
464 			//
465 			this.command_line_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
466 				| System.Windows.Forms.AnchorStyles.Right)));
467 			this.command_line_textBox.Location = new System.Drawing.Point(104, 80);
468 			this.command_line_textBox.Name = "command_line_textBox";
469 			this.command_line_textBox.ReadOnly = true;
470 			this.command_line_textBox.Size = new System.Drawing.Size(400, 20);
471 			this.command_line_textBox.TabIndex = 10;
472 			this.command_line_textBox.Text = "";
473 			//
474 			// application_radioButton
475 			//
476 			this.application_radioButton.Checked = true;
477 			this.application_radioButton.Location = new System.Drawing.Point(8, 8);
478 			this.application_radioButton.Name = "application_radioButton";
479 			this.application_radioButton.Size = new System.Drawing.Size(16, 24);
480 			this.application_radioButton.TabIndex = 1;
481 			this.application_radioButton.TabStop = true;
482 			this.application_radioButton.CheckedChanged += new System.EventHandler(this.application_radioButton_CheckedChanged);
483 			//
484 			// configfile_radioButton
485 			//
486 			this.configfile_radioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
487 			this.configfile_radioButton.Location = new System.Drawing.Point(8, 520);
488 			this.configfile_radioButton.Name = "configfile_radioButton";
489 			this.configfile_radioButton.Size = new System.Drawing.Size(16, 24);
490 			this.configfile_radioButton.TabIndex = 21;
491 			this.configfile_radioButton.CheckedChanged += new System.EventHandler(this.configfile_radioButton_CheckedChanged);
492 			//
493 			// mpich1_radioButton
494 			//
495 			this.mpich1_radioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
496 			this.mpich1_radioButton.Location = new System.Drawing.Point(8, 544);
497 			this.mpich1_radioButton.Name = "mpich1_radioButton";
498 			this.mpich1_radioButton.Size = new System.Drawing.Size(16, 24);
499 			this.mpich1_radioButton.TabIndex = 24;
500 			this.mpich1_radioButton.CheckedChanged += new System.EventHandler(this.mpich1_radioButton_CheckedChanged);
501 			//
502 			// show_bottom_checkBox
503 			//
504 			this.show_bottom_checkBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
505 			this.show_bottom_checkBox.Location = new System.Drawing.Point(8, 328);
506 			this.show_bottom_checkBox.Name = "show_bottom_checkBox";
507 			this.show_bottom_checkBox.Size = new System.Drawing.Size(96, 16);
508 			this.show_bottom_checkBox.TabIndex = 12;
509 			this.show_bottom_checkBox.Text = "more options";
510 			this.show_bottom_checkBox.CheckedChanged += new System.EventHandler(this.show_bottom_checkBox_CheckedChanged);
511 			//
512 			// extra_options_textBox
513 			//
514 			this.extra_options_textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
515 				| System.Windows.Forms.AnchorStyles.Right)));
516 			this.extra_options_textBox.Location = new System.Drawing.Point(152, 496);
517 			this.extra_options_textBox.Name = "extra_options_textBox";
518 			this.extra_options_textBox.Size = new System.Drawing.Size(352, 20);
519 			this.extra_options_textBox.TabIndex = 27;
520 			this.extra_options_textBox.Text = "";
521 			//
522 			// extra_options_label
523 			//
524 			this.extra_options_label.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
525 			this.extra_options_label.Location = new System.Drawing.Point(24, 496);
526 			this.extra_options_label.Name = "extra_options_label";
527 			this.extra_options_label.Size = new System.Drawing.Size(120, 23);
528 			this.extra_options_label.TabIndex = 28;
529 			this.extra_options_label.Text = "extra mpiexec options";
530 			//
531 			// popup_checkBox
532 			//
533 			this.popup_checkBox.Location = new System.Drawing.Point(168, 56);
534 			this.popup_checkBox.Name = "popup_checkBox";
535 			this.popup_checkBox.Size = new System.Drawing.Size(168, 24);
536 			this.popup_checkBox.TabIndex = 29;
537 			this.popup_checkBox.Text = "run in an separate window";
538 			//
539 			// jumpshot_button
540 			//
541 			this.jumpshot_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
542 			this.jumpshot_button.Location = new System.Drawing.Point(432, 336);
543 			this.jumpshot_button.Name = "jumpshot_button";
544 			this.jumpshot_button.Size = new System.Drawing.Size(75, 24);
545 			this.jumpshot_button.TabIndex = 30;
546 			this.jumpshot_button.Text = "Jumpshot";
547 			this.jumpshot_button.Click += new System.EventHandler(this.jumpshot_button_Click);
548 			//
549 			// log_checkBox
550 			//
551 			this.log_checkBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
552 			this.log_checkBox.Location = new System.Drawing.Point(312, 336);
553 			this.log_checkBox.Name = "log_checkBox";
554 			this.log_checkBox.Size = new System.Drawing.Size(112, 24);
555 			this.log_checkBox.TabIndex = 31;
556 			this.log_checkBox.Text = "produce clog2 file";
557 			//
558 			// wmpiexec
559 			//
560 			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
561 			this.ClientSize = new System.Drawing.Size(512, 579);
562 			this.Controls.Add(this.log_checkBox);
563 			this.Controls.Add(this.jumpshot_button);
564 			this.Controls.Add(this.popup_checkBox);
565 			this.Controls.Add(this.extra_options_label);
566 			this.Controls.Add(this.extra_options_textBox);
567 			this.Controls.Add(this.application_radioButton);
568 			this.Controls.Add(this.command_line_textBox);
569 			this.Controls.Add(this.drive_map_textBox);
570 			this.Controls.Add(this.env_textBox);
571 			this.Controls.Add(this.mpich1_textBox);
572 			this.Controls.Add(this.configfile_textBox);
573 			this.Controls.Add(this.hosts_textBox);
574 			this.Controls.Add(this.wdir_textBox);
575 			this.Controls.Add(this.show_bottom_checkBox);
576 			this.Controls.Add(this.mpich1_radioButton);
577 			this.Controls.Add(this.configfile_radioButton);
578 			this.Controls.Add(this.show_command_button);
579 			this.Controls.Add(this.application_comboBox);
580 			this.Controls.Add(this.output_richTextBox);
581 			this.Controls.Add(this.break_button);
582 			this.Controls.Add(this.execute_button);
583 			this.Controls.Add(this.load_job_button);
584 			this.Controls.Add(this.save_job_button);
585 			this.Controls.Add(this.channel_comboBox);
586 			this.Controls.Add(this.channel_label);
587 			this.Controls.Add(this.drive_map_label);
588 			this.Controls.Add(this.env_label);
589 			this.Controls.Add(this.mpich1_browse_button);
590 			this.Controls.Add(this.mpich1_label);
591 			this.Controls.Add(this.configfile_browse_button);
592 			this.Controls.Add(this.configfile_label);
593 			this.Controls.Add(this.hosts_reset_button);
594 			this.Controls.Add(this.hosts_label);
595 			this.Controls.Add(this.wdir_browse_button);
596 			this.Controls.Add(this.wdir_label);
597 			this.Controls.Add(this.nproc_numericUpDown);
598 			this.Controls.Add(this.nproc_label);
599 			this.Controls.Add(this.application_browse_button);
600 			this.Controls.Add(this.application_label);
601 			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
602 			this.Name = "wmpiexec";
603 			this.Text = "MPIEXEC wrapper";
604 			this.Closing += new System.ComponentModel.CancelEventHandler(this.wmpiexec_Closing);
605 			((System.ComponentModel.ISupportInitialize)(this.nproc_numericUpDown)).EndInit();
606 			this.ResumeLayout(false);
607 
608 		}
609 		#endregion
610 
611 		/// <summary>
612 		/// The main entry point for the application.
613 		/// </summary>
614 		[STAThread]
Main()615 		static void Main()
616 		{
617 			Application.Run(new wmpiexec());
618 		}
619 
AppendText(string str)620 		private void AppendText(string str)
621 		{
622 			output_richTextBox.AppendText(str);
623 		}
624 
SetProcess(Process p)625 		private void SetProcess(Process p)
626 		{
627 			process = p;
628 		}
629 
ResetExecuteButtons()630 		private void ResetExecuteButtons()
631 		{
632 			execute_button.Enabled = true;
633 			break_button.Enabled = false;
634 		}
635 
application_browse_button_Click(object sender, System.EventArgs e)636 		private void application_browse_button_Click(object sender, System.EventArgs e)
637 		{
638 			OpenFileDialog dlg = new OpenFileDialog();
639 			dlg.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*";
640 			if (dlg.ShowDialog() == DialogResult.OK)
641 			{
642 				if (dlg.FileName.IndexOf(' ') != -1)
643 				{
644 					application_comboBox.Text = "\"" + dlg.FileName + "\"";
645 				}
646 				else
647 				{
648 					application_comboBox.Text = dlg.FileName;
649 				}
650 			}
651 		}
652 
wdir_browse_button_Click(object sender, System.EventArgs e)653 		private void wdir_browse_button_Click(object sender, System.EventArgs e)
654 		{
655 			FolderBrowserDialog dlg = new FolderBrowserDialog();
656 			if (wdir_textBox.Text.Length > 0)
657 			{
658 				dlg.SelectedPath = wdir_textBox.Text;
659 			}
660 			else
661 			{
662 				dlg.SelectedPath = Environment.CurrentDirectory;
663 			}
664 			if (dlg.ShowDialog() == DialogResult.OK)
665 			{
666 				wdir_textBox.Text = dlg.SelectedPath;
667 			}
668 		}
669 
hosts_reset_button_Click(object sender, System.EventArgs e)670 		private void hosts_reset_button_Click(object sender, System.EventArgs e)
671 		{
672 			object obj;
673 			RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD");
674 			obj = key.GetValue("hosts");
675 			if (obj != null)
676 			{
677 				hosts_textBox.Text = obj.ToString();
678 			}
679 			else
680 			{
681 				hosts_textBox.Text = "";
682 			}
683 		}
684 
configfile_browse_button_Click(object sender, System.EventArgs e)685 		private void configfile_browse_button_Click(object sender, System.EventArgs e)
686 		{
687 			OpenFileDialog dlg = new OpenFileDialog();
688 			dlg.Filter = "All files (*.*)|*.*";
689 			if (dlg.ShowDialog() == DialogResult.OK)
690 			{
691 				configfile_textBox.Text = dlg.FileName;
692 			}
693 		}
694 
mpich1_browse_button_Click(object sender, System.EventArgs e)695 		private void mpich1_browse_button_Click(object sender, System.EventArgs e)
696 		{
697 			OpenFileDialog dlg = new OpenFileDialog();
698 			dlg.Filter = "Configuration file (*.cfg)|*.cfg|All files (*.*)|*.*";
699 			if (dlg.ShowDialog() == DialogResult.OK)
700 			{
701 				mpich1_textBox.Text = dlg.FileName;
702 			}
703 		}
704 
save_job_button_Click(object sender, System.EventArgs e)705 		private void save_job_button_Click(object sender, System.EventArgs e)
706 		{
707 			SaveFileDialog dlg = new SaveFileDialog();
708 			dlg.Filter = "Job files (*.txt *.mpi)|*.txt;*.mpi|All files (*.*)|*.*";
709 			if (dlg.ShowDialog() == DialogResult.OK)
710 			{
711 				StreamWriter stream;
712 				using (stream = new StreamWriter(dlg.FileName))
713 				{
714 					stream.WriteLine("exe {0}", application_comboBox.Text.Trim());
715 					stream.WriteLine("n {0}", nproc_numericUpDown.Value);
716 					stream.WriteLine("wdir {0}", wdir_textBox.Text.Trim());
717 					stream.WriteLine("hosts {0}", hosts_textBox.Text.Trim());
718 					stream.WriteLine("cfg {0}", configfile_textBox.Text.Trim());
719 					stream.WriteLine("mpich1 {0}", mpich1_textBox.Text.Trim());
720 					stream.WriteLine("env {0}", env_textBox.Text.Trim());
721 					stream.WriteLine("map {0}", drive_map_textBox.Text.Trim());
722 					stream.WriteLine("channel {0}", channel_comboBox.Text.Trim());
723 					stream.WriteLine("extra {0}", extra_options_textBox.Text.Trim());
724 					stream.WriteLine(popup_checkBox.Checked ? "window yes" : "window no");
725 					stream.WriteLine(log_checkBox.Checked ? "log yes" : "log no");
726 					stream.Close();
727 				}
728 			}
729 		}
730 
load_job_button_Click(object sender, System.EventArgs e)731 		private void load_job_button_Click(object sender, System.EventArgs e)
732 		{
733 			OpenFileDialog dlg = new OpenFileDialog();
734 			dlg.Filter = "Job files (*.txt *.mpi)|*.txt;*.mpi|All files (*.*)|*.*";
735 			if (dlg.ShowDialog() == DialogResult.OK)
736 			{
737 				StreamReader stream;
738 				using (stream = new StreamReader(dlg.FileName))
739 				{
740 					string line;
741 					int index;
742 
743 					// reset all the values before loading new ones
744 					application_comboBox.Text = "";
745 					nproc_numericUpDown.Value = 1;
746 					wdir_textBox.Text = "";
747 					hosts_textBox.Text = "";
748 					configfile_textBox.Text = "";
749 					mpich1_textBox.Text = "";
750 					env_textBox.Text = "";
751 					drive_map_textBox.Text = "";
752 					channel_comboBox.Text = "";
753 					extra_options_textBox.Text = "";
754 					popup_checkBox.Checked = false;
755 					log_checkBox.Checked = false;
756 
757 					line = stream.ReadLine();
758 					while (line != null)
759 					{
760 						index = line.IndexOf(" ");
761 						if (index > 0)
762 						{
763 							string key, val;
764 							key = line.Substring(0, index);
765 							val = line.Substring(index+1);
766 							switch (key)
767 							{
768 								case "exe":
769 									application_comboBox.Text = val;
770 									break;
771 								case "n":
772 									nproc_numericUpDown.Value = Convert.ToInt32(val);
773 									break;
774 								case "wdir":
775 									wdir_textBox.Text = val;
776 									break;
777 								case "hosts":
778 									hosts_textBox.Text = val;
779 									break;
780 								case "cfg":
781 									configfile_textBox.Text = val;
782 									break;
783 								case "mpich1":
784 									mpich1_textBox.Text = val;
785 									break;
786 								case "env":
787 									env_textBox.Text = val;
788 									break;
789 								case "map":
790 									drive_map_textBox.Text = val;
791 									break;
792 								case "channel":
793 									channel_comboBox.Text = val;
794 									break;
795 								case "extra":
796 									extra_options_textBox.Text = val;
797 									break;
798 								case "window":
799 									if (val == "yes")
800 										popup_checkBox.Checked = true;
801 									else
802 										popup_checkBox.Checked = false;
803 									break;
804 								case "log":
805 									if (val == "yes")
806 										log_checkBox.Checked = true;
807 									else
808 										log_checkBox.Checked = false;
809 									break;
810 							}
811 						}
812 						line = stream.ReadLine();
813 					}
814 					stream.Close();
815 				}
816 			}
817 		}
818 
819 		#region Process thread functions
820 		/// <summary>
821 		/// These functions read and write input and output of the spawned mpiexec process.
822 		/// They are run in separate threads since they can execute for a long period of time
823 		/// and therefore shouldn't come from the thread pool (delegates).
824 		/// Is this a correct design decision?
825 		/// </summary>
ReadOutput(TextReader stream)826 		private void ReadOutput(TextReader stream)
827 		{
828 			thread_output_stream = stream;
829 			Thread thread = new Thread(new ThreadStart(ReadOutputThread));
830 			thread.Start();
831 		}
832 
ReadError(TextReader stream)833 		private void ReadError(TextReader stream)
834 		{
835 			thread_error_stream = stream;
836 			Thread thread = new Thread(new ThreadStart(ReadErrorThread));
837 			thread.Start();
838 		}
839 
ReadErrorThread()840 		private void ReadErrorThread()
841 		{
842 			int num_read;
843 			char [] buffer = new char[4096];
844 			TextReader stream = thread_error_stream;
845 			num_read = stream.Read(buffer, 0, 4096);
846 			while (num_read > 0)
847 			{
848 				string str;
849 				char [] text = new char[num_read];
850 				Array.Copy(buffer, 0, text, 0, num_read);
851 				str = new string(text);
852 				object[] pList = { str };
853 				// put the string in the edit box in a thread safe way
854 				AppendTextDelegate ap = new AppendTextDelegate(AppendText);
855 				output_richTextBox.Invoke(ap, pList);
856 				num_read = stream.Read(buffer, 0, 1024);
857 			}
858 		}
859 
ReadOutputThread()860 		private void ReadOutputThread()
861 		{
862 			int num_read;
863 			char [] buffer = new char[4096];
864 			TextReader stream = thread_output_stream;
865 			num_read = stream.Read(buffer, 0, 4096);
866 			while (num_read > 0)
867 			{
868 				string str;
869 				char [] text = new char[num_read];
870 				Array.Copy(buffer, 0, text, 0, num_read);
871 				str = new string(text);
872 				object[] pList = { str };
873 				// put the string in the edit box in a thread safe way
874 				AppendTextDelegate ap = new AppendTextDelegate(AppendText);
875 				output_richTextBox.Invoke(ap, pList);
876 				num_read = stream.Read(buffer, 0, 1024);
877 			}
878 		}
879 
880 		ManualResetEvent char_available = new ManualResetEvent(false);
881 		ManualResetEvent char_written = new ManualResetEvent(true);
882 		bool quit_input = false;
883 		char ch;
WriteInput(TextWriter stream)884 		private void WriteInput(TextWriter stream)
885 		{
886 			thread_input_stream = stream;
887 			Thread thread = new Thread(new ThreadStart(WriteInputThread));
888 			thread.Start();
889 		}
890 
WriteInputThread()891 		private void WriteInputThread()
892 		{
893 			WriteInputEx(thread_input_stream);
894 		}
895 
WriteInputEx(TextWriter stream)896 		private void WriteInputEx(TextWriter stream)
897 		{
898 			while (char_available.WaitOne())
899 			{
900 				if (quit_input)
901 				{
902 					return;
903 				}
904 				stream.Write(ch);
905 				stream.Flush();
906 				char_available.Reset();
907 				char_written.Set();
908 
909 				/*
910 				object[] pList = { "ch(" + ch + ")" };
911 				// put the string in the edit box in a thread safe way
912 				AppendTextDelegate ap = new AppendTextDelegate(AppendText);
913 				output_richTextBox.Invoke(ap, pList);
914 				*/
915 			}
916 		}
917 
RunCommand(string command, string mpiexec_command, string mpiexec_command_args, bool popup)918 		private void RunCommand(string command, string mpiexec_command, string mpiexec_command_args, bool popup)
919 		{
920 			thread_command = command;
921 			thread_mpiexec_command = mpiexec_command;
922 			thread_mpiexec_command_args = mpiexec_command_args;
923 			thread_popup = popup;
924 			Thread thread = new Thread(new ThreadStart(RunCommandThread));
925 			thread.Start();
926 		}
927 
RunCommandThread()928 		void RunCommandThread()
929 		{
930 			RunCommandEx(thread_command, thread_mpiexec_command, thread_mpiexec_command_args, thread_popup);
931 		}
932 
RunCommandEx(string command, string mpiexec_command, string mpiexec_command_args, bool popup)933 		private void RunCommandEx(string command, string mpiexec_command, string mpiexec_command_args, bool popup)
934 		{
935 			if (popup)
936 			{
937 				// start a process to run the mpiexec command
938 				Process p = new Process();
939 				p.StartInfo.UseShellExecute = true;
940 				p.StartInfo.CreateNoWindow = false;
941 				p.StartInfo.RedirectStandardError = false;
942 				p.StartInfo.RedirectStandardInput = false;
943 				p.StartInfo.RedirectStandardOutput = false;
944 				p.StartInfo.FileName = "cmd.exe";
945 				if (command.IndexOf('"') != -1)
946 				{
947 					p.StartInfo.Arguments = "/C \"" + command + "\" && pause";
948 				}
949 				else
950 				{
951 					p.StartInfo.Arguments = "/C " + command + " && pause";
952 				}
953 				p.Start();
954 				p.WaitForExit();
955 			}
956 			else
957 			{
958 				quit_input = false;
959 				// start a process to run the mpiexec command
960 				Process p = new Process();
961 				p.StartInfo.UseShellExecute = false;
962 				p.StartInfo.CreateNoWindow = true;
963 				p.StartInfo.RedirectStandardError = true;
964 				p.StartInfo.RedirectStandardInput = true;
965 				p.StartInfo.RedirectStandardOutput = true;
966 				p.StartInfo.FileName = mpiexec_command;
967 				p.StartInfo.Arguments = mpiexec_command_args;
968 				p.Start();
969 				// start a delagate to read stdout
970 				ReadOutputDelegate r1 = new ReadOutputDelegate(ReadOutput);
971 				//IAsyncResult ar1 = r1.BeginInvoke(TextReader.Synchronized(p.StandardOutput), null, null);
972 				object [] list1 = { TextReader.Synchronized(p.StandardOutput) };
973 				Invoke(r1, list1);
974 				// start a delagate to read stderr
975 				ReadErrorDelegate r2 = new ReadErrorDelegate(ReadError);
976 				//IAsyncResult ar2 = r2.BeginInvoke(TextReader.Synchronized(p.StandardError), null, null);
977 				object [] list2 = { TextReader.Synchronized(p.StandardError) };
978 				Invoke(r2, list2);
979 				// Send stdin to the process
980 				WriteInputDelegate w = new WriteInputDelegate(WriteInput);
981 				//IAsyncResult ar3 = w.BeginInvoke(TextWriter.Synchronized(p.StandardInput), null, null);
982 				object [] list3 = { TextWriter.Synchronized(p.StandardInput) };
983 				Invoke(w, list3);
984 
985 				//process = p;
986 				SetProcessDelegate sp = new SetProcessDelegate(SetProcess);
987 				object [] list = { p };
988 				Invoke(sp, list);
989 				// wait for the process to exit
990 				p.WaitForExit();
991 				// wait for the output and error delegates to finish
992 				//r1.EndInvoke(ar1);
993 				//r2.EndInvoke(ar2);
994 				// set the process variable to null
995 				list[0] = null;
996 				Invoke(sp, list);
997 				// signal the input delegate to exit after setting the process variable to null to avoid conflicts with the keypressed handler
998 				quit_input = true;
999 				char_available.Set();
1000 				//w.EndInvoke(ar3);
1001 			}
1002 			ResetExecuteButtonsDelegate d = new ResetExecuteButtonsDelegate(ResetExecuteButtons);
1003 			Invoke(d);
1004 		}
1005 		#endregion
1006 
execute_button_Click(object sender, System.EventArgs e)1007 		private void execute_button_Click(object sender, System.EventArgs e)
1008 		{
1009 			VerifyEncryptedPasswordExists();
1010 			execute_button.Enabled = false;
1011 			break_button.Enabled = true;
1012 			output_richTextBox.Clear();
1013 			if (last_execute_result != null)
1014 			{
1015 				run_command.EndInvoke(last_execute_result);
1016 			}
1017 			// Create the command line
1018 			command_line_textBox.Text = get_command_line();
1019 			// Add the command to the application drop down if it has not already been added
1020 			bool found = false;
1021 			foreach (string str in application_comboBox.Items)
1022 			{
1023 				if (str == application_comboBox.Text)
1024 					found = true;
1025 			}
1026 			if (!found)
1027 			{
1028 				application_comboBox.Items.Add(application_comboBox.Text);
1029 			}
1030 			run_command = new RunCommandDelegate(RunCommand);
1031 			last_execute_result = run_command.BeginInvoke(command_line_textBox.Text, mpiexec_command, mpiexec_command_args, popup_checkBox.Checked, null, null);
1032 			// after starting a command move to the output box so the user can interact with the running process.
1033 			output_richTextBox.Focus();
1034 		}
1035 
VerifyEncryptedPasswordExists()1036 		private void VerifyEncryptedPasswordExists()
1037 		{
1038 			try
1039 			{
1040 				bool popup = true;
1041 				string mpiexec = get_mpiexec();
1042 
1043 				// Check the registry for the encrypted password
1044 				// This code will have to be kept synchronized with the smpd code
1045 				// The advantage of this approach is that the credentials don't have to be valid on the local host
1046 				RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\MPICH");
1047 				if (key != null)
1048 				{
1049 					// check to see that an encrypted password for the current user exists
1050 					object obj = key.GetValue("smpdPassword");
1051 					key.Close();
1052 					if (obj != null)
1053 					{
1054 						popup = false;
1055 					}
1056 				}
1057 
1058 				// Or run "mpiexec -validate" and check the output for SUCCESS
1059 				// This code will last longer because it doesn't rely on known information about the smpd implementation
1060 				// The disadvantage of this code is that the user credentials have to be valid on the local host.
1061 				/*
1062 				Process p1 = new Process();
1063 				p1.StartInfo.RedirectStandardOutput = true;
1064 				p1.StartInfo.RedirectStandardError = true;
1065 				p1.StartInfo.UseShellExecute = false;
1066 				p1.StartInfo.CreateNoWindow = true;
1067 				p1.StartInfo.FileName = mpiexec;
1068 				p1.StartInfo.Arguments = "-validate";
1069 				p1.Start();
1070 				string output = p1.StandardOutput.ReadToEnd() + p1.StandardError.ReadToEnd();
1071 				p1.WaitForExit();
1072 				p1.Close();
1073 				if (output.IndexOf("SUCCESS") != -1)
1074 				{
1075 					popup = false;
1076 				}
1077 				*/
1078 
1079 				if (popup)
1080 				{
1081 					string wmpiregister;
1082 					wmpiregister = mpiexec.Replace("mpiexec.exe", "wmpiregister.exe");
1083 					Process p = new Process();
1084 					p.StartInfo.FileName = wmpiregister;
1085 					p.Start();
1086 					p.WaitForExit();
1087 				}
1088 			}
1089 			catch (Exception)
1090 			{
1091 			}
1092 		}
1093 
break_button_Click(object sender, System.EventArgs e)1094 		private void break_button_Click(object sender, System.EventArgs e)
1095 		{
1096 			if (process != null)
1097 			{
1098 				process.Kill();
1099 			}
1100 		}
1101 
1102 		#region Get known files: mpiexec, jumpshot, and clog2 files
get_jumpshot()1103 		private string get_jumpshot()
1104 		{
1105 			string jumpshot = "";
1106 			object obj;
1107 			try
1108 			{
1109 				RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH2");
1110 				if (key != null)
1111 				{
1112 					obj = key.GetValue("Path");
1113 					key.Close();
1114 					if (obj != null)
1115 					{
1116 						jumpshot = obj.ToString();
1117 						if (jumpshot.EndsWith(@"\"))
1118 						{
1119 							jumpshot = jumpshot + @"bin\jumpshot.jar";
1120 						}
1121 						else
1122 						{
1123 							jumpshot = jumpshot + @"\bin\jumpshot.jar";
1124 						}
1125 						if (!File.Exists(jumpshot))
1126 						{
1127 							jumpshot = "";
1128 						}
1129 					}
1130 				}
1131 				if (jumpshot == "")
1132 				{
1133 					key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD");
1134 					if (key != null)
1135 					{
1136 						obj = key.GetValue("binary");
1137 						key.Close();
1138 						if (obj != null)
1139 						{
1140 							jumpshot = obj.ToString().Replace("smpd.exe", "jumpshot.jar");
1141 							if (!File.Exists(jumpshot))
1142 							{
1143 								jumpshot = "";
1144 							}
1145 						}
1146 					}
1147 				}
1148 				if (jumpshot == "")
1149 				{
1150 					jumpshot = "jumpshot.jar";
1151 				}
1152 				jumpshot = jumpshot.Trim();
1153 				if (jumpshot.IndexOf(' ') != -1)
1154 				{
1155 					jumpshot = "\"" + jumpshot + "\"";
1156 				}
1157 			}
1158 			catch (Exception)
1159 			{
1160 				jumpshot = "jumpshot.jar";
1161 			}
1162 			return jumpshot;
1163 		}
1164 
get_clog2()1165 		private string get_clog2()
1166 		{
1167 			int index, last;
1168 			string app = application_comboBox.Text;
1169 			try
1170 			{
1171 				if (app[0] == '\"')
1172 				{
1173 					// remove the quotes to be restored at the end
1174 					app = app.Replace("\"", "");
1175 				}
1176 				index = app.LastIndexOf('\\');
1177 				if (index == -1)
1178 				{
1179 					index = 0;
1180 				}
1181 				last = index;
1182 				// find the index of .exe starting from the last \
1183 				index = app.IndexOf(".exe", last);
1184 				if (index == -1)
1185 				{
1186 					// no .exe so find the first space after the last \
1187 					// This assumes the executable does not have spaces in its name
1188 					index = app.IndexOf(' ', last);
1189 					if (index == -1)
1190 					{
1191 						// no .exe and no spaces found so take the entire string
1192 						index = app.Length;
1193 					}
1194 				}
1195 				app = app.Substring(0, index) + ".exe.clog2";
1196 				app = app.Trim();
1197 				if (!File.Exists(app) && wdir_textBox.Text.Length > 0)
1198 				{
1199 					// file not found from the application combo box so try finding it in the working directory
1200 					string app2 = application_comboBox.Text;
1201 					if (app2[0] == '\"')
1202 					{
1203 						// remove the quotes to be restored at the end
1204 						app2 = app2.Replace("\"", "");
1205 					}
1206 					index = app2.LastIndexOf('\\');
1207 					if (index != -1)
1208 					{
1209 						// remove the path
1210 						app2 = app2.Remove(0, index);
1211 					}
1212 					// find the index of .exe
1213 					index = app2.IndexOf(".exe");
1214 					if (index != -1)
1215 					{
1216 						// remove any arguments after the executable name
1217 						app2 = app2.Substring(0, index + 4);
1218 					}
1219 					else
1220 					{
1221 						// no .exe so find the first space
1222 						// This assumes the executable does not have spaces in its name
1223 						index = app.IndexOf(' ');
1224 						if (index != -1)
1225 						{
1226 							app2 = app2.Substring(0, index) + ".exe";
1227 						}
1228 						else
1229 						{
1230 							// no .exe and no arguments so append .exe
1231 							app2 += ".exe";
1232 						}
1233 					}
1234 					// app2 should now contain only the executable name
1235 					// Add the wdir path and clog2 extension
1236 					if (wdir_textBox.Text.EndsWith("\\"))
1237 						app2 = wdir_textBox.Text + app2 + ".clog2";
1238 					else
1239 						app2 = wdir_textBox.Text + "\\" + app2 + ".clog2";
1240 					if (File.Exists(app2))
1241 					{
1242 						app = app2;
1243 						FileStream f = File.OpenRead(app2);
1244 						app = f.Name;
1245 						f.Close();
1246 					}
1247 				}
1248 				if (app.IndexOf(' ') != -1)
1249 				{
1250 					app = "\"" + app + "\"";
1251 				}
1252 			}
1253 			catch (Exception)
1254 			{
1255 				app = "";
1256 			}
1257 			return app;
1258 		}
1259 
get_mpiexec()1260 		private string get_mpiexec()
1261 		{
1262 			string mpiexec = "";
1263 			object obj;
1264 			try
1265 			{
1266 				RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH2");
1267 				if (key != null)
1268 				{
1269 					obj = key.GetValue("Path");
1270 					key.Close();
1271 					if (obj != null)
1272 					{
1273 						mpiexec = obj.ToString();
1274 						if (mpiexec.EndsWith(@"\"))
1275 						{
1276 							mpiexec = mpiexec + @"bin\mpiexec.exe";
1277 						}
1278 						else
1279 						{
1280 							mpiexec = mpiexec + @"\bin\mpiexec.exe";
1281 						}
1282 						if (!File.Exists(mpiexec))
1283 						{
1284 							mpiexec = "";
1285 						}
1286 					}
1287 				}
1288 				if (mpiexec == "")
1289 				{
1290 					key = Registry.LocalMachine.OpenSubKey(@"Software\MPICH\SMPD");
1291 					if (key != null)
1292 					{
1293 						obj = key.GetValue("binary");
1294 						key.Close();
1295 						if (obj != null)
1296 						{
1297 							mpiexec = obj.ToString().Replace("smpd.exe", "mpiexec.exe");
1298 							if (!File.Exists(mpiexec))
1299 							{
1300 								mpiexec = "";
1301 							}
1302 						}
1303 					}
1304 				}
1305 				if (mpiexec == "")
1306 				{
1307 					mpiexec = "mpiexec.exe";
1308 				}
1309 				mpiexec = mpiexec.Trim();
1310 				mpiexec_command = mpiexec; // save the path to mpiexec.exe without quotes
1311 				if (mpiexec.IndexOf(' ') != -1)
1312 				{
1313 					mpiexec = "\"" + mpiexec + "\"";
1314 				}
1315 			}
1316 			catch (Exception)
1317 			{
1318 				mpiexec = "mpiexec.exe";
1319 			}
1320 			return mpiexec;
1321 		}
1322 		#endregion
1323 
get_command_line()1324 		private string get_command_line()
1325 		{
1326 			string cmd, mpiexec;
1327 			cmd = mpiexec = get_mpiexec();
1328 			if (application_radioButton.Checked)
1329 			{
1330 				wdir_textBox.Text = wdir_textBox.Text.Trim();
1331 				if (wdir_textBox.Text.Length > 0)
1332 				{
1333 					if (wdir_textBox.Text.IndexOf(' ') != -1)
1334 					{
1335 						cmd = cmd + " -wdir \"" + wdir_textBox.Text + "\"";
1336 					}
1337 					else
1338 					{
1339 						cmd = cmd + " -wdir " + wdir_textBox.Text;
1340 					}
1341 				}
1342 				drive_map_textBox.Text = drive_map_textBox.Text.Trim();
1343 				if (drive_map_textBox.Text.Length > 0)
1344 				{
1345 					if (drive_map_textBox.Text.IndexOf(' ') != -1)
1346 					{
1347 						cmd = cmd + " -map \"" + drive_map_textBox.Text + "\"";
1348 					}
1349 					else
1350 					{
1351 						cmd = cmd + " -map " + drive_map_textBox.Text;
1352 					}
1353 				}
1354 				if (log_checkBox.Checked)
1355 				{
1356 					cmd = cmd + " -log";
1357 				}
1358 				channel_comboBox.Text = channel_comboBox.Text.Trim();
1359 				if (channel_comboBox.Text != "default" && channel_comboBox.Text != "auto" && channel_comboBox.Text != "")
1360 				{
1361 					cmd = cmd + " -env MPICH2_CHANNEL " + channel_comboBox.Text;
1362 				}
1363 				env_textBox.Text = env_textBox.Text.Trim();
1364 				if (env_textBox.Text.Length > 0)
1365 				{
1366 					foreach (string keyval in env_textBox.Text.Split(' '))
1367 					{
1368 						string [] kv;
1369 						kv = keyval.Split('=');
1370 						if (kv.Length > 1)
1371 						{
1372 							cmd = cmd + " -env " + kv[0] + " " + kv[1];
1373 						}
1374 					}
1375 				}
1376 				hosts_textBox.Text = hosts_textBox.Text.Trim();
1377 				if (hosts_textBox.Text.Length > 0)
1378 				{
1379 					string [] hosts;
1380 					int n;
1381 					hosts = hosts_textBox.Text.Split(' ');
1382 					n = (int)nproc_numericUpDown.Value;
1383 					if (n > hosts.Length)
1384 					{
1385 						int max = n % hosts.Length;
1386 						cmd = cmd + " -hosts " + hosts.Length + " ";
1387 						for (int i=0; i<hosts.Length; i++)
1388 						{
1389 							if (i<max)
1390 							{
1391 								cmd = cmd + hosts[i] + " " + ((n / hosts.Length) + 1) + " ";
1392 							}
1393 							else
1394 							{
1395 								cmd = cmd + hosts[i] + " " + (n / hosts.Length) + " ";
1396 							}
1397 						}
1398 					}
1399 					else
1400 					{
1401 						cmd = cmd + " -hosts " + n + " ";
1402 						for (int i=0; i<n; i++)
1403 						{
1404 							cmd = cmd + hosts[i] + " ";
1405 						}
1406 					}
1407 				}
1408 				else
1409 				{
1410 					cmd = cmd + " -n " + nproc_numericUpDown.Value + " ";
1411 				}
1412 				extra_options_textBox.Text = extra_options_textBox.Text.Trim();
1413 				if (extra_options_textBox.Text.Length > 0)
1414 				{
1415 					cmd = cmd + " " + extra_options_textBox.Text;
1416 				}
1417 				application_comboBox.Text = application_comboBox.Text.Trim();
1418 				// Don't add quotes because they would enclose any arguments to the application
1419 				// The user must provide the quotes as necessary in the combo box.
1420 				/*
1421 				if (application_comboBox.Text.IndexOf(' ') != -1)
1422 				{
1423 					cmd = cmd + " \"" + application_comboBox.Text + "\"";
1424 				}
1425 				else
1426 				{
1427 					cmd = cmd + " " + application_comboBox.Text;
1428 				}
1429 				*/
1430 				cmd = cmd + " -noprompt " + application_comboBox.Text; // add -noprompt since we can't send input to stdin
1431 				mpiexec_command_args = cmd.Replace(mpiexec, ""); // save the command line minus the mpiexec path
1432 			}
1433 			else if (configfile_radioButton.Checked)
1434 			{
1435 				configfile_textBox.Text = configfile_textBox.Text.Trim();
1436 				if (configfile_textBox.Text.IndexOf(' ') != -1)
1437 				{
1438 					cmd = cmd + " -configfile \"" + configfile_textBox.Text + "\"";
1439 				}
1440 				else
1441 				{
1442 					cmd = cmd + " -configfile " + configfile_textBox.Text;
1443 				}
1444 			}
1445 			else if (mpich1_radioButton.Checked)
1446 			{
1447 				mpich1_textBox.Text = mpich1_textBox.Text.Trim();
1448 				if (mpich1_textBox.Text.IndexOf(' ') != -1)
1449 				{
1450 					cmd = cmd + " -file \"" + mpich1_textBox.Text + "\"";
1451 				}
1452 				else
1453 				{
1454 					cmd = cmd + " -file " + mpich1_textBox.Text;
1455 				}
1456 			}
1457 			else
1458 			{
1459 				cmd = "";
1460 			}
1461 			return cmd;
1462 		}
1463 
show_command_button_Click(object sender, System.EventArgs e)1464 		private void show_command_button_Click(object sender, System.EventArgs e)
1465 		{
1466 			command_line_textBox.Text = get_command_line();
1467 		}
1468 
output_richTextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)1469 		private void output_richTextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
1470 		{
1471 			if (process != null)
1472 			{
1473 				char_written.WaitOne();
1474 				ch = e.KeyChar;
1475 				char_written.Reset();
1476 				char_available.Set();
1477 			}
1478 		}
1479 
1480 		#region Radio buttons enabling and disabling functions
1481 		/// <summary>
1482 		/// Enable and disable controls based on which radio button is selected
1483 		/// </summary>
DisableApplicationControls()1484 		private void DisableApplicationControls()
1485 		{
1486 			application_label.Enabled = false;
1487 			application_comboBox.Enabled = false;
1488 			application_browse_button.Enabled = false;
1489 			nproc_label.Enabled = false;
1490 			nproc_numericUpDown.Enabled = false;
1491 			wdir_label.Enabled = false;
1492 			wdir_textBox.Enabled = false;
1493 			wdir_browse_button.Enabled = false;
1494 			hosts_label.Enabled = false;
1495 			hosts_textBox.Enabled = false;
1496 			hosts_reset_button.Enabled = false;
1497 			env_label.Enabled = false;
1498 			env_textBox.Enabled = false;
1499 			drive_map_label.Enabled = false;
1500 			drive_map_textBox.Enabled = false;
1501 			channel_label.Enabled = false;
1502 			channel_comboBox.Enabled = false;
1503 			extra_options_label.Enabled = false;
1504 			extra_options_textBox.Enabled = false;
1505 			log_checkBox.Enabled = false;
1506 		}
1507 
EnableApplicationControls()1508 		private void EnableApplicationControls()
1509 		{
1510 			application_label.Enabled = true;
1511 			application_comboBox.Enabled = true;
1512 			application_browse_button.Enabled = true;
1513 			nproc_label.Enabled = true;
1514 			nproc_numericUpDown.Enabled = true;
1515 			wdir_label.Enabled = true;
1516 			wdir_textBox.Enabled = true;
1517 			wdir_browse_button.Enabled = true;
1518 			hosts_label.Enabled = true;
1519 			hosts_textBox.Enabled = true;
1520 			hosts_reset_button.Enabled = true;
1521 			env_label.Enabled = true;
1522 			env_textBox.Enabled = true;
1523 			drive_map_label.Enabled = true;
1524 			drive_map_textBox.Enabled = true;
1525 			channel_label.Enabled = true;
1526 			channel_comboBox.Enabled = true;
1527 			extra_options_textBox.Enabled = true;
1528 			extra_options_label.Enabled = true;
1529 			log_checkBox.Enabled = true;
1530 		}
1531 
DisableConfigfileControls()1532 		private void DisableConfigfileControls()
1533 		{
1534 			configfile_label.Enabled = false;
1535 			configfile_textBox.Enabled = false;
1536 			configfile_browse_button.Enabled = false;
1537 		}
1538 
EnableConfigfileControls()1539 		private void EnableConfigfileControls()
1540 		{
1541 			configfile_label.Enabled = true;
1542 			configfile_textBox.Enabled = true;
1543 			configfile_browse_button.Enabled = true;
1544 		}
1545 
DisableMPICH1Controls()1546 		private void DisableMPICH1Controls()
1547 		{
1548 			mpich1_label.Enabled = false;
1549 			mpich1_textBox.Enabled = false;
1550 			mpich1_browse_button.Enabled = false;
1551 		}
1552 
EnableMPICH1Controls()1553 		private void EnableMPICH1Controls()
1554 		{
1555 			mpich1_label.Enabled = true;
1556 			mpich1_textBox.Enabled = true;
1557 			mpich1_browse_button.Enabled = true;
1558 		}
1559 
application_radioButton_CheckedChanged(object sender, System.EventArgs e)1560 		private void application_radioButton_CheckedChanged(object sender, System.EventArgs e)
1561 		{
1562 			if (application_radioButton.Checked)
1563 			{
1564 				EnableApplicationControls();
1565 				DisableConfigfileControls();
1566 				DisableMPICH1Controls();
1567 			}
1568 		}
1569 
configfile_radioButton_CheckedChanged(object sender, System.EventArgs e)1570 		private void configfile_radioButton_CheckedChanged(object sender, System.EventArgs e)
1571 		{
1572 			if (configfile_radioButton.Checked)
1573 			{
1574 				DisableApplicationControls();
1575 				EnableConfigfileControls();
1576 				DisableMPICH1Controls();
1577 			}
1578 		}
1579 
mpich1_radioButton_CheckedChanged(object sender, System.EventArgs e)1580 		private void mpich1_radioButton_CheckedChanged(object sender, System.EventArgs e)
1581 		{
1582 			if (mpich1_radioButton.Checked)
1583 			{
1584 				DisableApplicationControls();
1585 				DisableConfigfileControls();
1586 				EnableMPICH1Controls();
1587 			}
1588 		}
1589 		#endregion
1590 
1591 		#region Dialog expansion and contraction
1592 		/// <summary>
1593 		/// Manage expansion and contraction of the extra dialog controls
1594 		/// </summary>
DisableAnchors()1595 		private void DisableAnchors()
1596 		{
1597 			show_bottom_checkBox.Anchor = AnchorStyles.Top;
1598 			wdir_label.Anchor = AnchorStyles.Top;
1599 			wdir_textBox.Anchor = AnchorStyles.Top;
1600 			wdir_browse_button.Anchor = AnchorStyles.Top;
1601 			hosts_label.Anchor = AnchorStyles.Top;
1602 			hosts_textBox.Anchor = AnchorStyles.Top;
1603 			hosts_reset_button.Anchor = AnchorStyles.Top;
1604 			configfile_label.Anchor = AnchorStyles.Top;
1605 			configfile_textBox.Anchor = AnchorStyles.Top;
1606 			configfile_browse_button.Anchor = AnchorStyles.Top;
1607 			mpich1_label.Anchor = AnchorStyles.Top;
1608 			mpich1_textBox.Anchor = AnchorStyles.Top;
1609 			mpich1_browse_button.Anchor = AnchorStyles.Top;
1610 			env_label.Anchor = AnchorStyles.Top;
1611 			env_textBox.Anchor = AnchorStyles.Top;
1612 			drive_map_label.Anchor = AnchorStyles.Top;
1613 			drive_map_textBox.Anchor = AnchorStyles.Top;
1614 			channel_label.Anchor = AnchorStyles.Top;
1615 			channel_comboBox.Anchor = AnchorStyles.Top;
1616 			output_richTextBox.Anchor = AnchorStyles.Top;
1617 			configfile_radioButton.Anchor = AnchorStyles.Top;
1618 			mpich1_radioButton.Anchor = AnchorStyles.Top;
1619 			extra_options_label.Anchor = AnchorStyles.Top;
1620 			extra_options_textBox.Anchor = AnchorStyles.Top;
1621 			log_checkBox.Anchor = AnchorStyles.Top;
1622 			jumpshot_button.Anchor = AnchorStyles.Top;
1623 		}
1624 
EnableAnchors()1625 		private void EnableAnchors()
1626 		{
1627 			show_bottom_checkBox.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
1628 			wdir_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1629 			wdir_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1630 			wdir_browse_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1631 			hosts_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1632 			hosts_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1633 			hosts_reset_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1634 			configfile_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1635 			configfile_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1636 			configfile_browse_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1637 			mpich1_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1638 			mpich1_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1639 			mpich1_browse_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1640 			env_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1641 			env_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1642 			drive_map_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1643 			drive_map_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1644 			channel_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1645 			channel_comboBox.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1646 			output_richTextBox.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
1647 			configfile_radioButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1648 			mpich1_radioButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1649 			extra_options_label.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
1650 			extra_options_textBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
1651 			log_checkBox.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1652 			jumpshot_button.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
1653 		}
1654 
HideExtraOptions()1655 		private void HideExtraOptions()
1656 		{
1657 			wdir_label.Hide();
1658 			wdir_textBox.Hide();
1659 			wdir_browse_button.Hide();
1660 			hosts_label.Hide();
1661 			hosts_textBox.Hide();
1662 			hosts_reset_button.Hide();
1663 			configfile_label.Hide();
1664 			configfile_textBox.Hide();
1665 			configfile_browse_button.Hide();
1666 			mpich1_label.Hide();
1667 			mpich1_textBox.Hide();
1668 			mpich1_browse_button.Hide();
1669 			env_label.Hide();
1670 			env_textBox.Hide();
1671 			drive_map_label.Hide();
1672 			drive_map_textBox.Hide();
1673 			channel_label.Hide();
1674 			channel_comboBox.Hide();
1675 			configfile_radioButton.Hide();
1676 			mpich1_radioButton.Hide();
1677 			extra_options_textBox.Hide();
1678 			extra_options_label.Hide();
1679 			log_checkBox.Hide();
1680 			jumpshot_button.Hide();
1681 		}
1682 
ShowExtraOptions()1683 		private void ShowExtraOptions()
1684 		{
1685 			wdir_label.Show();
1686 			wdir_textBox.Show();
1687 			wdir_browse_button.Show();
1688 			hosts_label.Show();
1689 			hosts_textBox.Show();
1690 			hosts_reset_button.Show();
1691 			configfile_label.Show();
1692 			configfile_textBox.Show();
1693 			configfile_browse_button.Show();
1694 			mpich1_label.Show();
1695 			mpich1_textBox.Show();
1696 			mpich1_browse_button.Show();
1697 			env_label.Show();
1698 			env_textBox.Show();
1699 			drive_map_label.Show();
1700 			drive_map_textBox.Show();
1701 			channel_label.Show();
1702 			channel_comboBox.Show();
1703 			configfile_radioButton.Show();
1704 			mpich1_radioButton.Show();
1705 			extra_options_label.Show();
1706 			extra_options_textBox.Show();
1707 			log_checkBox.Show();
1708 			jumpshot_button.Show();
1709 		}
1710 
UpdateExtraControls(bool bShow)1711 		private void UpdateExtraControls(bool bShow)
1712 		{
1713 			DisableAnchors();
1714 			if (bShow)
1715 			{
1716 				ShowExtraOptions();
1717 				Height = Height + expanded_dialog_difference;//230;
1718 			}
1719 			else
1720 			{
1721 				HideExtraOptions();
1722 				Height = Height - expanded_dialog_difference;//230;
1723 			}
1724 			EnableAnchors();
1725 		}
1726 
show_bottom_checkBox_CheckedChanged(object sender, System.EventArgs e)1727 		private void show_bottom_checkBox_CheckedChanged(object sender, System.EventArgs e)
1728 		{
1729 			UpdateExtraControls(show_bottom_checkBox.Checked);
1730 		}
1731 		#endregion
1732 
wmpiexec_Closing(object sender, System.ComponentModel.CancelEventArgs e)1733 		private void wmpiexec_Closing(object sender, System.ComponentModel.CancelEventArgs e)
1734 		{
1735 			if (process != null)
1736 			{
1737 				process.Kill();
1738 			}
1739 			if (last_execute_result != null)
1740 			{
1741 				run_command.EndInvoke(last_execute_result);
1742 				last_execute_result = null;
1743 			}
1744 		}
1745 
jumpshot_button_Click(object sender, System.EventArgs e)1746 		private void jumpshot_button_Click(object sender, System.EventArgs e)
1747 		{
1748 			Process p;
1749 			string args = "-Xms32m -Xmx256m -jar " + get_jumpshot() + " " + get_clog2();
1750 			//MessageBox.Show("javaw.exe " + args);
1751 			//output_richTextBox.AppendText("javaw.exe " + args + "\r\n");
1752 			try
1753 			{
1754 				p = Process.Start("javaw.exe", args);
1755 			}
1756 			catch (Exception x)
1757 			{
1758 				MessageBox.Show("Unable to start: javaw.exe " + args + "\r\n" + x.Message, "Error");
1759 			}
1760 		}
1761 	}
1762 }
1763