- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 MPI 将两个 nxn 矩阵相乘。第二个矩阵 (bb) 被广播给所有“奴隶”,然后从第一个矩阵 (aa) 发送一行来计算乘积。然后它将答案发送回主进程并存储在产品矩阵 cc 中。出于某种原因,我收到错误:
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= EXIT CODE: 11
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
我相信主进程正在接收从属进程发送的所有消息,反之亦然,所以我不确定这里发生了什么……有什么想法吗?
主要内容:
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/times.h>
#define min(x, y) ((x)<(y)?(x):(y))
#define MASTER 0
double* gen_matrix(int n, int m);
int mmult(double *c, double *a, int aRows, int aCols, double *b, int bRows, int bCols);
int main(int argc, char* argv[]) {
int nrows, ncols;
double *aa; /* the A matrix */
double *bb; /* the B matrix */
double *cc1; /* A x B computed */
double *buffer; /* Row to send to slave for processing */
double *ans; /* Computed answer for master */
int myid, numprocs;
int i, j, numsent, sender;
int row, anstype;
double starttime, endtime;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
if (argc > 1) {
nrows = atoi(argv[1]);
ncols = nrows;
if (myid == 0) {
/* Master Code */
aa = gen_matrix(nrows, ncols);
bb = gen_matrix(ncols, nrows);
cc1 = malloc(sizeof(double) * nrows * nrows);
starttime = MPI_Wtime();
buffer = (double*)malloc(sizeof(double) * ncols);
numsent = 0;
MPI_Bcast(bb, ncols*nrows, MPI_DOUBLE, MASTER, MPI_COMM_WORLD); /*broadcast bb to all slaves*/
for (i = 0; i < min(numprocs-1, nrows); i++) { /*for each process or row*/
for (j = 0; j < ncols; j++) { /*for each column*/
buffer[j] = aa[i * ncols + j]; /*get row of aa*/
}
MPI_Send(buffer, ncols, MPI_DOUBLE, i+1, i+1, MPI_COMM_WORLD); /*send row to slave*/
numsent++; /*increment number of rows sent*/
}
ans = (double*)malloc(sizeof(double) * ncols);
for (i = 0; i < nrows; i++) {
MPI_Recv(ans, ncols, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
sender = status.MPI_SOURCE;
anstype = status.MPI_TAG;
for (i = 0; i < ncols; i++){
cc1[(anstype-1) * ncols + i] = ans[i];
}
if (numsent < nrows) {
for (j = 0; j < ncols; j++) {
buffer[j] = aa[numsent*ncols + j];
}
MPI_Send(buffer, ncols, MPI_DOUBLE, sender, numsent+1,
MPI_COMM_WORLD);
numsent++;
} else {
MPI_Send(MPI_BOTTOM, 0, MPI_DOUBLE, sender, 0, MPI_COMM_WORLD);
}
}
endtime = MPI_Wtime();
printf("%f\n",(endtime - starttime));
} else {
/* Slave Code */
buffer = (double*)malloc(sizeof(double) * ncols);
bb = (double*)malloc(sizeof(double) * ncols*nrows);
MPI_Bcast(bb, ncols*nrows, MPI_DOUBLE, MASTER, MPI_COMM_WORLD); /*get bb*/
if (myid <= nrows) {
while(1) {
MPI_Recv(buffer, ncols, MPI_DOUBLE, MASTER, MPI_ANY_TAG, MPI_COMM_WORLD, &status); /*recieve a row of aa*/
if (status.MPI_TAG == 0){
break;
}
row = status.MPI_TAG; /*get row number*/
ans = (double*)malloc(sizeof(double) * ncols);
for (i = 0; i < ncols; i++){
ans[i]=0.0;
}
for (i=0; i<nrows; i++){
for (j = 0; j < ncols; j++) { /*for each column*/
ans[i] += buffer[j] * bb[j * ncols + i];
}
}
MPI_Send(ans, ncols, MPI_DOUBLE, MASTER, row, MPI_COMM_WORLD);
}
}
} /*end slave code*/
} else {
fprintf(stderr, "Usage matrix_times_vector <size>\n");
}
MPI_Finalize();
return 0;
}
最佳答案
此错误消息通常意味着至少有一个 MPI 进程崩溃,并且整个 MPI 作业随后中止。它可能由任何类型的错误引起,但大多数情况下,它是由错误的内存访问引起的段错误。
我没有仔细查看代码,所以我不知道逻辑是否有效等,但我可以说的是这一行有问题:
MPI_Recv(&ans, nrows, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
确实,这里有两个问题:
&ans
是一个**double
,这不是你想要的,我猜你想要的是ans
ans
还没有分配所以不能作为接收缓冲区首先尝试解决这个问题,看看会发生什么。
编辑:在您的新代码上,您分配 ans
如下:
ans = (double*)malloc(sizeof(double) * ncols);
然后你像这样初始化它:
for (i = 0; i < nrows; i++) {
ans[i]=0.0;
}
然后像这样使用它:
MPI_Send(ans, nrows, MPI_DOUBLE, MASTER, row, MPI_COMM_WORLD);
或
MPI_Recv(ans, nrows, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
这不一致:ans
的大小是ncols
还是nrows
?
你的新错误信息是什么?
关于c - MPI 矩阵乘法,进程未清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32730995/
我需要为元素属性动态构建 XPath 查询,其中属性值由用户提供。我不确定如何清理或清理此值以防止 XPath 等同于 SQL 注入(inject)攻击。例如(在 PHP 中): xpath("//m
问题很简单:在使用 PHPmailer 类时我应该使用任何类型的清理吗? 我制作了使用 phpmailer 类发送电子邮件的简单发送邮件表单。目前我只使用“htmlspecialchars”进行清理(
你可以在python中创建一个在for循环退出时运行清理代码的迭代吗?就像是: from random import randint class Iterable: def __iter__(
假设我定期将数据插入 SQLite 数据库,然后清除前 50% 的数据,但我不清理。 我现在是否有类似文件前 50% 的清零页面之类的东西?如果我添加另一批数据,我是否正在填写那些清零的页面? 手册中
我有一堆 HTML 代码,我想在其中删除所有 HTML 标记。 我认为 Regex(正则表达式)可以做到这一点。通过搜索和替换,我将如何执行此操作? 我尝试了 ,我认为 * 是通配符,但显然不是。
我仍在学习 Haskell,我想知道是否有一种不太冗长的方法来使用 1 行代码来表达以下语句: map (\x -> (x, (if mod x 3 == 0 then "fizz" else "")
我需要怎么做才能正确清理/转义程序化SSH命令中输入的参数? 例如,路径参数- public boolean exists(String path) { try { Chann
这个问题已经有答案了: How to clear the canvas for redrawing (25 个回答) 已关闭10 个月前。 我目前正在尝试创建一个带有雨滴落下的 Canvas ,我唯一
我目前正在使用此过程来清理/过滤用户输入的评论 -> 这个是用来去掉斜线的……和 if (get_magic_quotes_gpc()) { function stripslashe
是否可以在 portal_setup 中删除旧的导入配置文件。 目前,我的网站上有许多可追溯到 2009 年的条目:: import-all-profile-Products.Archetypes_
假设我有多个指令,包括以下内容: ...template content... ...template content... 你如何销毁指令?通常我会在 jquery 中做一些我 $('#2').re
我正在开发一个可移植java应用程序,它可以在用户的PC(Windows XP)上动态生成一些文件。现在,我想要的是在java程序退出后删除这些临时文件。显然,java的文件删除机制是不可信的。即
我有一个 argv c 程序,它反转单词,并查看它是否是回文。我只是想清理输出并让它打印原始输入而不是相反的输入,但由于它是 argv,我似乎不知道该怎么做。 int main(int argc, c
我的网页上有一篇用 markdown 写的文章,我想在索引页上显示一份简短的简历。 问题是正文有markdown,我想在简历上显示纯文本。 例如: Article text: Hello people
在下面的代码片段中,可以做些什么来a)让编译器安静,b)清理交叉的指针困惑? extern struct tree *sintablein[sintablesize]; struct tree *(*
我试图弄清楚 WeakHashMap 在垃圾收集后如何清理。正如你们中许多人可能知道的那样,当 WeakHashMap 条目的键被垃圾回收时,它会自动删除。但是,例如,如果我做这样的事情: List>
我对构建的理解是,它只编译上次构建中编辑过的Java文件,而干净构建将删除所有类文件并重新编译所有文件。那么,当单独构建就足以满足我提供最新版本的类文件的需要时,干净构建的效用是什么? 最佳答案 有时
是否有任何简单的(内置的、附加的、开源的或商业的)在 Postgresql(主从)上进行复制,以便在复制时清理从属内部的数据以符合 PCI 合规性? ETL工具怎么样?它不一定是瞬时的……最多一个小时
我有一个将数据保存到 MySQL 数据库的网站 在将 HTML 插入 MySQL 或在我的网站上显示它时,我应该转义 HTML 吗? 理想情况下,我想将原始 HTML 输入到我的数据库中,并在每次从中
我知道我已经asked一个关于 sanitizer 和转义的问题,但我有一个问题没有得到回答。 好了,到此为止。如果我有一个 PHP 脚本并且我 GET用户输入和SELECT它来自 mySQL 数据库
我是一名优秀的程序员,十分优秀!