- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
编辑:感谢之前的帮助。我真的很感激。
我是否也应该从 *list 中删除指针?为了创建 atributo 和 estrucura,我也在使用指针,这也会有问题吗?
union atributo{
int valor1;
char valor2[tamChar];
float valor3;
};
struct estructura{
int tipo[tamEstruct]; //Here i will have an array with the types of the union
union atributo *list[tamEstruct];
};
union atributo *atributos;
struct estructura *estructuras;
estructuras = malloc (sizeof(struct estructura) * (cantEstruct) );
MPI_Datatype atributo_MPI;
MPI_Datatype type[1] = { MPI_BYTE };
int blocklen[1] = { tamChar }; // the largest element is the chat
MPI_Aint disp[1];
disp[0]= atributos[0]; // the begin of the union
MPI_Datatype estructura_MPI;
MPI_Datatype type[2] = { MPI_INT, atributo_MPI };
int blocklen[2] = { tamEstruct, tamEstruct};
MPI_Aint disp2[2];
disp2[0]= offsetof(atributos, tipo);
disp2[1]= offsetof(atributos, list);
我接近正确的代码了吗?
最佳答案
那段代码有几处错误。
首先,在这种情况下,结构和 union 非常不同。结构包含列出的每个元素,在内存中一个接一个地排列。另一方面, union 仅与其最大元素一样大,并且其所有成员共享相同的内存空间(好像它们是结构的唯一成员)。这意味着您不能将 union 打包到 MPI_Struct
中,因为每个成员的偏移量实际上都是 0。
有两种方法可以解决 union 数组的问题:
MPI_BYTE
数组发送。这很简单,但如果您的进程不共享相同的数据表示(例如,它们的整数在字节序上不同),则存在数据损坏的风险。MPI_Pack()
将值一个一个打包。这是类型安全的,但更复杂,并且会生成数据的内存副本。请注意,在任何一种情况下,接收进程都需要知道它接收到的值(即,如果它接收到 3 个 union ,是那 3 个整数,还是 2 个整数和一个 float ,等等)。如果您使用 union ,您也必须发送此信息。
您可能需要考虑一种更棘手的方法:根据哪个值有效对枚举进行分组,并发送一条消息,其中相似的枚举彼此相邻放置(例如,包含 数组的消息MPI_INT
,然后是 MPI_FLOAT
的数组等等)。通过巧妙地使用派生的 MPI 数据类型,您可以保持类型安全,避免内存中复制,和避免发送多条消息。
第二:永远不要在 MPI 进程之间发送指针!很容易将 char*
视为 char
的数组,但事实并非如此。它只是一个内存地址,对您将其发送到的进程没有意义,即使有,您实际上也没有发送它指向的数据。如果 valor2
是一个具有相当短的最大长度的字符串,我建议将它声明为 char valor2[maxLength]
以便它的内存分配在实际结构/联盟。如果这不可行,您将不得不做更多的内存杂耍,以将您的字符串传递给其他进程,就像处理任何可变大小的数组一样。
关于在 MPI 上创建结构和 union ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19637159/
是否有等级编号对组编号的概括?对于我的代码,我想创建 MPI::COMM_WORLD 的分层分解。假设我们使用 16 个线程。我使用 MPI::COMM_WORLD.Split 创建 4 个通信器,每
能够使用多个节点执行 MPI 作业以加快流程 这是我目前使用的命令: mpirun --hostfile myhost -np 2 --map-by slot Job.x//只在第一个节点执行 mpi
我想创建一个新的通信器,它只保留处理中使用的行列,如果我有 24 个可用处理器而我只需要 10 个,那么该组应该只保留这 10 个,否则它将保留所有他们。出于某种原因,当我尝试创建一个通信器时,一切都
我正在开发一些程序,而不是在每个节点上有 4 个内核的 4 节点集群上运行。我有一个非常快的 OpenMP 版本的程序,它只在一个集群上运行,我正在尝试使用 MPI 扩展它。由于我的经验有限,我想知道
这是我尝试在 MPI 中编写经典平滑像素平均算法的代码。我几乎让它工作了,但是光晕交换发生了一些奇怪的事情,因为可以看到边缘的线条。我似乎找不到错误。我是否正确地交换了光环?我应该收集最终数组的哪一部
我有兴趣使用 MPI(消息传递接口(interface))实现一种事件驱动的调度队列。我要解决的基本问题是:我有一个主进程,它将作业插入全局队列,每个可用的从进程检索队列中的下一个作业(如果有的话)。
当我们在集群上使用命令 say mpirun -np 4 a.out 启动 MPI 程序时,然后MPI 运行时系统如何跨 CPU 分配进程? 我的意思是,假设它在集群中找到一个空闲的四核 CPU,它会
使用 mpirun 启动 MPI 作业时或 mpiexec ,我可以理解人们如何开始每个单独的过程。但是,如果没有任何编译器魔法,这些包装器可执行文件如何将安排(MPI 通信器)传达给 MPI 进程?
MPI 中的等级和进程有什么区别? 最佳答案 Here是我从中学习所有 MPI 的资源,您可能会发现它很有用。 关于你的问题:流程 是正在运行的程序的实际实例。 MPI 允许您创建逻辑 团体进程,并且
MPI 障碍的时间复杂度是多少?它们是否可以扩展到大量核心(>> 10k)? 最佳答案 屏障复杂性与实现高度相关。它可以是线性的,可以是对数的,也可以是更好或更差。某些架构为某些集体操作提供专用网络,
我正在尝试 MPI,想知道这段代码是否会导致死锁。 MPI_Comm_rank (comm, &my_rank); if (my_rank == 0) { MPI_Send (sendbuf,
我有一个简单的 MPI 代码,可以打印出进程的等级,使用 Intel 编译器和 MPI 库进行编译和链接。然后我在集群的主节点上以交互方式运行它:mpiexec -n 50 ./a.out该节点只有
我正在尝试使用 mpi run 使用扭矩调度程序来运行我的程序。虽然在我的 pbs 文件中我通过 加载了所有库 export LD_LIBRARY_PATH=/path/to/library 但它给出
我在所有等级上都有一个相同长度的数组(假设为 10)。数组中的某些值包含处理器的等级。例如 ... Proc 1: [1 0 0 0 0 1 0 0 0 1] Proc 2: [0 2 2 0 0 0
我想在集群中的每台机器上独立地轻松执行集体通信。假设我有 4 台机器,每台机器有 8 个内核,我的 MPI 程序将运行 32 个 MPI 任务。对于给定的功能,我想要的是: 在每个主机上,只有一个任务
我希望能够获得某个通信器的唯一 ID,但是当您通过 MPI_Comm_split() 调用获得此通信器时,这似乎是一项不可能完成的任务。我知道什么时候 MPI_Comm_split() 被集体调用,每
非阻塞发送/接收立即在 MPI 中返回,操作在后台完成。我看到这种情况发生的唯一方法是当前进程/线程调用/创建另一个进程/线程并将发送/接收代码的图像加载到其中并返回。然后这个新进程/线程完成这个操作
冗长的背景 我正在为心脏电生理学模拟并行处理一些代码。由于用户可以使用内置脚本语言指定他们自己的模拟,我无法知道如何在通信与计算之间进行权衡。为了解决这个问题,我正在制作一种运行时分析器,一旦看到要运
我打算做一些并行计算,我完全是这方面的初学者。我将使用 MPI 来完成并行工作,采用 Master-Slave 模型。我现在有四台机器,希望其中一台作为主节点。但是,我不知道如何指定运行该程序的其他机
我可以在我的大学使用 PelicanHPC 访问集群网络,其中运行各种 MPI 程序,但在家里我想练习编写/使用其他 MPI 程序。有没有办法在我自己的系统上运行 MPI 程序? (我在 Ubuntu
我是一名优秀的程序员,十分优秀!