Skip to content

Commit d231be6

Browse files
committed
Fix memory check to work on other platforms - SC_PHYS_PAGES is not available on OS X or Windows
1 parent f07414c commit d231be6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

fidimag/common/cuboid_mesh.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
2828
"""
2929
from __future__ import print_function
30-
import os
30+
from psutil import virtual_memory
3131
import numpy as np
3232
from textwrap import dedent
3333
from six.moves import range
@@ -268,18 +268,20 @@ def check_size(self, system_memory_fake_for_testing=None):
268268
269269
"""
270270
bytes_per_float_numpy = 8
271-
size_coordinates_bytes = self.nx * self.ny * self.nz * 3 * bytes_per_float_numpy
271+
size_coordinates_bytes = self.nx * self.ny * \
272+
self.nz * 3 * bytes_per_float_numpy
272273
size_coordinates_GiB = size_coordinates_bytes / (1024. ** 3)
273274

274275
if system_memory_fake_for_testing is None:
275-
mem_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
276-
mem_GiB = mem_bytes / (1024. ** 3)
276+
mem = virtual_memory() / (1024.0 ** 3)
277277
else:
278278
mem_GiB = system_memory_fake_for_testing
279279

280280
if 2 * size_coordinates_GiB > mem_GiB:
281281
# print because no logging yet
282-
print("Warning! Size of mesh coordinates i {} GiB.".format(size_coordinates_GiB))
283-
print("You have {} GiB system memory. Possible halt.".format(mem_GiB))
282+
print("Warning! Size of mesh coordinates i {} GiB.".format(
283+
size_coordinates_GiB))
284+
print(
285+
"You have {} GiB system memory. Possible halt.".format(mem_GiB))
284286
return 1
285287
return 0

0 commit comments

Comments
 (0)