📄 mpirun.cpp
字号:
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 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;}bool CreateShmCliqueString(HostNode *pHosts, char *str){ int i, iProc, iterProc, nProc = 0; HostNode *n, *iter; bool *pDone; char *strOrig = str; str[0] = '\0'; if (pHosts == NULL) { char temp[20]; nProc = g_nHosts; for (i=0; i<nProc; i++) { sprintf(temp, "(%d)", i); strcat(str, temp); } return true; } n = pHosts; while (n) { nProc += n->nSMPProcs; n = n->next; } if (nProc < 1) return false; pDone = new bool[nProc]; for (i=0; i<nProc; i++) pDone[i] = false; n = pHosts; iProc = 0; while (n) { if (!pDone[iProc]) { pDone[iProc] = true; str += sprintf(str, "(%d", iProc); iProc++; for (i=1; i<n->nSMPProcs; i++) { pDone[iProc] = true; str += sprintf(str, ",%d", iProc); iProc++; } iter = n->next; iterProc = iProc; while (iter) { if (stricmp(iter->host, n->host) == 0) { pDone[iterProc] = true; str += sprintf(str, ",%d", iterProc); iterProc++; for (i=1; i<iter->nSMPProcs; i++) { pDone[iterProc] = true; str += sprintf(str, ",%d", iterProc); iterProc++; } } else { for (i=0; i<iter->nSMPProcs; i++) iterProc++; } iter = iter->next; } str += sprintf(str, ")"); } else { for (i=0; i<n->nSMPProcs; i++) iProc++; } n = n->next; } return true;}void CreateSingleShmCliqueString(int nCliqueCount, int *pMembers, char *pszSingleShmCliqueString){ int i; char *str = pszSingleShmCliqueString; if (nCliqueCount < 1) return; str += sprintf(str, "("); str += sprintf(str, "%d", pMembers[0]); for (i=1; i<nCliqueCount; i++) { str += sprintf(str, ",%d", pMembers[i]); } sprintf(str, ")"); //printf("CreateSingleShmCliqueString produced: %s\n", pszSingleShmCliqueString); //exit(0);}void SetupTimeouts(){ char pszTimeout[20]; DWORD length; char *pszEnvVariable; length = 20; if (ReadMPDRegistry("timeout", pszTimeout, &length)) { g_nLaunchTimeout = atoi(pszTimeout); if (g_nLaunchTimeout < 1) g_nLaunchTimeout = MPIRUN_DEFAULT_TIMEOUT; } length = 20; if (ReadMPDRegistry("short_timeout", pszTimeout, &length)) { g_nMPIRUN_SHORT_TIMEOUT = atoi(pszTimeout); if (g_nMPIRUN_SHORT_TIMEOUT < 1) g_nMPIRUN_SHORT_TIMEOUT = MPIRUN_SHORT_TIMEOUT; } length = 20; if (ReadMPDRegistry("startup_timeout", pszTimeout, &length)) { g_nMPIRUN_CREATE_PROCESS_TIMEOUT = atoi(pszTimeout); if (g_nMPIRUN_CREATE_PROCESS_TIMEOUT < 1) g_nMPIRUN_CREATE_PROCESS_TIMEOUT = MPIRUN_CREATE_PROCESS_TIMEOUT; } pszEnvVariable = getenv("MPIRUN_SHORT_TIMEOUT"); if (pszEnvVariable) { g_nMPIRUN_SHORT_TIMEOUT = atoi(pszEnvVariable); if (g_nMPIRUN_SHORT_TIMEOUT < 1) g_nMPIRUN_SHORT_TIMEOUT = MPIRUN_SHORT_TIMEOUT; } pszEnvVariable = getenv("MPIRUN_STARTUP_TIMEOUT"); if (pszEnvVariable) { g_nMPIRUN_CREATE_PROCESS_TIMEOUT = atoi(pszEnvVariable); if (g_nMPIRUN_CREATE_PROCESS_TIMEOUT < 1) g_nMPIRUN_CREATE_PROCESS_TIMEOUT = MPIRUN_CREATE_PROCESS_TIMEOUT; }}// Function name : main// Description : // Return type : void // Argument : int argc// Argument : char *argv[]int main(int argc, char *argv[]){ int i; int iproc = 0; char pszJobID[100]; char pszEnv[MAX_CMD_LENGTH] = ""; HANDLE *pThread = NULL; int nShmLow, nShmHigh; DWORD dwThreadID; bool bLogon = false; char pBuffer[MAX_CMD_LENGTH]; char phrase[MPD_PASSPHRASE_MAX_LENGTH + 1];// = MPD_DEFAULT_PASSPHRASE; bool bLogonDots = true; HANDLE hStdout; char cMapDrive, pszMapShare[MAX_PATH]; int nArgsToStrip; bool bRunLocal; char pszMachineFileName[MAX_PATH] = ""; bool bUseMachineFile; bool bDoSMP; bool bPhraseNeeded; DWORD dwType; bool bUsePwdFile = false; char pszPwdFileName[MAX_PATH]; bool bUseDebugFlag = false; DWORD length; WSADATA wsaData; int err; bool bNoDriveMapping = false; bool bCredentialsPrompt = true; bool bUsePriorities = false; int nPriorityClass = 1; int nPriority = 3; char pszShmCliqueString[MAX_CMD_LENGTH]; char pszSingleShmCliqueString[MAX_CMD_LENGTH]; int nCliqueCount, *pMembers; if (argc < 2) { PrintOptions(); return 0; } SetConsoleCtrlHandler(CtrlHandlerRoutine, TRUE); if ((err = WSAStartup( MAKEWORD( 2, 0 ), &wsaData )) != 0) { printf("Winsock2 dll not initialized, error %d", err); switch (err) { case WSASYSNOTREADY: printf("Indicates that the underlying network subsystem is not ready for network communication.\n"); break; case WSAVERNOTSUPPORTED: printf("The version of Windows Sockets support requested is not provided by this particular Windows Sockets implementation.\n"); break; case WSAEINPROGRESS: printf("A blocking Windows Sockets 1.1 operation is in progress.\n"); break; case WSAEPROCLIM: printf("Limit on the number of tasks supported by the Windows Sockets implementation has been reached.\n"); break; case WSAEFAULT: printf("The lpWSAData is not a valid pointer.\n"); break; default: Translate_Error(err, pBuffer); printf("%s\n", pBuffer); break; } return 0; } // Set defaults g_bDoMultiColorOutput = !ReadMPDDefault("nocolor"); bRunLocal = false; g_bNoMPI = false; bLogon = false; bLogonDots = !ReadMPDDefault("nodots"); GetCurrentDirectory(MAX_PATH, g_pszDir); bUseMachineFile = false; bDoSMP = true; phrase[0] = '\0'; bPhraseNeeded = true; g_nHosts = 0; g_pHosts = NULL; bNoDriveMapping = ReadMPDDefault("nomapping"); g_bOutputExitCodes = ReadMPDDefault("exitcodes"); if (ReadMPDDefault("nopopup_debug")) { SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); } if (ReadMPDDefault("usejobhost")) { length = MAX_HOST_LENGTH; if (ReadMPDRegistry("jobhost", g_pszJobHost, &length)) { g_bUseJobHost = true; length = 100; if (ReadMPDRegistry("jobhostpwd", g_pszJobHostMPDPwd, &length)) { g_bUseJobMPDPwd = true; } } } bUseDebugFlag = ReadMPDDefault("dbg"); SetupTimeouts(); // Parse mpirun options while (argv[1] && (argv[1][0] == '-' || argv[1][0] == '/')) { nArgsToStrip = 1; if (stricmp(&argv[1][1], "np") == 0) { if (argc < 3) { printf("Error: no number specified after -np option.\n"); return 0; } g_nHosts = atoi(argv[2]); if (g_nHosts < 1) { printf("Error: must specify a number greater than 0 after the -np option\n"); return 0; } nArgsToStrip = 2; } else if (stricmp(&argv[1][1], "localonly") == 0) { bRunLocal = true; if (argc > 2) { if (isnumber(argv[2])) { g_nHosts = atoi(argv[2]); if (g_nHosts < 1) { printf("Error: If you specify a number after -localonly option,\n it must be greater than 0.\n"); return 0; } nArgsToStrip = 2; } } } else if (stricmp(&argv[1][1], "machinefile") == 0) { if (argc < 3) { printf("Error: no filename specified after -machinefile option.\n"); return 0; } strcpy(pszMachineFileName, argv[2]); bUseMachineFile = true; nArgsToStrip = 2; } else if (stricmp(&argv[1][1], "map") == 0) { if (argc < 3) { printf("Error: no drive specified after -map option.\n"); return 0; } if ((strlen(argv[2]) > 2) && argv[2][1] == ':') { MapDriveNode *pNode = new MapDriveNode; pNode->cDrive = argv[2][0]; strcpy(pNode->pszShare, &argv[2][2]); pNode->pNext = g_pDriveMapList; g_pDriveMapList = pNode; } nArgsToStrip = 2; } else if (stricmp(&argv[1][1], "dir") == 0) { if (argc < 3) { printf("Error: no directory after -dir option\n"); return 0; } strcpy(g_pszDir, argv[2]); nArgsToStrip = 2; } else if (stricmp(&argv[1][1], "env") == 0) { if (argc < 3) { printf("Error: no environment variables after -env option\n"); return 0; } strncpy(g_pszEnv, argv[2], MAX_CMD_LENGTH); g_pszEnv[MAX_CMD_LENGTH-1] = '\0'; if (strlen(argv[2]) >= MAX_CMD_LENGTH) { printf("Warning: environment variables truncated.\n"); } nArgsToStrip = 2; } else if (stricmp(&argv[1][1], "logon") == 0) { bLogon = true; } else if (stricmp(&argv[1][1], "noprompt") == 0) { bCredentialsPrompt = false; } else if (stricmp(&argv[1][1], "dbg") == 0) { bUseDebugFlag = true; } else if (stricmp(&argv[1][1], "pwdfile") == 0) { bUsePwdFile = true; if (argc < 3) { printf("Error: no filename specified after -pwdfile option\n"); return 0; } strncpy(pszPwdFileName, argv[2], MAX_PATH); pszPwdFileName[MAX_PATH-1] = '\0'; nArgsToStrip = 2; } else if (stricmp(&argv[1][1], "mpduser") == 0) { g_bUseMPDUser = true; } else if (stricmp(&argv[1][1], "hosts") == 0) { if (g_nHosts != 0) { printf("Error: only one option is allowed to determine the number of processes.\n"); printf(" -hosts cannot be used with -np or -localonly\n"); return 0; } if (argc > 2) { if (isnumber(argv[2])) { g_nHosts = atoi(argv[2]); if (g_nHosts < 1) { printf("Error: You must specify a number greater than 0 after -hosts.\n"); return 0; } nArgsToStrip = 2 + g_nHosts; int index = 3; for (i=0; i<g_nHosts; i++) { if (index >= argc) { printf("Error: missing host name after -hosts option.\n"); return 0; } HostNode *pNode = new HostNode; pNode->next = NULL; pNode->nSMPProcs = 1; pNode->exe[0] = '\0'; strcpy(pNode->host, argv[index]); index++; if (argc > index) { if (isnumber(argv[index])) { pNode->nSMPProcs = atoi(argv[index]); index++; nArgsToStrip++; } } if (g_pHosts == NULL) { g_pHosts = pNode; } else { HostNode *pIter = g_pHosts; while (pIter->next) pIter = pIter->next; pIter->next = pNode; } } } else { printf("Error: You must specify the number of hosts after the -hosts option.\n"); return 0; } } else { printf("Error: not enough arguments.\n"); return 0; } } else if (stricmp(&argv[1][1], "tcp") == 0) { bDoSMP = false; } else if (stricmp(&argv[1][1], "getphrase") == 0) { GetMPDPassPhrase(phrase); bPhraseNeeded = false; } else if (stricmp(&argv[1][1], "nocolor") == 0) { g_bDoMultiColorOutput = false; } else if (stricmp(&argv[1][1], "nompi") == 0) { g_bNoMPI = true; } else if (stricmp(&argv[1][1], "nodots") == 0) { bLogonDots = false; } else if (stricmp(&argv[1][1], "nomapping") == 0) { bNoDriveMapping = true; } else if (stricmp(&argv[1][1], "nopopup_debug") == 0) { SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); } else if (stricmp(&argv[1][1], "help") == 0 || argv[1][1] == '?') { PrintOptions(); return 0; } else if (stricmp(&argv[1][1], "help2") == 0) { PrintExtraOptions(); return 0; } else if (stricmp(&argv[1][1], "jobhost") == 0) { g_bUseJobHost = true; if (argc < 3) { printf("Error: no host name specified after -jobhost option\n"); return 0; } strncpy(g_pszJobHost, argv[2], MAX_HOST_LENGTH); g_pszJobHost[MAX_HOST_LENGTH-1] = '\0'; nArgsToStrip = 2; } else if (stricmp(&argv[1][1], "jobhostmpdpwd") == 0) { g_bUseJobMPDPwd = true; if (argc < 3) { printf("Error: no passphrase specified after -jobhostmpdpwd option\n"); return 0; } strncpy(g_pszJobHostMPDPwd, argv[2], 100); g_pszJobHostMPDPwd[99] = '\0'; nArgsToStrip = 2; } else if (stricmp(&argv[1][1], "exitcodes") == 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -