我有一个父母有5个子进程.我想向每个子进程发送一个随机变量.每个孩子都会对变量进行平方并将其发送回父母,父母将这些变量加在一起.
这甚至可能吗?我无法弄明白......
编辑:此过程将使用共享内存.
我想使用IPC将共享内存分配为2D阵列.我尝试了以下方法:
id_shmem = shmget(ipc_key, sizeof(int)*rows*columns, IPC_CREAT|0666);
matrix = (int **)shmat(id_shmem, 0, 0);
Run Code Online (Sandbox Code Playgroud)
问题是,每当我尝试在矩阵中写入内容时,我都会遇到段错误.
这是我的设置......
/* Bounded Buffer item structure */
struct item {
int id; /* string index value */
char str[80]; /* string value */
};
/* Structure for the shared memory region */
typedef struct {
int debug; /* debug flag */
int in; /* index of next empty slot */
int out; /* index of next full slot */
char MUTEXname[32]; /* name of the MUTEX semaphore */
char EMPTYname[32]; /* name of the EMPTY semaphore */
char FULLname[32]; /* …Run Code Online (Sandbox Code Playgroud) 我目前正在ubunto上开发一个应用程序并调用shm_open,目前默认路径在/ var/run/shm内.但是我需要将其更改为/ tmp.只是尝试以下操作不起作用:
fd = shm_open("/ tmp/test",O_RDWR | O_CREAT,0777);
任何人都可以建议吗?
我正在尝试创建一个将由多个进程使用的共享内存,这些进程不一定由同一用户启动,因此我使用以下行创建了段:
fd = shm_open(SHARE_MEM_NAME,O_RDWR | O_CREAT,0606);
但是,当我检查在/ dev/shm中创建的文件的权限时,它们是:
-rw----r-- 1 lmccauslin lmccauslin 1784 2012-08-10 17:11 /dev/shm/CubeConfigShare
不像-rw----rw-我预期的那样.
/ dev/shm的权限是lrwxrwxrwx.
类似地创建的信号量也会发生完全相同的事情.
内核版本:3.0.0-23-通用
glibc版本:EGLIBC 2.13-20ubuntu5.1
有人有任何想法吗?
基本上,我很难理解这里到底出了什么问题.
在调试时,共享内存似乎不以块独占方式运行.正常运行代码时,不会打印任何内容.但是,如果我尝试调试它,则在块之间共享共享内存并到达print语句.
这是一个例子,显然这不是非常有用的代码,但它重现了我的系统上的问题.难道我做错了什么?这是调试器中的错误或预期行为吗?
__global__
void test()
{
__shared__ int result[1];
if (blockIdx.x == 0 && blockIdx.y == 0 && blockIdx.z == 0)
result[0] = 4444;
else
{
if (result[0] == 4444)
printf("This should never print if shared memory is unique\n");
}
}
Run Code Online (Sandbox Code Playgroud)
并推出它:
test<<<dim3(8,8,1), dim3(8,8,1)>>>();
Run Code Online (Sandbox Code Playgroud)
完全有可能我完全误解了共享内存.
谢谢您的帮助.
其他信息: 我使用的是GTX 460.为项目设置了Compute_20和sm_20.我正在使用nsight 3.0预览在Visual Studio 2010中编写代码.
共享内存被"条带化"到银行中.正如众所周知的那样,这导致了银行冲突的整个问题.
问题: 但是如何确定共享内存中存在多少个银行("条带")?
(围绕NVIDIA"devtalk"论坛,似乎每块共享内存被"条带化"到16家银行.但我们怎么知道呢?线程暗示这已经有几年了.有没有改变?它是否已修复所有支持 NVIDIA CUDA的卡?有没有办法从运行时API中确定这一点(我没有在那里看到它,例如在cudaDeviceProp下)?是否有一种手动方式在运行时确定它?)
我产生了一个单独的进程来处理我的云服务.我像这样产生它:
CldProc = Process(target=CloudRun)
CldProc.start()
Run Code Online (Sandbox Code Playgroud)
我想知道我是否可以在CloudProc和我当前的主流程之间拥有一个共享字典?
编辑: 或者我想使用pickle将我的数据转储到进程中的文件并加载回来,这要求我使用join()等待进程完成并退出.
第二次编辑 所以,我现在将我的dict声明为mac_dict = {},然后我将其填入我的子进程并希望在我的主进程中访问它.现在我试过这个:
>>> dict = dict()
>>> dict['A'] = 1
>>> print dict
{'A': 1}
Run Code Online (Sandbox Code Playgroud)
那么Python如何知道应该从Managers调用dict()?我可以遵循任何例子吗?
我在父母和孩子之间创建共享内存.然后我从子进程向共享内存写一个值并从父进程中读取它.但价值观是不同的.这是代码:
#include <sys/shm.h>
#include <sys/stat.h>
#include <stdio.h>
int main()
{
int seg_id, pid;
int fib1 = 1, fib = 1, temp;
int i, tempsize;
int *result;
seg_id = shmget(IPC_PRIVATE, 8, S_IRUSR | S_IWUSR);
result = (int *) shmat(seg_id, NULL, 0);
printf("Enter size\n> ");
scanf("%d", &tempsize);
pid = fork();
if (pid == 0)
{
for(i = 0; i < tempsize; i++)
{
temp = fib;
fib = fib + fib1;
fib1 = temp;
}
printf("fib value %d\n", fib);
result = fib; …Run Code Online (Sandbox Code Playgroud) 当打开共享内存对象(使用shm_open)时,为该对象提供名称.每个对象必须具有不同的名称.
有没有办法识别所有当前分配的共享对象的名称?如果是这样,怎么样?
更新:在我看来,这些(就像@HristoLliev所称的那样)系统V共享内存段. ipcs -m报告类似于我期望的段列表,但不显示名称.
shared-memory ×10
c ×4
linux ×3
c++ ×2
cuda ×2
ipc ×2
posix ×2
boost ×1
dictionary ×1
fork ×1
gpu ×1
nsight ×1
pointers ×1
python-2.7 ×1