diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 9371406ddb68f391d1aaa720fda1030eb6af2a1c..0bf0e7c3e919bb6219f8ee7f99eff6c47656bec4 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -85,11 +85,14 @@ def _current_expected_place(): def _cpu_num(): if "CPU_NUM" not in os.environ.keys(): - sys.stderr.write( - 'The CPU_NUM is not specified, you should set CPU_NUM in ' - 'the environment variable list, i.e export CPU_NUM=1. CPU_NUM ' - 'indicates that how many CPUPlace are used in the current task.\n' - '!!! The default number of CPUPlaces is 1.\n\n') + if multiprocessing.cpu_count() > 1: + sys.stderr.write( + '!!! The CPU_NUM is not specified, you should set CPU_NUM in the environment variable list.\n' + 'CPU_NUM indicates that how many CPUPlace are used in the current task.\n' + 'And if this parameter are set as N (equal to the number of physical CPU core) the program may be faster.\n\n' + 'export CPU_NUM={} # for example, set CPU_NUM as number of physical CPU core which is {}.\n\n' + '!!! The default number of CPU_NUM=1.\n'.format( + multiprocessing.cpu_count(), multiprocessing.cpu_count())) os.environ['CPU_NUM'] = str(1) cpu_num = os.environ.get('CPU_NUM') return int(cpu_num)