We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
By default use core number as n_parallel for threaded scheduling
Use core number as `n_parallel` for threaded scheduling, currently 1 thread by default.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mars/session.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright 1999-2018 Alibaba Group Holding Ltd.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import numpy as np
18 
19 
20 class LocalSession(object):
21     def __init__(self):
22         from .tensor.execution.core import Executor
23 
24         self._executor = Executor()
25         self._endpoint = None
26 
27     @property
28     def endpoint(self):
29         return self._endpoint
30 
31     @endpoint.setter
32     def endpoint(self, endpoint):
33         if endpoint is not None:
34             raise ValueError('Local session cannot set endpoint')
35         self._endpoint = endpoint
36 
37     def run(self, *tensors, **kw):
38         if self._executor is None:
39             raise RuntimeError('Session has closed')
40         return self._executor.execute_tensors(tensors, **kw)
41 
42     def decref(self, *keys):
43         self._executor.decref(*keys)
44 
45     def __enter__(self):
46         return self
47 
48     def __exit__(self, *_):
49         self._executor = None
50 
51 
52 class Session(object):
53     _default_session = None
54 
55     def __init__(self, endpoint=None):
56         if endpoint is not None:
57             if 'http' in endpoint:
58                 # connect to web
59                 from .web.session import Session as WebSession
60 
61                 self._sess = WebSession(endpoint)
62             else:
63                 # connect to local cluster
64                 from .deploy.local.session import LocalClusterSession
65 
66                 self._sess = LocalClusterSession(endpoint)
67         else:
68             self._sess = LocalSession()
69 
70         self._executed_keys = set()
71 
72     def run(self, *tensors, **kw):
73         from . import tensor as mt
74 
75         ret_list = False
76         if len(tensors) == 1 and isinstance(tensors[0], (tuple, list)):
77             ret_list = True
78             tensors = tensors[0]
79         elif len(tensors) > 1:
80             ret_list = True
81 
82         tensors = tuple(mt.tensor(t) for t in tensors)
83         result = self._sess.run(*tensors, **kw)
84         self._executed_keys.update(t.key for t in tensors)
85         for t in tensors:
86             t._execute_session = self
87 
88         ret = []
89         for r, t in zip(result, tensors):
90             if r is None:
91                 ret.append(r)
92                 continue
93             if t.isscalar() and hasattr(r, 'item'):
94                 ret.append(np.asscalar(r))
95             else:
96                 ret.append(r)
97         if ret_list:
98             return ret
99         return ret[0]
100 
101     @property
102     def endpoint(self):
103         return self._sess.endpoint
104 
105     @endpoint.setter
106     def endpoint(self, endpoint):
107         self._sess.endpoint = endpoint
108 
109     def decref(self, *keys):
110         if hasattr(self._sess, 'decref'):
111             self._sess.decref(*keys)
112 
113     def __getattr__(self, attr):
114         try:
115             obj = self._sess.__getattribute__(attr)
116             return obj
117         except AttributeError:
118             raise
119 
120     def __enter__(self):
121         self._sess.__enter__()
122         return self
123 
124     def __exit__(self, exc_type, exc_val, exc_tb):
125         self._sess.__exit__(exc_type, exc_val, exc_tb)
126 
127     close = __exit__
128 
129     def as_default(self):
130         Session._default_session = self
131         return self
132 
133     @classmethod
134     def default_or_local(cls):
135         if cls._default_session is not None:
136             return cls._default_session
137 
138         cls._default_session = Session()
139         return cls._default_session
140 
141 
142 def new_session(scheduler=None):
143     return Session(scheduler)
144
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mars/session.py b/mars/session.py
--- a/mars/session.py
+++ b/mars/session.py
@@ -16,6 +16,11 @@
 
 import numpy as np
 
+try:
+    from .resource import cpu_count
+except ImportError:
+    from multiprocessing import cpu_count
+
 
 class LocalSession(object):
     def __init__(self):
