在不同处理器中并行执行两个程序
我使用这个 c/c++ 代码来调度 2 个处理器并行运行 2 个不同的程序。请问如何确认 2 个处理器正在并行运行 2 个程序?
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
#include <sched.h>
#include <stdio.h>
#include <cstdlib>
int main(int argc, char *argv[])
{
cpu_set_t mask;
CPU_ZERO(&mask);
int pid;
pid=fork();
if (pid == 0) { /* second child */
CPU_SET(0, &mask);
sched_setaffinity(0, sizeof(mask), &mask);
system("/home/ifeanyi/Process/PID/Debug/PID");
}
else if (pid > 0) { // Parent ends
CPU_SET(1, &mask);
sched_setaffinity(getpid(), sizeof(mask), &mask);
cout << getpid() << endl;
system("/home/ifeanyi/Process/checkpointing/Debug/checkpointing"); // Last leaf
}
cout << endl;
}
I used this c/c++ code to schedule 2 processors to run 2 different programs in parallel. please how do I confirm that the 2 processors are running the 2 programs in parallel?
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
#include <sched.h>
#include <stdio.h>
#include <cstdlib>
int main(int argc, char *argv[])
{
cpu_set_t mask;
CPU_ZERO(&mask);
int pid;
pid=fork();
if (pid == 0) { /* second child */
CPU_SET(0, &mask);
sched_setaffinity(0, sizeof(mask), &mask);
system("/home/ifeanyi/Process/PID/Debug/PID");
}
else if (pid > 0) { // Parent ends
CPU_SET(1, &mask);
sched_setaffinity(getpid(), sizeof(mask), &mask);
cout << getpid() << endl;
system("/home/ifeanyi/Process/checkpointing/Debug/checkpointing"); // Last leaf
}
cout << endl;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,使用 任务集,例如
Rather than hard-coding these details in your program it is in general easier and more flexible to do it from the command line using taskset, e.g.