本文整理汇总了C++中Epetra_SerialComm::ScanSum方法的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_SerialComm::ScanSum方法的具体用法?C++ Epetra_SerialComm::ScanSum怎么用?C++ Epetra_SerialComm::ScanSum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Epetra_SerialComm
的用法示例。
在下文中一共展示了Epetra_SerialComm::ScanSum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
// define an Epetra communicator
Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
// get the proc ID of this process
int MyPID = Comm.MyPID();
// get the total number of processes
int NumProc = Comm.NumProc();
// output some information to std output
cout << Comm << endl;
// ======================== //
// now some basic MPI calls //
// ------------------------ //
int ivalue;
double dvalue, dvalue2;
double* dvalues; dvalues = new double[NumProc];
double* dvalues2; dvalues2 = new double[NumProc];
int root = 0;
// equivalent to MPI_Barrier
Comm.Barrier();
if (MyPID == root) dvalue = 12.0;
// On input, the root processor contains the list of values
// (in this case, a single value). On exit, all processes will
// have he same list of values. Note that all values must be allocated
// vefore the broadcast
// equivalent to MPI_Broadcast
Comm.Broadcast(&dvalue, 1, root);
// as before, but with integer values. As C++ can bind to the appropriate
// interface based on argument typing, the type of data is not required.
Comm.Broadcast(&ivalue, 1, root);
// equivalent MPI_Allgather
Comm.GatherAll(dvalues, dvalues2, 1);
// equivalent to MPI_Allreduce with MPI_SUM
dvalue = 1.0*MyPID;
Comm.SumAll( &dvalue, dvalues, 1);
// equivalent to MPI_Allreduce with MPI_SUM
Comm.MaxAll( &dvalue, dvalues, 1);
// equiavant to MPI_Scan with MPI_SUM
dvalue = 1.0 * MyPID;
Comm.ScanSum(&dvalue, &dvalue2, 1);
cout << "On proc " << MyPID << " dvalue2 = " << dvalue2 << endl;
delete[] dvalues;
delete[] dvalues2;
// ======================= //
// Finalize MPI and return //
// ----------------------- //
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return( EXIT_SUCCESS );
} /* main */