当数据较大时,使用点到点操作的mpi点产品将失败

当数据较大时,使用点到点操作的mpi点产品将失败,mpi,Mpi,我在下面的代码2中得到了两个向量的点积VECTORSIZE。代码工作正常,直到VECTORSIZE达到10000,但随后它会给出不相关的结果。当我试着调试程序时,我看到处理器0(root)在所有处理器发送本地结果之前完成了它的工作。当我使用MPI\u Reduce()(代码第2部分)时,我遇到了同样的情况。但是,如果在MPI\u Reduce()之前使用MPI\u Scatter() #include <stdio.h> #include <stdlib.h> #incl

我在下面的代码2中得到了两个向量的点积
VECTORSIZE
。代码工作正常,直到VECTORSIZE达到10000,但随后它会给出不相关的结果。当我试着调试程序时,我看到处理器0(root)在所有处理器发送本地结果之前完成了它的工作。当我使用
MPI\u Reduce()
(代码第2部分)时,我遇到了同样的情况。但是,如果在
MPI\u Reduce()
之前使用
MPI\u Scatter()

#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"

#define VECTORSIZE 10000000
#define ROOT 0


//[[## operation ConstructVectorPart()
void ConstructVector(double * vector, int size, short vectorEnu)
{
  int i = 0;
    if(vectorEnu == 1) // i.e vector 1
    {
        for(i = 0; i < size; i++)
        {
            vector[i] = 0.1 + (i%20)*0.1;
        }
    }
    else if(vectorEnu == 2) // i.e. vector 2
    {
        for(i = 0 ; i < size; i++)
        {
            vector[i] = 2-(i%20)*0.1;
        }
    }
}

//[[## operation dotproduct()
double dotproduct(double* a, double* b, int length) 
{
  double result = 0;
    int i = 0;

  for (i = 0; i<length; i++)
        result +=  a[i] * b[i];

  return result;
}

int main( argc, argv )
int  argc;
char **argv;
{
  int processorID, numofProcessors;
    int partialVectorSize ;
    double t1, t2, localDotProduct, result;

  MPI_Init( &argc, &argv );
  MPI_Comm_size( MPI_COMM_WORLD, &numofProcessors );
  MPI_Comm_rank( MPI_COMM_WORLD, &processorID );

    if(processorID == 0)
        t1 = MPI_Wtime();

    // all processors constitute their own vector parts and 
    // calculates corresponding partial dot products
    partialVectorSize = VECTORSIZE/ numofProcessors;


    double *v1, *v2;
    v1 = (double*)(malloc((partialVectorSize) * sizeof(double)));
    v2 = (double*)(malloc((partialVectorSize) * sizeof(double)));

    ConstructVectorPart(v1,0,partialVectorSize,1);
    ConstructVectorPart(v2,0,partialVectorSize,2);

    localDotProduct = dotproduct(v1,v2, partialVectorSize);

    printf(" I am processor %d \n",processorID);

//----------------- code part 1 ---------------------------------------------   
    if( processorID != 0 ) // if not a master
    { // send partial result to master
        MPI_Send( &localDotProduct, 1, MPI_DOUBLE, 0,0, MPI_COMM_WORLD );
    }
    else // master
    {  // collect results
      result = localDotProduct; // own result
        int j;
        for( j=1; j<numofProcessors; ++j )
        {
            MPI_Recv( &localDotProduct, 1, MPI_DOUBLE, j, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE);
            result += localDotProduct;
        }
        t2 = MPI_Wtime();
        printf(" result = %f  TimeConsumed = %f \n",result, t2-t1);
    }
 //----------------------------------------------------------------------------


    /*
   //--------------------- code part 2 ----------------
  MPI_Reduce(&localDotProduct, &result, 1, MPI_DOUBLE, MPI_SUM, 0,MPI_COMM_WORLD);

    if(processorID == 0)
    {
            t2 = MPI_Wtime();
            printf(" result = %f  TimeConsumed = %f \n",result, t2-t1);
    }
    //---------------------------------------------------
    */

    MPI_Finalize();

        free(v1);
        free(v2);

    return 0;
}
#包括
#包括
#包括“mpi.h”
#定义向量大小10000000
#定义根0
//[[##操作构造函数部分()
void ConstructVector(双*向量、整数大小、短向量菜单)
{
int i=0;
if(vectorEnu==1)//即向量1
{
对于(i=0;i对于(i=0;i它在做什么不正确?当我在本地运行代码时(忽略所有的点积计算,因为它不是MPI),我对4个进程没有任何问题。我无法理解你为什么忽略点积计算?为什么不是mpi?执行会给出正确的点积结果,直到向量大小合理,然后执行失败,即给出错误的结果。感谢你的关注。我忽略了它,因为点积计算中没有mpi调用n、 这意味着你的MPI代码很可能不是问题所在,它可能来自于你对点积本身的计算。