Skip to content

Commit

Permalink
Automatically determining number of partitions based on cores (#49)
Browse files Browse the repository at this point in the history
* Automatically determining number of partitions based on cores

* Fix lint

* Resolving threads error

* Cleaning up
  • Loading branch information
devin-petersohn authored and simon-mo committed Jul 25, 2018
1 parent 0f89033 commit f7fda88
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions modin/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@
Timedelta, Timestamp, to_timedelta, set_eng_float_format,
set_option, NaT, PeriodIndex, Categorical)
import threading
import os
import ray

DEFAULT_NPARTITIONS = 8
try:
if threading.current_thread().name == "MainThread":
ray.init(redirect_output=True, include_webui=False,
redirect_worker_output=True)
except AssertionError:
pass

# Set this so that Pandas doesn't try to multithread by itself
os.environ['OMP_NUM_THREADS'] = "1"

num_cpus = ray.global_state.cluster_resources()['CPU']
DEFAULT_NPARTITIONS = int(num_cpus)


def set_npartition_default(n):
Expand Down Expand Up @@ -42,10 +55,3 @@ def get_npartitions():
"set_eng_float_format", "set_option", "CategoricalIndex", "Timedelta",
"Timestamp", "NaT", "PeriodIndex", "Categorical"
]

try:
if threading.current_thread().name == "MainThread":
import ray
ray.init()
except AssertionError:
pass

0 comments on commit f7fda88

Please sign in to comment.