告诉线程以编程方式更改它正在处理的核心的方法是什么?
假设我使用的是FX-8150,它有一些内核,但我想让我的一个线程在5.core下工作。这个是可能的吗?如果是,你能给我一个Java的样本吗?该线程可以是另一个进程的线程或当前进程的线程。
我的伪例:
time interval 1 : my_thread working in first core at 5GHz while other cores are 3.6 GHz
time interval 2 : my_thread working in second core at 5GHz while other cores are 3.6 GHz
time interval 3 : my_thread working in third core at 5GHz while other cores are 3.6 GHz
time interval 4 : my_thread working in fourth core at 5GHz while other cores are 3.6 GHz
time interval 5 : my_thread working in fifth core at 5GHz while other cores are 3.6 GHz
time interval 6 : my_thread working in sixth core at 5GHz while other cores are 3.6 GHz
time interval 7 : my_thread working in seventh core at 5GHz while other cores are 3.6 GHz
time interval 8 : my_thread working in eighth core at 5GHz while other cores are 3.6 GHz所有其他核心都需要空闲。
发布于 2012-09-28 22:04:15
我有一个名为Java Thread Affinity的库,它允许您将正在运行的线程分配给逻辑线程或核心。
在您的情况下,至少需要为操作系统允许一个内核,并且可以在Linux中保留所有剩余的内核。线程库将线程分配给这些保留的核心。您需要保留cpu的原因是为了防止其他线程在该cpu上运行。您可以告诉该库将一个线程分配给一个逻辑cpu或整个核心。您可以将线程分配到与另一个线程相同或不同的核心或套接字上。
https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started
该库目前支持Windows和Linux。
发布于 2012-09-28 22:05:36
假设您使用的是Windows7。在任务管理器中找到进程,右键单击它,选择设置亲和性,选择您希望它使用的内核。
http://www.sevenforums.com/tutorials/83632-processor-affinity-set-applications.html
Programatically:
您可以永久设置程序的关联性,方法是在程序所在的文件夹中创建一个.bat批处理文件,其中包含以下内容:
start /affinity 1 program_name.exe
start /affinity 1 <invoke your_java_program>这将强制程序仅使用cpu核心0。使用... /affinity 2...指定cpu核心1等
然后,您应该修改程序的开始菜单和/或桌面快捷方式,使其指向新创建的批处理文件。
一个很小的缺点是,在你的程序打开之前,你会在屏幕上看到一个短暂闪烁的cmd小窗口。
为了获得更高的性能,您可以添加/high来为应用程序提供更高的cpu优先级。
start /affinity 1 /high program_name.exe
start /affinity 1 <invoke your_java_program>https://stackoverflow.com/questions/12641457
复制相似问题