@@ -37,6 +42,8 @@
     def run(self, *tensors, **kw):
         if self._executor is None:
             raise RuntimeError('Session has closed')
+        if 'n_parallel' not in kw:
+            kw['n_parallel'] = cpu_count()
         return self._executor.execute_tensors(tensors, **kw)
 
     def decref(self, *keys):

{"golden_diff": "diff --git a/mars/session.py b/mars/session.py\n--- a/mars/session.py\n+++ b/mars/session.py\n@@ -16,6 +16,11 @@\n \n import numpy as np\n \n+try:\n+    from .resource import cpu_count\n+except ImportError:\n+    from multiprocessing import cpu_count\n+\n \n class LocalSession(object):\n     def __init__(self):\n@@ -37,6 +42,8 @@\n     def run(self, *tensors, **kw):\n         if self._executor is None:\n             raise RuntimeError('Session has closed')\n+        if 'n_parallel' not in kw:\n+            kw['n_parallel'] = cpu_count()\n         return self._executor.execute_tensors(tensors, **kw)\n \n     def decref(self, *keys):\n", "issue": "By default use core number as n_parallel for threaded scheduling\nUse core number as `n_parallel` for threaded scheduling, currently 1 thread by default.\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n# Copyright 1999-2018 Alibaba Group Holding Ltd.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\n\nclass LocalSession(object):\n    def __init__(self):\n        from .tensor.execution.core import Executor\n\n        self._executor = Executor()\n        self._endpoint = None\n\n    @property\n    def endpoint(self):\n        return self._endpoint\n\n    @endpoint.setter\n    def endpoint(self, endpoint):\n        if endpoint is not None:\n            raise ValueError('Local session cannot set endpoint')\n        self._endpoint = endpoint\n\n    def run(self, *tensors, **kw):\n        if self._executor is None:\n            raise RuntimeError('Session has closed')\n        return self._executor.execute_tensors(tensors, **kw)\n\n    def decref(self, *keys):\n        self._executor.decref(*keys)\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, *_):\n        self._executor = None\n\n\nclass Session(object):\n    _default_session = None\n\n    def __init__(self, endpoint=None):\n        if endpoint is not None:\n            if 'http' in endpoint:\n                # connect to web\n                from .web.session import Session as WebSession\n\n                self._sess = WebSession(endpoint)\n            else:\n                # connect to local cluster\n                from .deploy.local.session import LocalClusterSession\n\n                self._sess = LocalClusterSession(endpoint)\n        else:\n            self._sess = LocalSession()\n\n        self._executed_keys = set()\n\n    def run(self, *tensors, **kw):\n        from . import tensor as mt\n\n        ret_list = False\n        if len(tensors) == 1 and isinstance(tensors[0], (tuple, list)):\n            ret_list = True\n            tensors = tensors[0]\n        elif len(tensors) > 1:\n            ret_list = True\n\n        tensors = tuple(mt.tensor(t) for t in tensors)\n        result = self._sess.run(*tensors, **kw)\n        self._executed_keys.update(t.key for t in tensors)\n        for t in tensors:\n            t._execute_session = self\n\n        ret = []\n        for r, t in zip(result, tensors):\n            if r is None:\n                ret.append(r)\n                continue\n            if t.isscalar() and hasattr(r, 'item'):\n                ret.append(np.asscalar(r))\n            else:\n                ret.append(r)\n        if ret_list:\n            return ret\n        return ret[0]\n\n    @property\n    def endpoint(self):\n        return self._sess.endpoint\n\n    @endpoint.setter\n    def endpoint(self, endpoint):\n        self._sess.endpoint = endpoint\n\n    def decref(self, *keys):\n        if hasattr(self._sess, 'decref'):\n            self._sess.decref(*keys)\n\n    def __getattr__(self, attr):\n        try:\n            obj = self._sess.__getattribute__(attr)\n            return obj\n        except AttributeError:\n            raise\n\n    def __enter__(self):\n        self._sess.__enter__()\n        return self\n\n    def __exit__(self, exc_type, exc_val, exc_tb):\n        self._sess.__exit__(exc_type, exc_val, exc_tb)\n\n    close = __exit__\n\n    def as_default(self):\n        Session._default_session = self\n        return self\n\n    @classmethod\n    def default_or_local(cls):\n        if cls._default_session is not None:\n            return cls._default_session\n\n        cls._default_session = Session()\n        return cls._default_session\n\n\ndef new_session(scheduler=None):\n    return Session(scheduler)\n", "path": "mars/session.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n# Copyright 1999-2018 Alibaba Group Holding Ltd.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\ntry:\n    from .resource import cpu_count\nexcept ImportError:\n    from multiprocessing import cpu_count\n\n\nclass LocalSession(object):\n    def __init__(self):\n        from .tensor.execution.core import Executor\n\n        self._executor = Executor()\n        self._endpoint = None\n\n    @property\n    def endpoint(self):\n        return self._endpoint\n\n    @endpoint.setter\n    def endpoint(self, endpoint):\n        if endpoint is not None:\n            raise ValueError('Local session cannot set endpoint')\n        self._endpoint = endpoint\n\n    def run(self, *tensors, **kw):\n        if self._executor is None:\n            raise RuntimeError('Session has closed')\n        if 'n_parallel' not in kw:\n            kw['n_parallel'] = cpu_count()\n        return self._executor.execute_tensors(tensors, **kw)\n\n    def decref(self, *keys):\n        self._executor.decref(*keys)\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, *_):\n        self._executor = None\n\n\nclass Session(object):\n    _default_session = None\n\n    def __init__(self, endpoint=None):\n        if endpoint is not None:\n            if 'http' in endpoint:\n                # connect to web\n                from .web.session import Session as WebSession\n\n                self._sess = WebSession(endpoint)\n            else:\n                # connect to local cluster\n                from .deploy.local.session import LocalClusterSession\n\n                self._sess = LocalClusterSession(endpoint)\n        else:\n            self._sess = LocalSession()\n\n        self._executed_keys = set()\n\n    def run(self, *tensors, **kw):\n        from . import tensor as mt\n\n        ret_list = False\n        if len(tensors) == 1 and isinstance(tensors[0], (tuple, list)):\n            ret_list = True\n            tensors = tensors[0]\n        elif len(tensors) > 1:\n            ret_list = True\n\n        tensors = tuple(mt.tensor(t) for t in tensors)\n        result = self._sess.run(*tensors, **kw)\n        self._executed_keys.update(t.key for t in tensors)\n        for t in tensors:\n            t._execute_session = self\n\n        ret = []\n        for r, t in zip(result, tensors):\n            if r is None:\n                ret.append(r)\n                continue\n            if t.isscalar() and hasattr(r, 'item'):\n                ret.append(np.asscalar(r))\n            else:\n                ret.append(r)\n        if ret_list:\n            return ret\n        return ret[0]\n\n    @property\n    def endpoint(self):\n        return self._sess.endpoint\n\n    @endpoint.setter\n    def endpoint(self, endpoint):\n        self._sess.endpoint = endpoint\n\n    def decref(self, *keys):\n        if hasattr(self._sess, 'decref'):\n            self._sess.decref(*keys)\n\n    def __getattr__(self, attr):\n        try:\n            obj = self._sess.__getattribute__(attr)\n            return obj\n        except AttributeError:\n            raise\n\n    def __enter__(self):\n        self._sess.__enter__()\n        return self\n\n    def __exit__(self, exc_type, exc_val, exc_tb):\n        self._sess.__exit__(exc_type, exc_val, exc_tb)\n\n    close = __exit__\n\n    def as_default(self):\n        Session._default_session = self\n        return self\n\n    @classmethod\n    def default_or_local(cls):\n        if cls._default_session is not None:\n            return cls._default_session\n\n        cls._default_session = Session()\n        return cls._default_session\n\n\ndef new_session(scheduler=None):\n    return Session(scheduler)\n", "path": "mars/session.py"}]}