forked from networkit/networkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_util.py
151 lines (140 loc) · 4.05 KB
/
setup_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import os
import sys
import subprocess
from subprocess import DEVNULL
import pip
# Used to install the missing Python packages.
def installPackage(package):
pip.main(['install', package])
def installExternalPythonPackages():
""" This function checks if all necessary packages are available and installs the ones that are not.
"""
notInstalledPackages = []
try:
import scipy
del scipy
except:
installPackage('scipy')
try:
import cython
del cython
except:
installPackage('cython')
try:
import matplotlib
del matplotlib
except:
installPackage('matplotlib')
try:
import pandas
del pandas
except:
installPackage('pandas')
try:
import numpy
del numpy
except:
installPackage('numpy')
try:
import networkx
del networkx
except:
installPackage('networkx')
try:
import tabulate
del tabulate
except:
installPackage('tabulate')
try:
import seaborn
del seaborn
except:
installPackage('seaborn')
try:
import sklearn
del sklearn
except:
installPackage('sklearn')
ipythonStatus = os.system('pip3 show ipython')
if ipythonStatus != 0:
installPackage('ipython')
def checkDependencies():
"""
Sees which outside dependencies are missing.
"""
missing = []
try:
import _tkinter
del _tkinter
except:
missing.append("WARNING: _tkinter is necessary for NetworKit.\n"
"Please install _tkinter \n"
"Root privileges are necessary for this. \n"
"If you have these, the installation command should be: sudo apt-get install python3-tk")
return missing
def determineCompiler(candidates, stdFlags):
""" This function tests a list of candidates, whether they are sufficient to the requirements of
NetworKit and focuses on C++11 and OpenMP support."""
#prepare sample.cpp file necessary to determine gcc
#TODO: proper c++11 test?
#TODO: generalize variable names to "compiler" instead of "gcc"...
sample = open("sample.cpp", "w")
sample.write("""/*****************************************************************************
* File: sample.cpp
* DESCRIPTION:
* OpenMP Example - Hello World - C/C++ Version
* In this simple example, the master thread forks a parallel region.
* All threads in the team obtain their unique thread number and print it.
* The master thread only prints the total number of threads. Two OpenMP
* library routines are used to obtain the number of threads and each
* thread's number.
* AUTHOR: Blaise Barney 5/99
* LAST REVISED: 04/06/05
******************************************************************************/
#include <omp.h>
#include <iostream>
[[deprecated("use the function body directly instead of wrapping it in a function.")]]
void helloWorld() {
std::cout << "Hello world" << std::endl;
}
int main (int argc, char *argv[]) {
helloWorld();
int nthreads, tid;
/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
std::cout << \"Hello World from thread = \" << tid << std::endl;
/* Only master thread does this */
if (tid == 0) {
nthreads = omp_get_num_threads();
std::cout << \"Number of threads = \" << nthreads << std::endl;
}
} /* All threads join master thread and disband */
}""")
sample.close()
compiler_version_satisfied = False
compiler = None
stdflag = None
v = 0
i = 0
while not compiler_version_satisfied and i < len(stdFlags):
while not compiler_version_satisfied and v < len(candidates):
#print("testing\t{}".format(candidates[v]))
try:
if subprocess.call([candidates[v],"-o","test_build","-std={}".format(stdFlags[i]),"-fopenmp","sample.cpp"],stdout=DEVNULL,stderr=DEVNULL) == 0:
compiler_version_satisfied = True
compiler = candidates[v]
stdflag = stdFlags[i]
#print("using {0} as C++ compiler with the {1} STD flag".format(candidates[v],stdFlags[i]))
except:
#print("{0} is not installed".format(candidates[v]))
pass
v += 1
i += 1
v = 0
os.remove("sample.cpp")
if compiler_version_satisfied:
os.remove("test_build")
return compiler, stdflag