Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/src/checkmpi.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI checkmpi *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
41
#include <iostream>
42
#include "checkmpi.h"
43
44
using namespace std;
45
46
CheckMpi::CheckMpi()
47
{
48
}
49
50
CheckMpi::~CheckMpi()
51
{
52
}
53
54
int CheckMpi::findSmpd()
55
{
56
// Check if there is an instance of smpd running:
57
58
#ifdef WIN32
59
60
unsigned int i;
61
TCHAR szProcessName[50] = TEXT("");
62
DWORD ProcessesIDs[MAX_PROCIDS], cbNeeded, cProcesses;
63
bool found = false;
64
65
cout << "Checking whether smpd is running... ";
66
67
if(!EnumProcesses(ProcessesIDs, sizeof(ProcessesIDs), &cbNeeded)) {
68
cout << "unable to enumerate processes - disabling parallel features" << endl;
69
return -1;
70
}
71
72
cProcesses = cbNeeded / sizeof(DWORD);
73
74
for(i = 0; i < cProcesses; i++) {
75
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
76
PROCESS_VM_READ, FALSE,
77
ProcessesIDs[i] );
78
79
if(hProcess != NULL)
80
GetModuleBaseName(hProcess, NULL, szProcessName,
81
sizeof(szProcessName)/sizeof(TCHAR));
82
//if(!wcscmp(szProcessName, TEXT("smpd.exe"))) {
83
if(!_tcscmp(szProcessName, TEXT("smpd.exe"))) {
84
found = true;
85
cout << "yes (PID " << ProcessesIDs[i] << ")" << endl;
86
}
87
88
CloseHandle(hProcess);
89
}
90
91
if(!found) {
92
cout << "no - disabling parallel features" << endl;
93
return -1;
94
}
95
96
#endif
97
98
return 0;
99
}
100
101