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

📄 guimpirunview.cpp

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// guiMPIRunView.cpp : implementation of the CGuiMPIRunView class//#include "stdafx.h"#include "guiMPIRun.h"#include "guiMPIRunDoc.h"#include "guiMPIRunView.h"#include "MPIJobDefs.h"#include "mpd.h"#include "RedirectIO.h"#include "global.h"#include "AdvancedOptionsDlg.h"#include "mpdutil.h"#include "launchprocess.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CGuiMPIRunViewIMPLEMENT_DYNCREATE(CGuiMPIRunView, CFormView)BEGIN_MESSAGE_MAP(CGuiMPIRunView, CFormView)//{{AFX_MSG_MAP(CGuiMPIRunView)ON_WM_SIZE()ON_NOTIFY(UDN_DELTAPOS, IDC_NPROC_SPIN, OnDeltaposNprocSpin)ON_BN_CLICKED(IDC_APP_BROWSE_BTN, OnAppBrowseBtn)ON_BN_CLICKED(IDC_RUN_BTN, OnRunBtn)ON_BN_CLICKED(IDC_HOSTS_RADIO, OnHostsRadio)ON_BN_CLICKED(IDC_ANY_HOSTS_RADIO, OnAnyHostsRadio)ON_COMMAND(ID_EDIT_COPY, OnEditCopy)ON_WM_CLOSE()	ON_BN_CLICKED(IDC_ADD_HOST_BTN, OnAddHostBtn)	ON_BN_CLICKED(IDC_BREAK_BTN, OnBreakBtn)	ON_BN_CLICKED(IDC_ADVANCED_BTN, OnAdvancedBtn)	ON_NOTIFY(EN_MSGFILTER, IDC_OUTPUT, OnMsgfilterOutput)	ON_BN_CLICKED(IDC_RESET_HOSTS_BTN, OnResetHostsBtn)	ON_WM_VKEYTOITEM()	//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CGuiMPIRunView construction/destructionCGuiMPIRunView::CGuiMPIRunView(): CFormView(CGuiMPIRunView::IDD){    //{{AFX_DATA_INIT(CGuiMPIRunView)    m_nproc = 1;    m_app = _T("");    m_host = _T("");	//}}AFX_DATA_INIT    m_bAnyHosts = true;    m_pHosts = NULL;    m_hJobThread = NULL;    m_bForceLogon = false;    m_Account = "";    m_Password = "";    m_bFirstBreak = true;    m_bUseWorkingDirectory = false;    m_WorkingDirectory = "";    m_bUseCommonEnvironment = false;    m_CommonEnvironment = "";    m_bUseSlaveProcess = false;    m_SlaveProcess = "";    m_bNoClear = false;    m_nMaxMRU = 10;    m_hJobFinished = CreateEvent(NULL, TRUE, TRUE, NULL);    m_hRedirectStdinEvent = CreateEvent(NULL, TRUE, FALSE, NULL);    m_hRedirectStdinMutex = CreateMutex(NULL, FALSE, NULL);    m_pRedirectStdinList = NULL;    m_curoutput = "";    m_fout = NULL;    m_bUseConfigFile = false;    m_ConfigFileName = "";    m_redirect = false;    m_output_filename = "";    m_pProcessThread = NULL;    m_nNumProcessThreads = 0;    m_pProcessSocket = NULL;    m_nNumProcessSockets = 0;    m_sockBreak = INVALID_SOCKET;    m_hBreakReadyEvent = CreateEvent(NULL, TRUE, FALSE, NULL);    m_pForwardHost = NULL;    m_pLaunchIdToRank = NULL;    m_hRedirectRicheditThread = NULL;    //m_pDriveMapList = NULL;    m_Mappings = "";    m_bUseMapping = false;    m_bCatch = false;}CGuiMPIRunView::~CGuiMPIRunView(){}void CGuiMPIRunView::DoDataExchange(CDataExchange* pDX){    CFormView::DoDataExchange(pDX);    //{{AFX_DATA_MAP(CGuiMPIRunView)	DDX_Control(pDX, IDC_RESET_HOSTS_BTN, m_reset_btn);	DDX_Control(pDX, IDC_ADVANCED_BTN, m_advanced_btn);	DDX_Control(pDX, IDC_NPROC, m_nproc_edit);	DDX_Control(pDX, IDC_RUN_BTN, m_run_btn);	DDX_Control(pDX, IDC_NPROC_SPIN, m_nproc_spin);	DDX_Control(pDX, IDC_BREAK_BTN, m_break_btn);	DDX_Control(pDX, IDC_ADD_HOST_BTN, m_add_btn);	DDX_Control(pDX, IDC_ANY_HOSTS_RADIO, m_any_hosts_btn);    DDX_Control(pDX, IDC_HOST_EDIT, m_host_edit);    DDX_Control(pDX, IDC_OUTPUT, m_output);    DDX_Control(pDX, IDC_HOST_LIST, m_host_list);    DDX_Control(pDX, IDC_APP_COMBO, m_app_combo);    DDX_Control(pDX, IDC_APP_BROWSE_BTN, m_app_browse_btn);    DDX_Text(pDX, IDC_NPROC, m_nproc);    DDV_MinMaxInt(pDX, m_nproc, 1, 1024);    DDX_CBString(pDX, IDC_APP_COMBO, m_app);    DDX_Text(pDX, IDC_HOST_EDIT, m_host);	//}}AFX_DATA_MAP}BOOL CGuiMPIRunView::PreCreateWindow(CREATESTRUCT& cs){    return CFormView::PreCreateWindow(cs);}bool ReadMPDRegistry(char *name, char *value, DWORD *length = NULL){    HKEY tkey;    DWORD len, result;        // Open the root key    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, MPD_REGISTRY_KEY,	0, 	KEY_READ,	&tkey) != ERROR_SUCCESS)    {	//printf("Unable to open the MPD registry key, error %d\n", GetLastError());	return false;    }        if (length == NULL)	len = MAX_CMD_LENGTH;    else	len = *length;    result = RegQueryValueEx(tkey, name, 0, NULL, (unsigned char *)value, &len);    if (result != ERROR_SUCCESS)    {	//printf("Unable to read the mpd registry key '%s', error %d\n", name, GetLastError());	RegCloseKey(tkey);	return false;    }    if (length != NULL)	*length = len;        RegCloseKey(tkey);    return true;}bool ReadMPDDefault(char *str){    DWORD length = 100;    char value[100] = "no";    if (ReadMPDRegistry(str, value, &length))    {	if ((stricmp(value, "yes") == 0) ||	    (stricmp(value, "y") == 0) ||	    (stricmp(value, "1") == 0))	    return true;    }    return false;}void CGuiMPIRunView::OnInitialUpdate(){    CFormView::OnInitialUpdate();    GetParentFrame()->RecalcLayout();    ResizeParentToFit();    RECT r;    GetClientRect(&r);    m_nMinWidth = r.right;    m_nMinHeight = r.bottom;    rOutput.SetInitialPosition(m_output.m_hWnd, RSR_STRETCH);    rHostList.SetInitialPosition(m_host_list.m_hWnd, RSR_ANCHOR_RIGHT_STRETCH);    rAppCombo.SetInitialPosition(m_app_combo.m_hWnd, RSR_STRETCH_RIGHT);    rAppBrowse.SetInitialPosition(m_app_browse_btn.m_hWnd, RSR_ANCHOR_RIGHT);        rAnyHost.SetInitialPosition(::GetDlgItem(m_hWnd, IDC_ANY_HOSTS_RADIO), RSR_ANCHOR_RIGHT);    rHost.SetInitialPosition(::GetDlgItem(m_hWnd, IDC_HOSTS_RADIO), RSR_ANCHOR_RIGHT);    rHostEdit.SetInitialPosition(m_host_edit.m_hWnd, RSR_ANCHOR_RIGHT);    rAdd.SetInitialPosition(m_add_btn.m_hWnd, RSR_ANCHOR_RIGHT);    rAdvanced.SetInitialPosition(m_advanced_btn.m_hWnd, RSR_ANCHOR_RIGHT);    rReset.SetInitialPosition(m_reset_btn.m_hWnd, RSR_ANCHOR_RIGHT);        easy_socket_init();        // Get hosts from registry    char pszHosts[4096];    DWORD nLength = 4096;    if (ReadMPDRegistry("hosts", pszHosts, &nLength))    {	/*	char *token = NULL;	token = strtok(pszHosts, "|");	if (token != NULL)	{	    m_host_list.InsertString(-1, token);	    while ((token = strtok(NULL, "|")) != NULL)	    {		m_host_list.InsertString(-1, token);	    }	}	*/	QVS_Container *phosts;	phosts = new QVS_Container(pszHosts);	if (phosts->first(pszHosts, 4096))	{	    m_host_list.InsertString(-1, pszHosts);	    while (phosts->next(pszHosts, 4096))	    {		m_host_list.InsertString(-1, pszHosts);	    }	}	delete phosts;    }    else    {	char temp[100];	gethostname(temp, 100);	m_host_list.InsertString(-1, temp);    }    char pszPhrase[100];    nLength = 100;    if (ReadMPDRegistry("phrase", pszPhrase, &nLength))    {	m_Phrase = pszPhrase;    }    else    {	m_Phrase = MPD_DEFAULT_PASSPHRASE;    }    m_any_hosts_btn.SetCheck(1);    // Initially "any hosts" is selected, so the host list is disabled    m_host_list.EnableWindow(FALSE);    m_host_edit.EnableWindow(FALSE);        m_hAbortEvent = CreateEvent(NULL, TRUE, FALSE, NULL);    m_bNormalExit = true;    m_bNoMPI = false;    m_bNoColor = false;    m_hConsoleOutputMutex = CreateMutex(NULL, FALSE, NULL);    if (ReadMPDDefault("usejobhost"))    {	DWORD length = MAX_HOST_LENGTH;	if (ReadMPDRegistry("jobhost", g_pszJobHost, &length))	{	    g_bUseJobHost = true;	    length = 100;	    if (ReadMPDRegistry("jobhostpwd", g_pszJobHostMPDPwd, &length))	    {		g_bUseJobMPDPwd = true;	    }	}    }    CHARFORMAT cf;    cf.dwMask = CFM_FACE;    cf.dwEffects = 0;    //strcpy(cf.szFaceName, "Courier");    strcpy(cf.szFaceName, "Lucida Console");    m_output.SetDefaultCharFormat(cf);    ReadMRU();    ::SendMessage(m_output.m_hWnd, EM_SETEVENTMASK, 0, ENM_KEYEVENTS);}/////////////////////////////////////////////////////////////////////////////// CGuiMPIRunView diagnostics#ifdef _DEBUGvoid CGuiMPIRunView::AssertValid() const{    CFormView::AssertValid();}void CGuiMPIRunView::Dump(CDumpContext& dc) const{    CFormView::Dump(dc);}CGuiMPIRunDoc* CGuiMPIRunView::GetDocument() // non-debug version is inline{    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGuiMPIRunDoc)));    return (CGuiMPIRunDoc*)m_pDocument;}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CGuiMPIRunView message handlersvoid CGuiMPIRunView::OnSize(UINT nType, int cx, int cy) {    CFormView::OnSize(nType, cx, cy);        if (m_nMinWidth < cx || m_nMinHeight < cy)    {	rOutput.Resize(cx, cy);	rHostList.Resize(cx, cy);	rAppCombo.Resize(cx, cy);	rAppBrowse.Resize(cx, cy);	rAnyHost.Resize(cx, cy);	rHost.Resize(cx, cy);	rHostEdit.Resize(cx, cy);	rAdd.Resize(cx, cy);	rAdvanced.Resize(cx, cy);	rReset.Resize(cx, cy);    }}void CGuiMPIRunView::OnDeltaposNprocSpin(NMHDR* pNMHDR, LRESULT* pResult) {    NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;        UpdateData();        if (pNMUpDown->iDelta < 0)	m_nproc++;    else	m_nproc--;        if (m_nproc < 1)	m_nproc = 1;    if (m_nproc > 1024)	m_nproc = 1024;        UpdateData(FALSE);        *pResult = 0;}void CGuiMPIRunView::OnAppBrowseBtn() {    UpdateData();    CFileDialog f(	TRUE, "*.exe", m_app, 	OFN_HIDEREADONLY | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,	"Executables (*.exe)|*.exe|All files (*.*)|*.*||"	);    if (f.DoModal() == IDOK)    {	POSITION p;	p = f.GetStartPosition();	m_app = f.GetNextPathName(p);	UpdateData(FALSE);    }}void CGuiMPIRunView::OnHostsRadio() {    m_host_list.EnableWindow();    m_host_edit.EnableWindow();    m_bAnyHosts = false;}void CGuiMPIRunView::OnAnyHostsRadio() {    m_host_list.EnableWindow(FALSE);    m_host_edit.EnableWindow(FALSE);    m_bAnyHosts = true;}void CGuiMPIRunView::OnEditCopy() {    CString str = m_output.GetSelText();    if (str.GetLength() == 0)    {	m_output.SetSel(0, -1);    }    m_output.Copy();}void CGuiMPIRunView::OnClose() {    // Stop any running jobs    Abort();    WaitForSingleObject(m_hJobFinished, 5000);    // Signal the IO redirection thread to stop    if (m_sockStopIOSignalSocket != INVALID_SOCKET)	easy_send(m_sockStopIOSignalSocket, "x", 1);    if (m_hRedirectIOListenThread != NULL)    {	// Wait for the redirection thread to complete.  Kill it if it takes too long.	if (WaitForSingleObject(m_hRedirectIOListenThread, 1000) != WAIT_OBJECT_0)	{	    //printf("Terminating the IO redirection control thread\n");	    TerminateThread(m_hRedirectIOListenThread, 0);	}	CloseHandle(m_hRedirectIOListenThread);	m_hRedirectIOListenThread = NULL;    }    if (m_hRedirectRicheditThread != NULL)    {	if (WaitForSingleObject(m_hRedirectRicheditThread, 1000) != WAIT_OBJECT_0)	{	    TerminateThread(m_hRedirectRicheditThread, 0);	}	CloseHandle(m_hRedirectRicheditThread);	m_hRedirectRicheditThread = NULL;    }    CloseHandle(m_hConsoleOutputMutex);    CloseHandle(m_hAbortEvent);    CloseHandle(m_hJobFinished);    m_hJobFinished = NULL;    m_hAbortEvent = NULL;    m_hConsoleOutputMutex = NULL;

⌨️ 快捷键说明

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