Debugging 在MPI中调试并行处理时发出警告?
我有以下代码:Debugging 在MPI中调试并行处理时发出警告?,debugging,mpi,visual-studio-debugging,visual-c++-2010-express,Debugging,Mpi,Visual Studio Debugging,Visual C++ 2010 Express,我有以下代码: #include <stdio.h> #include "mpi.h" #define NRA 512 /* number of rows in matrix A */ #define NCA 512 /* number of columns in matrix A */ #define NCB 512 /* number of columns in matrix B */ #define MASTER 0 /* taskid of
#include <stdio.h>
#include "mpi.h"
#define NRA 512 /* number of rows in matrix A */
#define NCA 512 /* number of columns in matrix A */
#define NCB 512 /* number of columns in matrix B */
#define MASTER 0 /* taskid of first task */
#define FROM_MASTER 1 /* setting a message type */
#define FROM_WORKER 2 /* setting a message type */
MPI_Status status;
double a[NRA][NCA], /* matrix A to be multiplied */
b[NCA][NCB], /* matrix B to be multiplied */
c[NRA][NCB]; /* result matrix C */
main(int argc, char **argv)
{
int numtasks, /* number of tasks in partition */
taskid, /* a task identifier */
numworkers, /* number of worker tasks */
source, /* task id of message source */
dest, /* task id of message destination */
nbytes, /* number of bytes in message */
mtype, /* message type */
intsize, /* size of an integer in bytes */
dbsize, /* size of a double float in bytes */
rows, /* rows of matrix A sent to each worker */
averow, extra, offset, /* used to determine rows sent to each worker */
i, j, k, /* misc */
count;
double t1,t2;
intsize = sizeof(int);
dbsize = sizeof(double);
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &taskid);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
numworkers = numtasks-1;
//printf(" size of matrix A = %d by %d\n",NRA,NCA);
//printf(" size of matrix B = %d by %d\n",NRA,NCB);
/*---------------------------- master ----------------------------*/
if (taskid == MASTER) {
printf("Number of worker tasks = %d\n",numworkers);
for (i=0; i<NRA; i++)
for (j=0; j<NCA; j++)
a[i][j]= i+j;
for (i=0; i<NCA; i++)
for (j=0; j<NCB; j++)
b[i][j]= i*j;
t1 = MPI_Wtime();
/* send matrix data to the worker tasks */
averow = NRA/numworkers;
extra = NRA%numworkers;
offset = 0;
mtype = FROM_MASTER;
for (dest=1; dest<=numworkers; dest++) {
rows = (dest <= extra) ? averow+1 : averow;
//printf(" Sending %d rows to task %d\n",rows,dest);
MPI_Send(&offset, 1, MPI_INT, dest, mtype, MPI_COMM_WORLD);
MPI_Send(&rows, 1, MPI_INT, dest, mtype, MPI_COMM_WORLD);
count = rows*NCA;
MPI_Send(&a[offset][0], count, MPI_DOUBLE, dest, mtype, MPI_COMM_WORLD);
count = NCA*NCB;
MPI_Send(&b, count, MPI_DOUBLE, dest, mtype, MPI_COMM_WORLD);
offset = offset + rows;
}
/* wait for results from all worker tasks */
mtype = FROM_WORKER;
for (i=1; i<=numworkers; i++) {
source = i;
MPI_Recv(&offset, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status);
MPI_Recv(&rows, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status);
count = rows*NCB;
MPI_Recv(&c[offset][0], count, MPI_DOUBLE, source, mtype, MPI_COMM_WORLD,
&status);
}
#ifdef PRINT
printf("Here is the result matrix\n");
for (i=0; i<NRA; i++) {
printf("\n");
for (j=0; j<NCB; j++)
printf("%6.2f ", c[i][j]);
}
printf ("\n");
#endif
t2 = MPI_Wtime();
fprintf(stdout,"Time = %.6f\n\n",
t2-t1);
} /* end of master section */
/*---------------------------- worker (slave)----------------------------*/
if (taskid > MASTER) {
mtype = FROM_MASTER;
source = MASTER;
#ifdef PRINT
printf ("Master =%d, mtype=%d\n", source, mtype);
#endif
MPI_Recv(&offset, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status);
#ifdef PRINT
printf ("offset =%d\n", offset);
#endif
MPI_Recv(&rows, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status);
#ifdef PRINT
printf ("row =%d\n", rows);
#endif
count = rows*NCA;
MPI_Recv(&a, count, MPI_DOUBLE, source, mtype, MPI_COMM_WORLD, &status);
#ifdef PRINT
printf ("a[0][0] =%e\n", a[0][0]);
#endif
count = NCA*NCB;
MPI_Recv(&b, count, MPI_DOUBLE, source, mtype, MPI_COMM_WORLD, &status);
#ifdef PRINT
printf ("b=\n");
#endif
for (k=0; k<NCB; k++)
for (i=0; i<rows; i++) {
c[i][k] = 0.0;
for (j=0; j<NCA; j++)
c[i][k] = c[i][k] + a[i][j] * b[j][k];
}
//mtype = FROM_WORKER;
#ifdef PRINT
printf ("after computer\n");
#endif
//MPI_Send(&offset, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD);
MPI_Send(&offset, 1, MPI_INT, MASTER, FROM_WORKER, MPI_COMM_WORLD);
//MPI_Send(&rows, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD);
MPI_Send(&rows, 1, MPI_INT, MASTER, FROM_WORKER, MPI_COMM_WORLD);
//MPI_Send(&c, rows*NCB, MPI_DOUBLE, MASTER, mtype, MPI_COMM_WORLD);
MPI_Send(&c, rows*NCB, MPI_DOUBLE, MASTER, FROM_WORKER, MPI_COMM_WORLD);
#ifdef PRINT
printf ("after send\n");
#endif
} /* end of worker */
MPI_Finalize();
} /* end of main */
#包括
#包括“mpi.h”
#定义矩阵A中的NRA 512/*行数*/
#定义NCA 512/*矩阵A中的列数*/
#定义NCB 512/*矩阵B中的列数*/
#定义第一个任务的主任务0/*任务ID*/
#从_MASTER 1/*定义设置消息类型*/
#从_WORKER 2/*设置消息类型定义*/
MPI_状态;
双a[NRA][NCA],/*矩阵a相乘*/
b[NCA][NCB],/*要乘以的矩阵b*/
c[NRA][NCB];/*结果矩阵C*/
主(内部argc,字符**argv)
{
int numtasks,/*分区中的任务数*/
taskid,/*任务标识符*/
numworkers,/*工人任务数*/
source,/*消息源的任务id*/
目的地,/*消息目的地的任务id*/
n字节,/*消息中的字节数*/
mtype,/*消息类型*/
intsize,/*整数的大小(字节)*/
dbsize,/*双浮点的大小(字节)*/
行,/*行矩阵A发送给每个工人*/
averow、extra、offset、/*用于确定发送给每个辅助进程的行*/
i、 j,k,/*杂项*/
计数
双t1,t2;
intsize=sizeof(int);
dbsize=sizeof(双倍);
MPI_Init(&argc,&argv);
MPI通信等级(MPI通信世界和任务ID);
MPI通信大小(MPI通信世界和numtasks);
numworkers=numtasks-1;
//printf(“矩阵A的大小=%d乘以%d\n”,NRA,NCA);
//printf(“矩阵B的大小=%d乘以%d\n”,NRA,NCB);
/*----------------------------主人----------------------------*/
if(taskid==MASTER){
printf(“工作任务数=%d\n”,numworkers);
对于(i=0;i而言,误差在这一行:
averow = NRA/numworkers;
numworkers为0,可能是因为您尚未配置Visual Studio以启动包含更多进程的MPI作业。在这里,让它做正确的事情非常困难,尤其是在调试时
确保安装正确-这是最可能的原因。在哪一行出现此错误?averow=NRA/numworkers;
哦,我记得。是因为我试图添加MPI\u Wtime()然后出现此错误?因为当我删除它时,如果只使用一个进程“numworkers”,则错误在第行mtype=FROM_MASTER;
numworkers=numtask-1必须为零,这可能会导致上述错误。我不知道visual studio如何处理调试中的进程。是否尝试运行代码?我尝试过运行代码,但只显示了辅助任务数:0
然后我必须先定义numtask。此处定义了“numtask”:MPI_Comm_大小(MPI_Comm_WORLD,&numtask);当您使用“mpiexec”运行代码时,您可以使用进程数声明代码。