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

📄 mpirun.cpp

📁 刚才是说明 现在是安装程序在 LINUX环境下进行编程的MPICH安装文件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	    pChar++;		// Advance over white space	while (*pChar != '\0' && isspace(*pChar))	    pChar++;	// Copy the executable	if (*pChar != '\0')	{	    strncpy(node->exe, pChar, MAX_CMD_LENGTH);	    node->exe[MAX_CMD_LENGTH-1] = '\0';	    ExeToUnc(node->exe);	}    }        return node;}#define PARSE_ERR_NO_FILE  -1#define PARSE_SUCCESS       0// Function name	: ParseConfigFile// Description	    : // Return type		: int // Argument         : char * filenameint ParseConfigFile(char * filename){    FILE *fin;    char buffer[1024] = "";    //dbg_printf("parsing configuration file '%s'\n", filename);    fin = fopen(filename, "r");    if (fin == NULL)    {	return PARSE_ERR_NO_FILE;    }        while (fgets(buffer, 1024, fin))    {	// Check for the name of the executable	if (strnicmp(buffer, "exe ", 4) == 0)	{	    char *pChar = &buffer[4];	    while (isspace(*pChar))		pChar++;	    strncpy(g_pszExe, pChar, MAX_CMD_LENGTH);	    g_pszExe[MAX_CMD_LENGTH-1] = '\0';	    pChar = &g_pszExe[strlen(g_pszExe)-1];	    while (isspace(*pChar) && (pChar >= g_pszExe))	    {		*pChar = '\0';		pChar--;	    }	    ExeToUnc(g_pszExe);	}	else	{	    // Check for program arguments	    if (strnicmp(buffer, "args ", 5) == 0)	    {		char *pChar = &buffer[5];		while (isspace(*pChar))		    pChar++;		strncpy(g_pszArgs, pChar, MAX_CMD_LENGTH);		g_pszArgs[MAX_CMD_LENGTH-1] = '\0';		pChar = &g_pszArgs[strlen(g_pszArgs)-1];		while (isspace(*pChar) && (pChar >= g_pszArgs))		{		    *pChar = '\0';		    pChar--;		}	    }	    else	    {		// Check for environment variables		if (strnicmp(buffer, "env ", 4) == 0)		{		    char *pChar = &buffer[4];		    while (isspace(*pChar))			pChar++;		    if (strlen(pChar) >= MAX_CMD_LENGTH)		    {			printf("Warning: environment variables truncated.\n");			fflush(stdout);		    }		    strncpy(g_pszEnv, pChar, MAX_CMD_LENGTH);		    g_pszEnv[MAX_CMD_LENGTH-1] = '\0';		    pChar = &g_pszEnv[strlen(g_pszEnv)-1];		    while (isspace(*pChar) && (pChar >= g_pszEnv))		    {			*pChar = '\0';			pChar--;		    }		}		else		{		    if (strnicmp(buffer, "map ", 4) == 0)		    {			char *pszMap;			pszMap = &buffer[strlen(buffer)-1];			while (isspace(*pszMap) && (pszMap >= buffer))			{			    *pszMap = '\0';			    pszMap--;			}			pszMap = &buffer[4];			while (isspace(*pszMap))			    pszMap++;			if (*pszMap != '\0' && strlen(pszMap) > 6 && pszMap[1] == ':')			{			    MapDriveNode *pNode = new MapDriveNode;			    pNode->cDrive = pszMap[0];			    strcpy(pNode->pszShare, &pszMap[2]);			    pNode->pNext = g_pDriveMapList;			    g_pDriveMapList = pNode;			}		    }		    else		    {			if (strnicmp(buffer, "dir ", 4) == 0)			{			    char *pChar = &buffer[4];			    while (isspace(*pChar))				pChar++;			    strcpy(g_pszDir, pChar);			    pChar = &g_pszDir[strlen(g_pszDir)-1];			    while (isspace(*pChar) && (pChar >= g_pszDir))			    {				*pChar = '\0';				pChar--;			    }			}			else			{			    // Check for hosts			    if (strnicmp(buffer, "hosts", 5) == 0)			    {				g_nHosts = 0;				g_pHosts = NULL;				HostNode *node, dummy;				dummy.next = NULL;				node = &dummy;				while (fgets(buffer, 1024, fin))				{				    node->next = ParseLineIntoHostNode(buffer);				    if (node->next != NULL)				    {					node = node->next;					g_nHosts++;				    }				}				g_pHosts = dummy.next;								fclose(fin);				return PARSE_SUCCESS;			    }			}		    }		}	    }	}    }    fclose(fin);    return PARSE_SUCCESS;}// Function name	: GetAccountAndPassword// Description	    : Attempts to read the password from the registry, //	                  upon failure it requests the user to provide one// Return type		: void void GetAccountAndPassword(){    char ch = 0;    int index = 0;    fprintf(stderr, "Mpd needs an account to launch processes with:\n");    do    {	fprintf(stderr, "account (domain\\user): ");	fflush(stderr);	gets(g_pszAccount);    }     while (strlen(g_pszAccount) == 0);        fprintf(stderr, "password: ");    fflush(stderr);        HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);    DWORD dwMode;    if (!GetConsoleMode(hStdin, &dwMode))	dwMode = ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT;    SetConsoleMode(hStdin, dwMode & ~ENABLE_ECHO_INPUT);    gets(g_pszPassword);    SetConsoleMode(hStdin, dwMode);        fprintf(stderr, "\n");}// Function name	: GetMPDPassPhrase// Description	    : // Return type		: void // Argument         : char *phrasevoid GetMPDPassPhrase(char *phrase){    fprintf(stderr, "mpd password: ");    fflush(stderr);        HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);    DWORD dwMode;    if (!GetConsoleMode(hStdin, &dwMode))	dwMode = ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT;    SetConsoleMode(hStdin, dwMode & ~ENABLE_ECHO_INPUT);    gets(phrase);    SetConsoleMode(hStdin, dwMode);        fprintf(stderr, "\n");}// Function name	: WaitToBreak// Description	    : // Return type		: void void WaitToBreak(){    WaitForSingleObject(g_hBreakReadyEvent, INFINITE);    if (easy_send(g_sockBreak, "x", 1) == SOCKET_ERROR)	easy_send(g_sockStopIOSignalSocket, "x", 1);}// Function name	: CtrlHandlerRoutine// Description	    : // Return type		: BOOL WINAPI // Argument         : DWORD dwCtrlTypestatic bool g_bFirst = true;static HANDLE g_hLaunchThreadsRunning = CreateEvent(NULL, TRUE, TRUE, NULL);BOOL WINAPI CtrlHandlerRoutine(DWORD dwCtrlType){    bool bOK;    // Don't abort while the launch threads are running because it can leave    // processes running.    if (WaitForSingleObject(g_hLaunchThreadsRunning, 0) == WAIT_OBJECT_0)    {	SetEvent(g_hAbortEvent);	return TRUE;    }    // Hit Ctrl-C once and I'll try to kill the remote processes    if (g_bFirst)    {	fprintf(stderr, "Soft break - attempting to kill processes\n(hit break again to do a hard abort)\n");		// Signal all the threads to stop	SetEvent(g_hAbortEvent);		bOK = true;	if (g_sockBreak != INVALID_SOCKET)	{	    // Send a break command to WaitForExitCommands	    if (easy_send(g_sockBreak, "x", 1) == SOCKET_ERROR)	    {		printf("easy_send(break) failed, error %d\n", WSAGetLastError());		bOK = false;	    }	}	else	{	    // Start a thread to wait until a break can be issued.  This happens	    // if you hit Ctrl-C before all the process threads have been created.	    DWORD dwThreadId;	    HANDLE hThread;	    hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WaitToBreak, NULL, 0, &dwThreadId);	    if (hThread == NULL)		bOK = false;	    else		CloseHandle(hThread);	}	if (!bOK)	{	    bOK = true;	    // If you cannot issue a break signal, send a stop signal to the io threads	    if (g_sockStopIOSignalSocket != INVALID_SOCKET)	    {		if (easy_send(g_sockStopIOSignalSocket, "x", 1) == SOCKET_ERROR)		{		    printf("easy_send(stop) failed, error %d\n", WSAGetLastError());		    bOK =false;		}	    }	    else		bOK = false;	    if (!bOK)	    {		if (g_bDoMultiColorOutput)		{		    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), g_ConsoleAttribute);		}		ExitProcess(1); // If you cannot issue either a break or stop signal, exit	    }	}	g_bFirst = false;	return TRUE;    }        fprintf(stderr, "aborting\n");    // Hit Ctrl-C twice and I'll exit    if (g_bDoMultiColorOutput)    {	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), g_ConsoleAttribute);    }    // Issue a stop signal    if (g_sockStopIOSignalSocket != INVALID_SOCKET)    {	if (easy_send(g_sockStopIOSignalSocket, "x", 1) == SOCKET_ERROR)	    printf("easy_send(stop) failed, error %d\n", WSAGetLastError());    }    Sleep(2000); // Give a little time for the kill commands to get sent out?    ExitProcess(1);    return TRUE;}// Function name	: PrintDots// Description	    : // Return type		: void // Argument         : HANDLE hEventvoid PrintDots(HANDLE hEvent){    if (WaitForSingleObject(hEvent, 3000) == WAIT_TIMEOUT)    {	printf(".");fflush(stdout);	while (WaitForSingleObject(hEvent, 1000) == WAIT_TIMEOUT)	{	    printf(".");fflush(stdout);	}    }    CloseHandle(hEvent);}/*// Function name	: CheckMapping// Description	    : // Return type		: bool // Argument         : char *pszExebool CheckMapping(char *pszExe){    DWORD dwResult;    DWORD dwLength;    char pBuffer[4096];    REMOTE_NAME_INFO *info = (REMOTE_NAME_INFO*)pBuffer;    char pszTemp[MAX_CMD_LENGTH];    if (*pszExe == '"')    {	strncpy(pszTemp, &pszExe[1], MAX_CMD_LENGTH);	pszTemp[MAX_CMD_LENGTH-1] = '\0';	if (pszTemp[strlen(pszTemp)-1] == '"')	    pszTemp[strlen(pszTemp)-1] = '\0';	pszExe = pszTemp;    }    dwLength = 4096;    info->lpConnectionName = NULL;    info->lpRemainingPath = NULL;    info->lpUniversalName = NULL;    dwResult = WNetGetUniversalName(pszExe, REMOTE_NAME_INFO_LEVEL, info, &dwLength);    if (dwResult == NO_ERROR)    {	printf("WNetGetUniversalName: '%s'\n unc: '%s'\n share: '%s'\n path: '%s'\n", 	    pszExe, 	    info->lpUniversalName, 	    info->lpConnectionName, 	    info->lpRemainingPath);    }    else	printf("WNetGetUniversalName: '%s'\n error %d\n", pszExe, dwResult);    return true;}*/// Function name	: NeedToMap// Description	    : // Return type		: bool // Argument         : char *pszFullPath// Argument         : char *pDrive// Argument         : char *pszShare// Argument         : char *pszDirbool NeedToMap(char *pszFullPath, char *pDrive, char *pszShare)//, char *pszDir){    DWORD dwResult;    DWORD dwLength;    char pBuffer[4096];    REMOTE_NAME_INFO *info = (REMOTE_NAME_INFO*)pBuffer;    char pszTemp[MAX_CMD_LENGTH];    if (*pszFullPath == '"')    {	strncpy(pszTemp, &pszFullPath[1], MAX_CMD_LENGTH);	pszTemp[MAX_CMD_LENGTH-1] = '\0';	if (pszTemp[strlen(pszTemp)-1] == '"')	    pszTemp[strlen(pszTemp)-1] = '\0';	pszFullPath = pszTemp;    }    dwLength = 4096;    info->lpConnectionName = NULL;    info->lpRemainingPath = NULL;    info->lpUniversalName = NULL;    dwResult = WNetGetUniversalName(pszFullPath, REMOTE_NAME_INFO_LEVEL, info, &dwLength);    if (dwResult == NO_ERROR)    {	/*	printf("WNetGetUniversalName: '%s'\n unc: '%s'\n share: '%s'\n path: '%s'\n", 	    pszFullPath, 	    info->lpUniversalName, 	    info->lpConnectionName, 	    info->lpRemainingPath);	*/	*pDrive = *pszFullPath;	strcpy(pszShare, info->lpConnectionName);	//strcpy(pszDir, info->lpRemainingPath);	return true;    }    //printf("WNetGetUniversalName: '%s'\n error %d\n", pszExe, dwResult);    return false;}// Function name	: ExeToUnc// Description	    : // Return type		: void // Argument         : char *pszExevoid ExeToUnc(char *pszExe){    DWORD dwResult;    DWORD dwLength;    char pBuffer[4096];    REMOTE_NAME_INFO *info = (REMOTE_NAME_INFO*)pBuffer;    char pszTemp[MAX_CMD_LENGTH];    bool bQuoted = false;    char *pszOriginal;    pszOriginal = pszExe;    if (*pszExe == '"')    {	bQuoted = true;	strncpy(pszTemp, &pszExe[1], MAX_CMD_LENGTH);	pszTemp[MAX_CMD_LENGTH-1] = '\0';	if (pszTemp[strlen(pszTemp)-1] == '"')	    pszTemp[strlen(pszTemp)-1] = '\0';	pszExe = pszTemp;    }    dwLength = 4096;    info->lpConnectionName = NULL;    info->lpRemainingPath = NULL;    info->lpUniversalName = NULL;    dwResult = WNetGetUniversalName(pszExe, REMOTE_NAME_INFO_LEVEL, info, &dwLength);    if (dwResult == NO_ERROR)    {	/*	printf("WNetGetUniversalName: '%s'\n unc: '%s'\n share: '%s'\n path: '%s'\n", 	    pszExe, 	    info->lpUniversalName, 	    info->lpConnectionName, 	    info->lpRemainingPath);	*/	if (bQuoted)	    sprintf(pszOriginal, "\"%s\"", info->lpUniversalName);	else	    strcpy(pszOriginal, info->lpUniversalName);    }}static void StripArgs(int &argc, char **&argv, int n){    if (n+1 > argc)    {	printf("Error: cannot strip %d args, only %d left.\n", n, argc-1);    }    for (int i=n+1; i<=argc; i++)    {	argv[i-n] = argv[i];    }    argc -= n;}static bool isnumber(char *str){    int i, n = strlen(str);    for (i=0; i<n; i++)    {	if (!isdigit(str[i]))	    return false;    }    return true;}bool CreatePMIDatabase(char *pmi_host, int pmi_port, char *phrase, char *pmi_kvsname){    int error;    SOCKET sock;    if ((error = ConnectToMPD(pmi_host, pmi_port, phrase, &sock)) == 0)    {	WriteString(sock, "dbcreate");	ReadString(sock, pmi_kvsname);	WriteString(sock, "done");	easy_closesocket(sock);	return true;    }    printf("Unable to connect to mpd at %s:%d\n", pmi_host, pmi_port);    return false;}bool DestroyPMIDatabase(char *pmi_host, int pmi_port, char *phrase, char *pmi_kvsname){    int error;    SOCKET sock;    char str[256];    if ((error = ConnectToMPD(pmi_host, pmi_port, phrase, &sock)) == 0)    {	sprintf(str, "dbdestroy %s", pmi_kvsname);	WriteString(sock, str);	ReadString(sock, str);	WriteString(sock, "done");	easy_closesocket(sock);	return true;    }    printf("Unable to connect to mpd at %s:%d\n", pmi_host, pmi_port);    return false;}

⌨️ 快捷键说明

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