⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmpiexec.cs

📁 fortran并行计算包
💻 CS
📖 第 1 页 / 共 5 页
字号:
		private void save_job_button_Click(object sender, System.EventArgs e)		{			SaveFileDialog dlg = new SaveFileDialog();			dlg.Filter = "Job files (*.txt *.mpi)|*.txt;*.mpi|All files (*.*)|*.*";			if (dlg.ShowDialog() == DialogResult.OK)			{				StreamWriter stream;				using (stream = new StreamWriter(dlg.FileName))				{					stream.WriteLine("exe {0}", application_comboBox.Text.Trim());					stream.WriteLine("n {0}", nproc_numericUpDown.Value);					stream.WriteLine("wdir {0}", wdir_textBox.Text.Trim());					stream.WriteLine("hosts {0}", hosts_textBox.Text.Trim());					stream.WriteLine("cfg {0}", configfile_textBox.Text.Trim());					stream.WriteLine("mpich1 {0}", mpich1_textBox.Text.Trim());					stream.WriteLine("env {0}", env_textBox.Text.Trim());					stream.WriteLine("map {0}", drive_map_textBox.Text.Trim());					stream.WriteLine("channel {0}", channel_comboBox.Text.Trim());					stream.WriteLine("extra {0}", extra_options_textBox.Text.Trim());					stream.WriteLine(popup_checkBox.Checked ? "window yes" : "window no");					stream.WriteLine(log_checkBox.Checked ? "log yes" : "log no");					stream.Close();				}			}		}		private void load_job_button_Click(object sender, System.EventArgs e)		{			OpenFileDialog dlg = new OpenFileDialog();			dlg.Filter = "Job files (*.txt *.mpi)|*.txt;*.mpi|All files (*.*)|*.*";			if (dlg.ShowDialog() == DialogResult.OK)			{				StreamReader stream;				using (stream = new StreamReader(dlg.FileName))				{					string line;					int index;					// reset all the values before loading new ones					application_comboBox.Text = "";					nproc_numericUpDown.Value = 1;					wdir_textBox.Text = "";					hosts_textBox.Text = "";					configfile_textBox.Text = "";					mpich1_textBox.Text = "";					env_textBox.Text = "";					drive_map_textBox.Text = "";					channel_comboBox.Text = "";					extra_options_textBox.Text = "";					popup_checkBox.Checked = false;					log_checkBox.Checked = false;					line = stream.ReadLine();					while (line != null)					{						index = line.IndexOf(" ");						if (index > 0)						{							string key, val;							key = line.Substring(0, index);							val = line.Substring(index+1);							switch (key)							{								case "exe":									application_comboBox.Text = val;									break;								case "n":									nproc_numericUpDown.Value = Convert.ToInt32(val);									break;								case "wdir":									wdir_textBox.Text = val;									break;								case "hosts":									hosts_textBox.Text = val;									break;								case "cfg":									configfile_textBox.Text = val;									break;								case "mpich1":									mpich1_textBox.Text = val;									break;								case "env":									env_textBox.Text = val;									break;								case "map":									drive_map_textBox.Text = val;									break;								case "channel":									channel_comboBox.Text = val;									break;								case "extra":									extra_options_textBox.Text = val;									break;								case "window":									if (val == "yes")										popup_checkBox.Checked = true;									else										popup_checkBox.Checked = false;									break;								case "log":									if (val == "yes")										log_checkBox.Checked = true;									else										log_checkBox.Checked = false;									break;							}						}						line = stream.ReadLine();					}					stream.Close();				}			}		}		#region Process thread functions		/// <summary>		/// These functions read and write input and output of the spawned mpiexec process.		/// They are run in separate threads since they can execute for a long period of time		/// and therefore shouldn't come from the thread pool (delegates).		/// Is this a correct design decision?		/// </summary>		private void ReadOutput(TextReader stream)		{			thread_output_stream = stream;			Thread thread = new Thread(new ThreadStart(ReadOutputThread));			thread.Start();		}		private void ReadError(TextReader stream)		{			thread_error_stream = stream;			Thread thread = new Thread(new ThreadStart(ReadErrorThread));			thread.Start();		}		private void ReadErrorThread()		{			int num_read;			char [] buffer = new char[4096];			TextReader stream = thread_error_stream;			num_read = stream.Read(buffer, 0, 4096);			while (num_read > 0)			{				string str;				char [] text = new char[num_read];				Array.Copy(buffer, 0, text, 0, num_read);				str = new string(text);				object[] pList = { str };				// put the string in the edit box in a thread safe way				AppendTextDelegate ap = new AppendTextDelegate(AppendText);				output_richTextBox.Invoke(ap, pList);				num_read = stream.Read(buffer, 0, 1024);			}		}		private void ReadOutputThread()		{			int num_read;			char [] buffer = new char[4096];			TextReader stream = thread_output_stream;			num_read = stream.Read(buffer, 0, 4096);			while (num_read > 0)			{				string str;				char [] text = new char[num_read];				Array.Copy(buffer, 0, text, 0, num_read);				str = new string(text);				object[] pList = { str };				// put the string in the edit box in a thread safe way				AppendTextDelegate ap = new AppendTextDelegate(AppendText);				output_richTextBox.Invoke(ap, pList);				num_read = stream.Read(buffer, 0, 1024);			}		}		ManualResetEvent char_available = new ManualResetEvent(false);		ManualResetEvent char_written = new ManualResetEvent(true);		bool quit_input = false;		char ch;		private void WriteInput(TextWriter stream)		{			thread_input_stream = stream;			Thread thread = new Thread(new ThreadStart(WriteInputThread));			thread.Start();		}		private void WriteInputThread()		{			WriteInputEx(thread_input_stream);		}		private void WriteInputEx(TextWriter stream)		{			while (char_available.WaitOne())			{				if (quit_input)				{					return;				}				stream.Write(ch);				stream.Flush();				char_available.Reset();				char_written.Set();				/*				object[] pList = { "ch(" + ch + ")" };				// put the string in the edit box in a thread safe way				AppendTextDelegate ap = new AppendTextDelegate(AppendText);				output_richTextBox.Invoke(ap, pList);				*/			}		}		private void RunCommand(string command, string mpiexec_command, string mpiexec_command_args, bool popup)		{			thread_command = command;			thread_mpiexec_command = mpiexec_command;			thread_mpiexec_command_args = mpiexec_command_args;			thread_popup = popup;			Thread thread = new Thread(new ThreadStart(RunCommandThread));			thread.Start();		}		void RunCommandThread()		{			RunCommandEx(thread_command, thread_mpiexec_command, thread_mpiexec_command_args, thread_popup);		}		private void RunCommandEx(string command, string mpiexec_command, string mpiexec_command_args, bool popup)		{			if (popup)			{				// start a process to run the mpiexec command				Process p = new Process();				p.StartInfo.UseShellExecute = true;				p.StartInfo.CreateNoWindow = false;				p.StartInfo.RedirectStandardError = false;				p.StartInfo.RedirectStandardInput = false;				p.StartInfo.RedirectStandardOutput = false;				p.StartInfo.FileName = "cmd.exe";				if (command.IndexOf('"') != -1)				{					p.StartInfo.Arguments = "/C \"" + command + "\" && pause";				}				else				{					p.StartInfo.Arguments = "/C " + command + " && pause";				}				p.Start();				p.WaitForExit();			}			else			{				quit_input = false;				// start a process to run the mpiexec command				Process p = new Process();				p.StartInfo.UseShellExecute = false;				p.StartInfo.CreateNoWindow = true;				p.StartInfo.RedirectStandardError = true;				p.StartInfo.RedirectStandardInput = true;				p.StartInfo.RedirectStandardOutput = true;				p.StartInfo.FileName = mpiexec_command;				p.StartInfo.Arguments = mpiexec_command_args;				p.Start();				// start a delagate to read stdout				ReadOutputDelegate r1 = new ReadOutputDelegate(ReadOutput);				//IAsyncResult ar1 = r1.BeginInvoke(TextReader.Synchronized(p.StandardOutput), null, null);				object [] list1 = { TextReader.Synchronized(p.StandardOutput) };				Invoke(r1, list1);				// start a delagate to read stderr				ReadErrorDelegate r2 = new ReadErrorDelegate(ReadError);				//IAsyncResult ar2 = r2.BeginInvoke(TextReader.Synchronized(p.StandardError), null, null);				object [] list2 = { TextReader.Synchronized(p.StandardError) };				Invoke(r2, list2);				// Send stdin to the process				WriteInputDelegate w = new WriteInputDelegate(WriteInput);				//IAsyncResult ar3 = w.BeginInvoke(TextWriter.Synchronized(p.StandardInput), null, null);				object [] list3 = { TextWriter.Synchronized(p.StandardInput) };				Invoke(w, list3);				//process = p;				SetProcessDelegate sp = new SetProcessDelegate(SetProcess);				object [] list = { p };				Invoke(sp, list);				// wait for the process to exit				p.WaitForExit();				// wait for the output and error delegates to finish				//r1.EndInvoke(ar1);				//r2.EndInvoke(ar2);				// set the process variable to null				list[0] = null;				Invoke(sp, list);				// signal the input delegate to exit after setting the process variable to null to avoid conflicts with the keypressed handler				quit_input = true;				char_available.Set();				//w.EndInvoke(ar3);			}			ResetExecuteButtonsDelegate d = new ResetExecuteButtonsDelegate(ResetExecuteButtons);			Invoke(d);		}		#endregion		private void execute_button_Click(object sender, System.EventArgs e)		{			VerifyEncryptedPasswordExists();			execute_button.Enabled = false;			break_button.Enabled = true;			output_richTextBox.Clear();			if (last_execute_result != null)			{				run_command.EndInvoke(last_execute_result);			}			// Create the command line			command_line_textBox.Text = get_command_line();			// Add the command to the application drop down if it has not already been added			bool found = false;			foreach (string str in application_comboBox.Items)			{				if (str == application_comboBox.Text)					found = true;			}			if (!found)			{				application_comboBox.Items.Add(application_comboBox.Text);			}			run_command = new RunCommandDelegate(RunCommand);			last_execute_result = run_command.BeginInvoke(command_line_textBox.Text, mpiexec_command, mpiexec_command_args, popup_checkBox.Checked, null, null);			// after starting a command move to the output box so the user can interact with the running process.			output_richTextBox.Focus();		}		private void VerifyEncryptedPasswordExists()		{			try			{				bool popup = true;				string mpiexec = get_mpiexec();				// Check the registry for the encrypted password				// This code will have to be kept synchronized with the smpd code				// The advantage of this approach is that the credentials don't have to be valid on the local host				RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\MPICH");				if (key != null)				{					// check to see that an encrypted password for the current user exists					object obj = key.GetValue("smpdPassword");					key.Close();					if (obj != null)					{						popup = false;					}				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -