From e7e8a9f60ee682db1e5bb534a74625ec4c922dea Mon Sep 17 00:00:00 2001 From: rahuel Date: Tue, 22 Jan 2008 10:51:03 +0000 Subject: [PATCH] Asynchronisme MPI : tests unitaires et fonctionnels avec CPPUNIT --- src/ParaMEDMEM/Test/MPIAccessDECTest.cxx | 51 ++ src/ParaMEDMEM/Test/MPIAccessDECTest.hxx | 103 ++++ src/ParaMEDMEM/Test/MPIAccessTest.cxx | 51 ++ src/ParaMEDMEM/Test/MPIAccessTest.hxx | 106 ++++ src/ParaMEDMEM/Test/TestMPIAccess.cxx | 31 ++ src/ParaMEDMEM/Test/TestMPIAccessDEC.cxx | 31 ++ src/ParaMEDMEM/Test/test_AllToAllDEC.cxx | 187 ++++++++ src/ParaMEDMEM/Test/test_AllToAllTimeDEC.cxx | 246 ++++++++++ src/ParaMEDMEM/Test/test_AllToAllvDEC.cxx | 193 ++++++++ src/ParaMEDMEM/Test/test_AllToAllvTimeDEC.cxx | 341 +++++++++++++ .../Test/test_AllToAllvTimeDoubleDEC.cxx | 318 ++++++++++++ .../Test/test_MPI_Access_Cancel.cxx | 302 ++++++++++++ .../test_MPI_Access_Cyclic_ISend_IRecv.cxx | 251 ++++++++++ .../Test/test_MPI_Access_Cyclic_Send_Recv.cxx | 168 +++++++ .../Test/test_MPI_Access_IProbe.cxx | 149 ++++++ .../Test/test_MPI_Access_ISendRecv.cxx | 197 ++++++++ .../Test/test_MPI_Access_ISend_IRecv.cxx | 202 ++++++++ ...test_MPI_Access_ISend_IRecv_BottleNeck.cxx | 206 ++++++++ .../test_MPI_Access_ISend_IRecv_Length.cxx | 215 +++++++++ .../test_MPI_Access_ISend_IRecv_Length_1.cxx | 286 +++++++++++ src/ParaMEDMEM/Test/test_MPI_Access_Probe.cxx | 125 +++++ .../Test/test_MPI_Access_SendRecv.cxx | 161 +++++++ .../Test/test_MPI_Access_Send_Recv.cxx | 147 ++++++ .../Test/test_MPI_Access_Send_Recv_Length.cxx | 171 +++++++ src/ParaMEDMEM/Test/test_MPI_Access_Time.cxx | 271 +++++++++++ .../Test/test_MPI_Access_Time_0.cxx | 452 ++++++++++++++++++ 26 files changed, 4961 insertions(+) create mode 100644 src/ParaMEDMEM/Test/MPIAccessDECTest.cxx create mode 100644 src/ParaMEDMEM/Test/MPIAccessDECTest.hxx create mode 100644 src/ParaMEDMEM/Test/MPIAccessTest.cxx create mode 100644 src/ParaMEDMEM/Test/MPIAccessTest.hxx create mode 100644 src/ParaMEDMEM/Test/TestMPIAccess.cxx create mode 100644 src/ParaMEDMEM/Test/TestMPIAccessDEC.cxx create mode 100644 src/ParaMEDMEM/Test/test_AllToAllDEC.cxx create mode 100644 src/ParaMEDMEM/Test/test_AllToAllTimeDEC.cxx create mode 100644 src/ParaMEDMEM/Test/test_AllToAllvDEC.cxx create mode 100644 src/ParaMEDMEM/Test/test_AllToAllvTimeDEC.cxx create mode 100644 src/ParaMEDMEM/Test/test_AllToAllvTimeDoubleDEC.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_Cancel.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_Cyclic_ISend_IRecv.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_Cyclic_Send_Recv.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_IProbe.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_ISendRecv.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_BottleNeck.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_Length.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_Length_1.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_Probe.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_SendRecv.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_Send_Recv.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_Send_Recv_Length.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_Time.cxx create mode 100644 src/ParaMEDMEM/Test/test_MPI_Access_Time_0.cxx diff --git a/src/ParaMEDMEM/Test/MPIAccessDECTest.cxx b/src/ParaMEDMEM/Test/MPIAccessDECTest.cxx new file mode 100644 index 000000000..d6bd4bcc5 --- /dev/null +++ b/src/ParaMEDMEM/Test/MPIAccessDECTest.cxx @@ -0,0 +1,51 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MPIAccessDECTest.hxx" +#include + +#include "MEDMEM_STRING.hxx" + +#include +#include + +using namespace std; + + + +/*! + * Tool to remove temporary files. + * Allows automatique removal of temporary files in case of test failure. + */ +MPIAccessDECTest_TmpFilesRemover::~MPIAccessDECTest_TmpFilesRemover() +{ + set::iterator it = myTmpFiles.begin(); + for (; it != myTmpFiles.end(); it++) { + if (access((*it).data(), F_OK) == 0) + remove((*it).data()); + } + myTmpFiles.clear(); + //cout << "~MPIAccessTest_TmpFilesRemover()" << endl; +} + +bool MPIAccessDECTest_TmpFilesRemover::Register(const string theTmpFile) +{ + return (myTmpFiles.insert(theTmpFile)).second; +} diff --git a/src/ParaMEDMEM/Test/MPIAccessDECTest.hxx b/src/ParaMEDMEM/Test/MPIAccessDECTest.hxx new file mode 100644 index 000000000..135726881 --- /dev/null +++ b/src/ParaMEDMEM/Test/MPIAccessDECTest.hxx @@ -0,0 +1,103 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _MPIACCESSDECTEST_HXX_ +#define _MPIACCESSDECTEST_HXX_ + +#include + +#include +#include +#include +#include "mpi.h" + + +class MPIAccessDECTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( MPIAccessDECTest ); + CPPUNIT_TEST( test_AllToAllDECSynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllDECAsynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllvDECSynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllvDECAsynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllTimeDECSynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllTimeDECAsynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllvTimeDECSynchronousNative ) ; + CPPUNIT_TEST( test_AllToAllvTimeDECSynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllvTimeDECAsynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllvTimeDoubleDECSynchronousPointToPoint ) ; + CPPUNIT_TEST( test_AllToAllvTimeDoubleDECAsynchronousPointToPoint ) ; + CPPUNIT_TEST_SUITE_END(); + + +public: + + MPIAccessDECTest():CppUnit::TestFixture(){} + ~MPIAccessDECTest(){} + void setUp(){} + void tearDown(){} + void test_AllToAllDECSynchronousPointToPoint() ; + void test_AllToAllDECAsynchronousPointToPoint() ; + void test_AllToAllvDECSynchronousPointToPoint() ; + void test_AllToAllvDECAsynchronousPointToPoint() ; + void test_AllToAllTimeDECSynchronousPointToPoint() ; + void test_AllToAllTimeDECAsynchronousPointToPoint() ; + void test_AllToAllvTimeDECSynchronousNative() ; + void test_AllToAllvTimeDECSynchronousPointToPoint() ; + void test_AllToAllvTimeDECAsynchronousPointToPoint() ; + void test_AllToAllvTimeDoubleDECSynchronousPointToPoint() ; + void test_AllToAllvTimeDoubleDECAsynchronousPointToPoint() ; + +private: + void test_AllToAllDEC( bool Asynchronous ) ; + void test_AllToAllvDEC( bool Asynchronous ) ; + void test_AllToAllTimeDEC( bool Asynchronous ) ; + void test_AllToAllvTimeDEC( bool Asynchronous , bool UseMPINative ) ; + void test_AllToAllvTimeDoubleDEC( bool Asynchronous ) ; + }; + +// to automatically remove temporary files from disk +class MPIAccessDECTest_TmpFilesRemover +{ +public: + MPIAccessDECTest_TmpFilesRemover() {} + ~MPIAccessDECTest_TmpFilesRemover(); + bool Register(const std::string theTmpFile); + +private: + std::set myTmpFiles; +}; + +/*! + * Tool to print array to stream. + */ +template +void MPIAccessDECTest_DumpArray (std::ostream & stream, const T* array, const int length, const std::string text) +{ + stream << text << ": {"; + if (length > 0) { + stream << array[0]; + for (int i = 1; i < length; i++) { + stream << ", " << array[i]; + } + } + stream << "}" << std::endl; +}; + +#endif diff --git a/src/ParaMEDMEM/Test/MPIAccessTest.cxx b/src/ParaMEDMEM/Test/MPIAccessTest.cxx new file mode 100644 index 000000000..7482de67e --- /dev/null +++ b/src/ParaMEDMEM/Test/MPIAccessTest.cxx @@ -0,0 +1,51 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MPIAccessTest.hxx" +#include + +#include "MEDMEM_STRING.hxx" + +#include +#include + +using namespace std; + + + +/*! + * Tool to remove temporary files. + * Allows automatique removal of temporary files in case of test failure. + */ +MPIAccessTest_TmpFilesRemover::~MPIAccessTest_TmpFilesRemover() +{ + set::iterator it = myTmpFiles.begin(); + for (; it != myTmpFiles.end(); it++) { + if (access((*it).data(), F_OK) == 0) + remove((*it).data()); + } + myTmpFiles.clear(); + //cout << "~MPIAccessTest_TmpFilesRemover()" << endl; +} + +bool MPIAccessTest_TmpFilesRemover::Register(const string theTmpFile) +{ + return (myTmpFiles.insert(theTmpFile)).second; +} diff --git a/src/ParaMEDMEM/Test/MPIAccessTest.hxx b/src/ParaMEDMEM/Test/MPIAccessTest.hxx new file mode 100644 index 000000000..d146a97e3 --- /dev/null +++ b/src/ParaMEDMEM/Test/MPIAccessTest.hxx @@ -0,0 +1,106 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _MPIACCESSTEST_HXX_ +#define _MPIACCESSTEST_HXX_ + +#include + +#include +#include +#include +#include "mpi.h" + + +class MPIAccessTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( MPIAccessTest ); + CPPUNIT_TEST( test_MPI_Access_Send_Recv ) ; + CPPUNIT_TEST( test_MPI_Access_Cyclic_Send_Recv ) ; + CPPUNIT_TEST( test_MPI_Access_SendRecv ) ; + CPPUNIT_TEST( test_MPI_Access_ISend_IRecv ) ; + CPPUNIT_TEST( test_MPI_Access_Cyclic_ISend_IRecv ) ; + CPPUNIT_TEST( test_MPI_Access_ISendRecv ) ; + CPPUNIT_TEST( test_MPI_Access_Probe ) ; + CPPUNIT_TEST( test_MPI_Access_IProbe ) ; + CPPUNIT_TEST( test_MPI_Access_Cancel ) ; + CPPUNIT_TEST( test_MPI_Access_Send_Recv_Length ) ; + CPPUNIT_TEST( test_MPI_Access_ISend_IRecv_Length ) ; + CPPUNIT_TEST( test_MPI_Access_ISend_IRecv_Length_1 ) ; + CPPUNIT_TEST( test_MPI_Access_Time ) ; + CPPUNIT_TEST( test_MPI_Access_Time_0 ) ; + CPPUNIT_TEST( test_MPI_Access_ISend_IRecv_BottleNeck ) ; + CPPUNIT_TEST_SUITE_END(); + + +public: + + MPIAccessTest():CppUnit::TestFixture(){} + ~MPIAccessTest(){} + void setUp(){} + void tearDown(){} + void test_MPI_Access_Send_Recv() ; + void test_MPI_Access_Cyclic_Send_Recv() ; + void test_MPI_Access_SendRecv() ; + void test_MPI_Access_ISend_IRecv() ; + void test_MPI_Access_Cyclic_ISend_IRecv() ; + void test_MPI_Access_ISendRecv() ; + void test_MPI_Access_Probe() ; + void test_MPI_Access_IProbe() ; + void test_MPI_Access_Cancel() ; + void test_MPI_Access_Send_Recv_Length() ; + void test_MPI_Access_ISend_IRecv_Length() ; + void test_MPI_Access_ISend_IRecv_Length_1() ; + void test_MPI_Access_Time() ; + void test_MPI_Access_Time_0() ; + void test_MPI_Access_ISend_IRecv_BottleNeck() ; + +private: + }; + +// to automatically remove temporary files from disk +class MPIAccessTest_TmpFilesRemover +{ +public: + MPIAccessTest_TmpFilesRemover() {} + ~MPIAccessTest_TmpFilesRemover(); + bool Register(const std::string theTmpFile); + +private: + std::set myTmpFiles; +}; + +/*! + * Tool to print array to stream. + */ +template +void MPIAccessTest_DumpArray (std::ostream & stream, const T* array, const int length, const std::string text) +{ + stream << text << ": {"; + if (length > 0) { + stream << array[0]; + for (int i = 1; i < length; i++) { + stream << ", " << array[i]; + } + } + stream << "}" << std::endl; +}; + +#endif diff --git a/src/ParaMEDMEM/Test/TestMPIAccess.cxx b/src/ParaMEDMEM/Test/TestMPIAccess.cxx new file mode 100644 index 000000000..bd6ec65dc --- /dev/null +++ b/src/ParaMEDMEM/Test/TestMPIAccess.cxx @@ -0,0 +1,31 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// --- include all MPIAccess Test + +#include "MPIAccessTest.hxx" + +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( MPIAccessTest ); + +// --- generic Main program from KERNEL_SRC/src/Basics/Test + +#include "MPIMainTest.hxx" diff --git a/src/ParaMEDMEM/Test/TestMPIAccessDEC.cxx b/src/ParaMEDMEM/Test/TestMPIAccessDEC.cxx new file mode 100644 index 000000000..5a4db57d5 --- /dev/null +++ b/src/ParaMEDMEM/Test/TestMPIAccessDEC.cxx @@ -0,0 +1,31 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// --- include all MPIAccessDEC Test + +#include "MPIAccessDECTest.hxx" + +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( MPIAccessDECTest ); + +// --- generic Main program from KERNEL_SRC/src/Basics/Test + +#include "MPIMainTest.hxx" diff --git a/src/ParaMEDMEM/Test/test_AllToAllDEC.cxx b/src/ParaMEDMEM/Test/test_AllToAllDEC.cxx new file mode 100644 index 000000000..779ec7e99 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_AllToAllDEC.cxx @@ -0,0 +1,187 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessDECTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_AccessDEC.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessDECTest::test_AllToAllDECSynchronousPointToPoint() { + test_AllToAllDEC( false ) ; +} +void MPIAccessDECTest::test_AllToAllDECAsynchronousPointToPoint() { + test_AllToAllDEC( true ) ; +} + +static void chksts( int sts , int myrank , ParaMEDMEM::MPI_Access mpi_access ) { + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + if ( sts != MPI_SUCCESS ) { + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + ostringstream strstream ; + strstream << "===========================================================" << endl + << "test_AllToAllDEC" << myrank << " KO" << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + return ; +} + +void MPIAccessDECTest::test_AllToAllDEC( bool Asynchronous ) { + + cout << "test_AllToAllDEC" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 || size > 11 ) { + ostringstream strstream ; + strstream << "usage :" << endl + << "mpirun -np test_AllToAllDEC" << endl + << " (nbprocs >=2)" << endl + << "test must be runned with more than 1 proc and less than 12 procs" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + +// int Asynchronous = atoi(argv[1]); + + cout << "test_AllToAllDEC" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + std::set sourceprocs; + std::set targetprocs; + int i ; + for ( i = 0 ; i < size/2 ; i++ ) { + sourceprocs.insert(i); + } + for ( i = size/2 ; i < size ; i++ ) { + targetprocs.insert(i); + } + + ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ; + ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ; + +// MPI_AccessDEC * MPIAccessDEC = new MPI_AccessDEC( *sourcegroup , *targetgroup , +// NULL , Asynchronous ) ; + MPI_AccessDEC * MPIAccessDEC = new MPI_AccessDEC( *sourcegroup , *targetgroup , + Asynchronous ) ; + + MPI_Access * mpi_access = MPIAccessDEC->MPIAccess() ; + +#define maxreq 100 +#define datamsglength 10 + +// int sts ; + int sendcount = datamsglength ; + int recvcount = datamsglength ; + int * recvbuf = new int[datamsglength*size] ; + + int ireq ; + for ( ireq = 0 ; ireq < maxreq ; ireq++ ) { + int * sendbuf = new int[datamsglength*size] ; +// cout << "test_AllToAllDEC" << myrank << " ireq " << ireq << " RecvRequestIdsSize " +// << mpi_access->RecvRequestIdsSize() << endl ; +// int * sendbuf = (int *) malloc( sizeof(int)*datamsglength*size) ; + int j ; + for ( j = 0 ; j < datamsglength*size ; j++ ) { + sendbuf[j] = myrank*1000000 + ireq*1000 + j ; + recvbuf[j] = -1 ; + } + + MPIAccessDEC->AllToAll( sendbuf, sendcount , MPI_INT , + recvbuf, recvcount , MPI_INT ) ; + +// cout << "test_AllToAllDEC" << myrank << " recvbuf before CheckSent" ; +// for ( i = 0 ; i < datamsglength*size ; i++ ) { +// cout << " " << recvbuf[i] ; +// } +// cout << endl ; + +// cout << "test_AllToAllDEC" << myrank << " sendbuf " << sendbuf << endl ; + MPIAccessDEC->CheckSent() ; + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; +// cout << "test_AllToAllDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests" << endl ; + int *ArrayOfRecvRequests = new int[nRecvReq] ; + int nReq = mpi_access->RecvRequestIds( nRecvReq, ArrayOfRecvRequests ) ; + mpi_access->WaitAll( nReq , ArrayOfRecvRequests ) ; + mpi_access->DeleteRequests( nReq , ArrayOfRecvRequests ) ; + delete [] ArrayOfRecvRequests ; +// cout << "test_AllToAllDEC" << myrank << " RecvRequestIdsSize " << mpi_access->RecvRequestIdsSize() +// << " after WaitAll" << endl ; + +// cout << "test_AllToAllDEC" << myrank << " recvbuf" ; +// for ( i = 0 ; i < datamsglength*size ; i++ ) { +// cout << " " << recvbuf[i] ; +// } +// cout << endl ; + } + + cout << "test_AllToAllDEC" << myrank << " final CheckSent" << endl ; + MPIAccessDEC->CheckSent() ; + + int nSendReq = mpi_access->SendRequestIdsSize() ; + cout << "test_AllToAllDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests" + << endl ; + if ( nSendReq ) { + int *ArrayOfSendRequests = new int[nSendReq] ; + int nReq = mpi_access->SendRequestIds( nSendReq, ArrayOfSendRequests ) ; + mpi_access->WaitAll( nReq , ArrayOfSendRequests ) ; + delete [] ArrayOfSendRequests ; + } + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; + if ( nRecvReq ) { + ostringstream strstream ; + strstream << "test_AllToAllDEC" << myrank << " final RecvRequestIds " << nRecvReq + << " RecvRequests # 0 Error" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "test_AllToAllDEC" << myrank << " final RecvRequestIds " << nRecvReq + << " RecvRequests = 0 OK" << endl ; + } + + mpi_access->Barrier() ; + + delete sourcegroup ; + delete targetgroup ; + delete MPIAccessDEC ; + delete [] recvbuf ; + +// MPI_Finalize(); + + cout << "test_AllToAllDEC" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_AllToAllTimeDEC.cxx b/src/ParaMEDMEM/Test/test_AllToAllTimeDEC.cxx new file mode 100644 index 000000000..264e0dc39 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_AllToAllTimeDEC.cxx @@ -0,0 +1,246 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessDECTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_AccessDEC.hxx" +#include "LinearTimeInterpolator.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessDECTest::test_AllToAllTimeDECSynchronousPointToPoint() { + test_AllToAllTimeDEC( false ) ; +} +void MPIAccessDECTest::test_AllToAllTimeDECAsynchronousPointToPoint() { + test_AllToAllTimeDEC( true ) ; +} + +static void chksts( int sts , int myrank , ParaMEDMEM::MPI_Access * mpi_access ) { + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + if ( sts != MPI_SUCCESS ) { + mpi_access->Error_String(sts, msgerr, &lenerr) ; + cout << "test_AllToAllTimeDEC" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + ostringstream strstream ; + strstream << "===========================================================" + << "test_AllToAllTimeDEC" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + return ; +} + +void MPIAccessDECTest::test_AllToAllTimeDEC( bool Asynchronous ) { + + cout << "test_AllToAllTimeDEC" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 || size > 11 ) { + ostringstream strstream ; + strstream << "usage :" << endl + << "mpirun -np test_AllToAllTimeDEC" << endl + << " (nbprocs >=2)" << endl + << "test must be runned with more than 1 proc and less than 12 procs" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + +// int Asynchronous = atoi(argv[1]); + + cout << "test_AllToAllTimeDEC" << myrank << " Asynchronous " << Asynchronous << endl ; + + ParaMEDMEM::CommInterface interface ; + std::set sourceprocs; + std::set targetprocs; + int i ; + for ( i = 0 ; i < size/2 ; i++ ) { + sourceprocs.insert(i); + } + for ( i = size/2 ; i < size ; i++ ) { + targetprocs.insert(i); + } + + ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ; + ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ; + +// LinearTimeInterpolator * aLinearInterpDEC = new LinearTimeInterpolator( 0.5 ) ; + MPI_AccessDEC * MPIAccessDEC = new MPI_AccessDEC( *sourcegroup , *targetgroup , + Asynchronous ) ; +// Asynchronous , LinearInterp , 0.5 ) ; + MPIAccessDEC->SetTimeInterpolator( LinearTimeInterp ) ; + MPI_Access * mpi_access = MPIAccessDEC->MPIAccess() ; + + cout << "test_AllToAllTimeDEC" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + +#define maxproc 11 +#define maxreq 10000 +#define datamsglength 10 + + int sts ; + int sendcount = datamsglength ; + int recvcount = datamsglength ; + + double time = 0 ; +// double deltatime[maxproc] = {1.,2.1,3.2,4.3,5.4,6.5,7.6,8.7,9.8,10.9,11.} ; + double deltatime[maxproc] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.} ; + double maxtime = maxreq ; + double nextdeltatime = deltatime[myrank] ; +// MPIAccessDEC->InitTime( time , deltatime[myrank] , maxtime ) ; +// for ( time = 0 ; time <= maxtime ; time+=deltatime[myrank] ) { + for ( time = 0 ; time <= maxtime && nextdeltatime != 0 ; time+=nextdeltatime ) { + if ( time != 0 ) { + nextdeltatime = deltatime[myrank] ; + if ( time+nextdeltatime > maxtime ) { + nextdeltatime = 0 ; + } +// MPIAccessDEC->NextTime( nextdeltatime ) ; + } + MPIAccessDEC->SetTime( time , nextdeltatime ) ; +// cout << "test_AllToAllTimeDEC" << myrank << "=====TIME " << time << "=====DELTATIME " +// << nextdeltatime << "=====MAXTIME " << maxtime << " ======" << endl ; + int * sendbuf = new int[datamsglength*size] ; +// int * sendbuf = (int *) malloc(sizeof(int)*datamsglength*size) ; + int * recvbuf = new int[datamsglength*size] ; + int j ; + for ( j = 0 ; j < datamsglength*size ; j++ ) { + sendbuf[j] = myrank*1000000 + (j/datamsglength)*1000 + j ; + recvbuf[j] = -1 ; + } + + int sts = MPIAccessDEC->AllToAllTime( sendbuf, sendcount , MPI_INT , + recvbuf, recvcount , MPI_INT ) ; + chksts( sts , myrank , mpi_access ) ; + +// cout << "test_AllToAllTimeDEC" << myrank << " recvbuf before CheckSent" ; +// for ( i = 0 ; i < datamsglength*size ; i++ ) { +// cout << " " << recvbuf[i] ; +// } +// cout << endl ; + +// cout << "test_AllToAllTimeDEC" << myrank << " sendbuf " << sendbuf << endl ; +// MPIAccessDEC->CheckSent() ; + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; + if ( nRecvReq != 0 ) { + ostringstream strstream ; + strstream << "=============================================================" << endl + << "test_AllToAllTimeDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests # 0 ERROR" + << endl << "=============================================================" + << endl ; + int *ArrayOfRecvRequests = new int[nRecvReq] ; + int nReq = mpi_access->RecvRequestIds( nRecvReq, ArrayOfRecvRequests ) ; + mpi_access->WaitAll( nReq , ArrayOfRecvRequests ) ; + delete [] ArrayOfRecvRequests ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + +// cout << "test_AllToAllTimeDEC" << myrank << " recvbuf" << endl ; + bool badrecvbuf = false ; + for ( i = 0 ; i < datamsglength*size ; i++ ) { + if ( recvbuf[i] != (i/datamsglength)*1000000 + myrank*1000 + + myrank*datamsglength+(i%datamsglength) ) { + badrecvbuf = true ; + cout << "test_AllToAllTimeDEC" << myrank << " recvbuf[" << i << "] " + << recvbuf[i] << " # " << (i/datamsglength)*1000000 + myrank*1000 + + myrank*datamsglength+(i%datamsglength) << endl ; + } + else if ( badrecvbuf ) { + cout << "test_AllToAllTimeDEC" << myrank << " recvbuf[" << i << "] " + << recvbuf[i] << " == " << (i/datamsglength)*1000000 + myrank*1000 + + myrank*datamsglength+(i%datamsglength) << endl ; + } + } + if ( badrecvbuf ) { + ostringstream strstream ; + strstream << "==============================================================" << endl + << "test_AllToAllTimeDEC" << myrank << " badrecvbuf" + << endl << "=============================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + delete [] recvbuf ; + } + + cout << "test_AllToAllTimeDEC" << myrank << " final CheckSent" << endl ; + sts = MPIAccessDEC->CheckSent() ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "================================================================" << endl + << "test_AllToAllTimeDEC" << myrank << " final CheckSent ERROR" + << endl << "================================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + int nSendReq = mpi_access->SendRequestIdsSize() ; + cout << "test_AllToAllTimeDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests" + << endl ; + if ( nSendReq ) { + int *ArrayOfSendRequests = new int[nSendReq] ; + int nReq = mpi_access->SendRequestIds( nSendReq, ArrayOfSendRequests ) ; + mpi_access->WaitAll( nReq , ArrayOfSendRequests ) ; + delete [] ArrayOfSendRequests ; + } + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; + if ( nRecvReq ) { + ostringstream strstream ; + strstream << "===============================================================" << endl + << "test_AllToAllTimeDEC" << myrank << " RecvRequestIds " << nRecvReq + << " RecvRequests # 0 Error" + << endl << "===============================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "test_AllToAllTimeDEC" << myrank << " RecvRequestIds " << nRecvReq + << " RecvRequests = 0 OK" << endl ; + } + + cout << "test_AllToAllTimeDEC" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + + delete sourcegroup ; + delete targetgroup ; +// delete aLinearInterpDEC ; + delete MPIAccessDEC ; + +// MPI_Finalize(); + + cout << "test_AllToAllTimeDEC" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_AllToAllvDEC.cxx b/src/ParaMEDMEM/Test/test_AllToAllvDEC.cxx new file mode 100644 index 000000000..390c53459 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_AllToAllvDEC.cxx @@ -0,0 +1,193 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessDECTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_AccessDEC.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessDECTest::test_AllToAllvDECSynchronousPointToPoint() { + test_AllToAllvDEC( false ) ; +} +void MPIAccessDECTest::test_AllToAllvDECAsynchronousPointToPoint() { + test_AllToAllvDEC( true ) ; +} + +static void chksts( int sts , int myrank , ParaMEDMEM::MPI_Access mpi_access ) { + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + if ( sts != MPI_SUCCESS ) { + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test_AllToAllvDEC" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + ostringstream strstream ; + strstream << "===========================================================" + << "test_AllToAllvDEC" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + return ; +} + +void MPIAccessDECTest::test_AllToAllvDEC( bool Asynchronous ) { + + cout << "test_AllToAllvDEC" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 || size > 11 ) { + ostringstream strstream ; + strstream << "usage :" << endl + << "mpirun -np test_AllToAllvDEC" << endl + << " (nbprocs >=2)" << endl + << "test must be runned with more than 1 proc and less than 12 procs" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + +// int Asynchronous = atoi(argv[1]); + + cout << "test_AllToAllvDEC" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + std::set sourceprocs; + std::set targetprocs; + int i ; + for ( i = 0 ; i < size/2 ; i++ ) { + sourceprocs.insert(i); + } + for ( i = size/2 ; i < size ; i++ ) { + targetprocs.insert(i); + } + + ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ; + ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ; + + MPI_AccessDEC * MPIAccessDEC = new MPI_AccessDEC( *sourcegroup , *targetgroup , + Asynchronous ) ; + + MPI_Access * mpi_access = MPIAccessDEC->MPIAccess() ; + +#define maxreq 100 +#define datamsglength 10 + +// int sts ; + int *sendcounts = new int[size] ; + int *sdispls = new int[size] ; + int *recvcounts = new int[size] ; + int *rdispls = new int[size] ; + for ( i = 0 ; i < size ; i++ ) { + sendcounts[i] = datamsglength-i; + sdispls[i] = i*datamsglength ; + recvcounts[i] = datamsglength-myrank; + rdispls[i] = i*datamsglength ; + } + int * recvbuf = new int[datamsglength*size] ; + + int ireq ; + for ( ireq = 0 ; ireq < maxreq ; ireq++ ) { + int * sendbuf = new int[datamsglength*size] ; +// int * sendbuf = (int *) malloc( sizeof(int)*datamsglength*size) ; + int j ; + for ( j = 0 ; j < datamsglength*size ; j++ ) { + sendbuf[j] = myrank*1000000 + ireq*1000 + j ; + recvbuf[j] = -1 ; + } + + MPIAccessDEC->AllToAllv( sendbuf, sendcounts , sdispls , MPI_INT , + recvbuf, recvcounts , rdispls , MPI_INT ) ; + +// cout << "test_AllToAllvDEC" << myrank << " recvbuf before CheckSent" ; +// for ( i = 0 ; i < datamsglength*size ; i++ ) { +// cout << " " << recvbuf[i] ; +// } +// cout << endl ; + +// cout << "test_AllToAllvDEC" << myrank << " sendbuf " << sendbuf << endl ; + MPIAccessDEC->CheckSent() ; + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; +// cout << "test_AllToAllvDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests" << endl ; + int *ArrayOfRecvRequests = new int[nRecvReq] ; + int nReq = mpi_access->RecvRequestIds( nRecvReq, ArrayOfRecvRequests ) ; + mpi_access->WaitAll( nReq , ArrayOfRecvRequests ) ; + mpi_access->DeleteRequests( nReq , ArrayOfRecvRequests ) ; + delete [] ArrayOfRecvRequests ; + +// cout << "test_AllToAllvDEC" << myrank << " recvbuf" ; +// for ( i = 0 ; i < datamsglength*size ; i++ ) { +// cout << " " << recvbuf[i] ; +// } +// cout << endl ; + } + + cout << "test_AllToAllvDEC" << myrank << " final CheckSent" << endl ; + MPIAccessDEC->CheckSent() ; + + int nSendReq = mpi_access->SendRequestIdsSize() ; + cout << "test_AllToAllvDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests" + << endl ; + if ( nSendReq ) { + int *ArrayOfSendRequests = new int[nSendReq] ; + int nReq = mpi_access->SendRequestIds( nSendReq, ArrayOfSendRequests ) ; + mpi_access->WaitAll( nReq , ArrayOfSendRequests ) ; + delete [] ArrayOfSendRequests ; + } + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; + if ( nRecvReq ) { + ostringstream strstream ; + strstream << "test_AllToAllvDEC" << myrank << " final RecvRequestIds " << nRecvReq + << " RecvRequests # 0 Error" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "test_AllToAllvDEC" << myrank << " final RecvRequestIds " << nRecvReq + << " RecvRequests = 0 OK" << endl ; + } + + mpi_access->Barrier() ; + + delete sourcegroup ; + delete targetgroup ; + delete MPIAccessDEC ; + delete [] sendcounts ; + delete [] sdispls ; + delete [] recvcounts ; + delete [] rdispls ; + delete [] recvbuf ; + +// MPI_Finalize(); + + cout << "test_AllToAllvDEC" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_AllToAllvTimeDEC.cxx b/src/ParaMEDMEM/Test/test_AllToAllvTimeDEC.cxx new file mode 100644 index 000000000..f07c8fee4 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_AllToAllvTimeDEC.cxx @@ -0,0 +1,341 @@ +#include +#include +#include +#include +#include +#include + +#include "MPIAccessDECTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_AccessDEC.hxx" +#include "LinearTimeInterpolator.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessDECTest::test_AllToAllvTimeDECSynchronousNative() { + test_AllToAllvTimeDEC( false , true ) ; +} +void MPIAccessDECTest::test_AllToAllvTimeDECSynchronousPointToPoint() { + test_AllToAllvTimeDEC( false , false ) ; +} +void MPIAccessDECTest::test_AllToAllvTimeDECAsynchronousPointToPoint() { + test_AllToAllvTimeDEC( true , false ) ; +} + +static void chksts( int sts , int myrank , ParaMEDMEM::MPI_Access * mpi_access ) { + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + if ( sts != MPI_SUCCESS ) { + mpi_access->Error_String(sts, msgerr, &lenerr) ; + cout << "test_AllToAllvTimeDEC" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + ostringstream strstream ; + strstream << "===========================================================" + << "test_AllToAllvTimeDEC" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + return ; +} + +void MPIAccessDECTest::test_AllToAllvTimeDEC( bool Asynchronous , bool UseMPINative ) { + + cout << "test_AllToAllvTimeDEC" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 || size > 11 ) { + ostringstream strstream ; + strstream << "usage :" << endl + << "mpirun -np test_AllToAllTimeDEC" << endl + << " (nbprocs >=2)" << endl + << "test must be runned with more than 1 proc and less than 12 procs" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + +// int Asynchronous = atoi(argv[1]) ; + int UseMPI_Alltoallv = UseMPINative ; +// if ( argc == 3 ) { +// UseMPI_Alltoallv = atoi(argv[2]) ; +// } + + cout << "test_AllToAllvTimeDEC" << myrank << " Asynchronous " << Asynchronous + << " UseMPI_Alltoallv " << UseMPI_Alltoallv << endl ; + + ParaMEDMEM::CommInterface interface ; + std::set sourceprocs; + std::set targetprocs; + int i ; + for ( i = 0 ; i < size/2 ; i++ ) { + sourceprocs.insert(i); + } + for ( i = size/2 ; i < size ; i++ ) { + targetprocs.insert(i); + } + + ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ; + ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ; + +// TimeInterpolator * aLinearInterpDEC = new LinearTimeInterpolator( 0.5 ) ; + MPI_AccessDEC * MPIAccessDEC = new MPI_AccessDEC( *sourcegroup , *targetgroup , + Asynchronous ) ; +// Asynchronous , LinearInterp , 0.5 ) ; + MPIAccessDEC->SetTimeInterpolator( LinearTimeInterp , 0.5 ) ; + MPI_Access * mpi_access = MPIAccessDEC->MPIAccess() ; + + cout << "test_AllToAllvTimeDEC" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + +#define maxproc 11 +#define maxreq 1000 +#define datamsglength 10 + + int sts ; + int *sendcounts = new int[size] ; + int *sdispls = new int[size] ; + int *recvcounts = new int[size] ; + int *rdispls = new int[size] ; + int *sendtimecounts = new int[size] ; + int *stimedispls = new int[size] ; + int *recvtimecounts = new int[size] ; + int *rtimedispls = new int[size] ; + for ( i = 0 ; i < size ; i++ ) { + sendcounts[i] = datamsglength-i ; + sdispls[i] = i*datamsglength ; + recvcounts[i] = datamsglength-myrank ; + rdispls[i] = i*datamsglength ; + sendtimecounts[i] = 1 ; + stimedispls[i] = 0 ; + recvtimecounts[i] = 1 ; + rtimedispls[i] = i ; + //rtimedispls[i] = i*mpi_access->TimeExtent() ; + } + + double time = 0 ; + double deltatime[maxproc] = {1.,2.1,3.2,4.3,5.4,6.5,7.6,8.7,9.8,10.9,11.} ; + double maxtime ; + double nextdeltatime = deltatime[myrank] ; + if ( UseMPI_Alltoallv ) { + maxtime = maxreq*nextdeltatime - 0.1 ; + } + else { + maxtime = maxreq ; +// MPIAccessDEC->InitTime( time , nextdeltatime , maxtime ) ; + } + time_t begintime = std::time(NULL) ; +// for ( time = 0 ; time <= maxtime ; time+=deltatime[myrank] ) { + for ( time = 0 ; time <= maxtime && nextdeltatime != 0 ; time+=nextdeltatime ) { + nextdeltatime = deltatime[myrank] ; + if ( time != 0 ) { + nextdeltatime = deltatime[myrank] ; + if ( time+nextdeltatime > maxtime ) { + nextdeltatime = 0 ; + } +// MPIAccessDEC->NextTime( nextdeltatime ) ; + } + MPIAccessDEC->SetTime( time , nextdeltatime ) ; +// cout << "test_AllToAllvTimeDEC" << myrank << "=====TIME " << time << "=====DELTATIME " +// << nextdeltatime << "=====MAXTIME " << maxtime << " ======" << endl ; + int * sendbuf = new int[datamsglength*size] ; +// int * sendbuf = (int *) malloc(sizeof(int)*datamsglength*size) ; + int * recvbuf = new int[datamsglength*size] ; + int j ; + for ( j = 0 ; j < datamsglength*size ; j++ ) { + sendbuf[j] = myrank*1000000 + (j/datamsglength)*1000 + j ; + recvbuf[j] = -1 ; + } + + if ( UseMPI_Alltoallv ) { + const MPI_Comm* comm = MPIAccessDEC->GetComm(); + TimeMessage * aSendTimeMessage = new TimeMessage ; + aSendTimeMessage->time = time ; +// aSendTimeMessage->deltatime = deltatime[myrank] ; + aSendTimeMessage->deltatime = nextdeltatime ; +// aSendTimeMessage->maxtime = maxtime ; + aSendTimeMessage->tag = (int ) (time/deltatime[myrank]) ; + TimeMessage * aRecvTimeMessage = new TimeMessage[size] ; + interface.allToAllV(aSendTimeMessage, sendtimecounts , stimedispls , + mpi_access->TimeType() , + aRecvTimeMessage, recvtimecounts , rtimedispls , + mpi_access->TimeType() , *comm ) ; +// for ( j = 0 ; j < size ; j++ ) { +// cout << "test_AllToAllvTimeDEC" << myrank << " TimeMessage received " << j << " " +// << aRecvTimeMessage[j] << endl ; +// } + delete aSendTimeMessage ; + delete [] aRecvTimeMessage ; + interface.allToAllV(sendbuf, sendcounts , sdispls , MPI_INT , + recvbuf, recvcounts , rdispls , MPI_INT , *comm ) ; +// free(sendbuf) ; + delete [] sendbuf ; + } + else { + int sts = MPIAccessDEC->AllToAllvTime( sendbuf, sendcounts , sdispls , MPI_INT , + recvbuf, recvcounts , rdispls , MPI_INT ) ; + chksts( sts , myrank , mpi_access ) ; + } + +// cout << "test_AllToAllvTimeDEC" << myrank << " recvbuf before CheckSent" ; +// for ( i = 0 ; i < datamsglength*size ; i++ ) { +// cout << " " << recvbuf[i] ; +// } +// cout << endl ; + +// cout << "test_AllToAllvTimeDEC" << myrank << " sendbuf " << sendbuf << endl ; +// MPIAccessDEC->CheckSent() ; + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; + if ( nRecvReq != 0 ) { + ostringstream strstream ; + strstream << "=============================================================" << endl + << "test_AllToAllvTimeDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests # 0 ERROR" + << endl << "=============================================================" + << endl ; + int *ArrayOfRecvRequests = new int[nRecvReq] ; + int nReq = mpi_access->RecvRequestIds( nRecvReq, ArrayOfRecvRequests ) ; + mpi_access->WaitAll( nReq , ArrayOfRecvRequests ) ; + delete [] ArrayOfRecvRequests ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + +// cout << "test_AllToAllvTimeDEC" << myrank << " check of recvbuf" << endl ; + bool badrecvbuf = false ; + for ( i = 0 ; i < size ; i++ ) { + int j ; + for ( j = 0 ; j < datamsglength ; j++ ) { + int index = i*datamsglength+j ; + if ( j < recvcounts[i] ) { + if ( recvbuf[index] != (index/datamsglength)*1000000 + myrank*1000 + + myrank*datamsglength+(index%datamsglength) ) { + badrecvbuf = true ; + cout << "test_AllToAllvTimeDEC" << myrank << " recvbuf[" << index << "] " + << recvbuf[index] << " # " << (index/datamsglength)*1000000 + + myrank*1000 + + myrank*datamsglength+(index%datamsglength) << endl ; + } + else if ( badrecvbuf ) { + cout << "test_AllToAllvTimeDEC" << myrank << " recvbuf[" << index << "] " + << recvbuf[index] << " == " << (index/datamsglength)*1000000 + + myrank*1000 + + myrank*datamsglength+(index%datamsglength) << endl ; + } + } + else if ( recvbuf[index] != -1 ) { + badrecvbuf = true ; + cout << "test_AllToAllvTimeDEC" << myrank << " recvbuf[" << index << "] " + << recvbuf[index] << " # -1" << endl ; + } + } + } + if ( badrecvbuf ) { + ostringstream strstream ; + strstream << "==============================================================" << endl + << "test_AllToAllvTimeDEC" << myrank << " badrecvbuf" + << endl << "=============================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + delete [] recvbuf ; + } + + cout << "test_AllToAllvTimeDEC" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + + cout << "test_AllToAllvTimeDEC" << myrank << " CheckFinalSent" << endl ; + sts = MPIAccessDEC->CheckFinalSent() ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "================================================================" << endl + << "test_AllToAllvTimeDEC" << myrank << " final CheckSent ERROR" + << endl << "================================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_AllToAllvTimeDEC" << myrank << " CheckFinalRecv" << endl ; + sts = MPIAccessDEC->CheckFinalRecv() ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "================================================================" << endl + << "test_AllToAllvTimeDEC" << myrank << " CheckFinalRecv ERROR" + << endl << "================================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; + if ( nRecvReq ) { + ostringstream strstream ; + strstream << "===============================================================" << endl + << "test_AllToAllvTimeDEC" << myrank << " RecvRequestIds " << nRecvReq + << " RecvRequests # 0 Error" + << endl << "===============================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "test_AllToAllvTimeDEC" << myrank << " RecvRequestIds " << nRecvReq + << " RecvRequests = 0 OK" << endl ; + } + + time_t endtime = std::time(NULL) ; + cout << "test_AllToAllvTimeDEC" << myrank << " begintime " << begintime << " endtime " << endtime + << " elapse " << endtime-begintime << " " << maxtime/deltatime[myrank] + << " calls to AllToAll" << endl ; + + cout << "test_AllToAllvTimeDEC" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + + delete sourcegroup ; + delete targetgroup ; + delete MPIAccessDEC ; +// delete aLinearInterpDEC ; + + delete [] sendcounts ; + delete [] sdispls ; + delete [] recvcounts ; + delete [] rdispls ; + delete [] sendtimecounts ; + delete [] stimedispls ; + delete [] recvtimecounts ; + delete [] rtimedispls ; + +// MPI_Finalize(); + + endtime = std::time(NULL) ; + + cout << "test_AllToAllvTimeDEC" << myrank << " OK begintime " << begintime << " endtime " << endtime + << " elapse " << endtime-begintime << " " << maxtime/deltatime[myrank] + << " calls to AllToAll" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_AllToAllvTimeDoubleDEC.cxx b/src/ParaMEDMEM/Test/test_AllToAllvTimeDoubleDEC.cxx new file mode 100644 index 000000000..bc02a3a11 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_AllToAllvTimeDoubleDEC.cxx @@ -0,0 +1,318 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "MPIAccessDECTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_AccessDEC.hxx" +#include "LinearTimeInterpolator.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessDECTest::test_AllToAllvTimeDoubleDECSynchronousPointToPoint() { + test_AllToAllvTimeDoubleDEC( false ) ; +} +void MPIAccessDECTest::test_AllToAllvTimeDoubleDECAsynchronousPointToPoint() { + test_AllToAllvTimeDoubleDEC( true ) ; +} + +static void chksts( int sts , int myrank , ParaMEDMEM::MPI_Access * mpi_access ) { + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + if ( sts != MPI_SUCCESS ) { + mpi_access->Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + return ; +} + +void MPIAccessDECTest::test_AllToAllvTimeDoubleDEC( bool Asynchronous ) { + + cout << "test_AllToAllvTimeDoubleDEC" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 || size > 11 ) { + ostringstream strstream ; + strstream << "usage :" << endl + << "mpirun -np test_AllToAllTimeDEC" << endl + << " (nbprocs >=2)" << endl + << "test must be runned with more than 1 proc and less than 12 procs" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + +// int Asynchronous = atoi(argv[1]) ; + + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " Asynchronous " << Asynchronous << endl ; + + ParaMEDMEM::CommInterface interface ; + std::set sourceprocs; + std::set targetprocs; + int i ; + for ( i = 0 ; i < size/2 ; i++ ) { + sourceprocs.insert(i); + } + for ( i = size/2 ; i < size ; i++ ) { + targetprocs.insert(i); + } + + ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ; + ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ; + +// TimeInterpolator * aLinearInterpDEC = new LinearTimeInterpolator( 0 ) ; + MPI_AccessDEC * MPIAccessDEC = new MPI_AccessDEC( *sourcegroup , *targetgroup , + Asynchronous ) ; +// Asynchronous , LinearInterp , 0.5 ) ; + MPIAccessDEC->SetTimeInterpolator( LinearTimeInterp ) ; + MPI_Access * mpi_access = MPIAccessDEC->MPIAccess() ; + + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + +#define maxproc 11 +#define maxreq 100 +#define datamsglength 10 + + int sts ; + int *sendcounts = new int[size] ; + int *sdispls = new int[size] ; + int *recvcounts = new int[size] ; + int *rdispls = new int[size] ; + int *sendtimecounts = new int[size] ; + int *stimedispls = new int[size] ; + int *recvtimecounts = new int[size] ; + int *rtimedispls = new int[size] ; + for ( i = 0 ; i < size ; i++ ) { + sendcounts[i] = datamsglength-i ; + sdispls[i] = i*datamsglength ; + recvcounts[i] = datamsglength-myrank ; + rdispls[i] = i*datamsglength ; + sendtimecounts[i] = 1 ; + stimedispls[i] = 0 ; + recvtimecounts[i] = 1 ; + rtimedispls[i] = i ; + } + + double time[maxproc] ; + double deltatime[maxproc] = {1.,2.1,3.2,4.3,5.4,6.5,7.6,8.7,9.8,10.9,11.} ; + double maxtime[maxproc] ; + double nextdeltatime[maxproc] ; + for ( i = 0 ; i < size ; i++ ) { + time[i] = 0 ; + maxtime[i] = maxreq ; + nextdeltatime[i] = deltatime[i] ; + } + time_t begintime = std::time(NULL) ; + for ( time[myrank] = 0 ; time[myrank] <= maxtime[myrank] && nextdeltatime[myrank] != 0 ; + time[myrank]+=nextdeltatime[myrank] ) { +//local and target times + int target ; + for ( target = 0 ; target < size ; target++ ) { + nextdeltatime[target] = deltatime[target] ; + if ( time[target] != 0 ) { + if ( time[target]+nextdeltatime[target] > maxtime[target] ) { + nextdeltatime[target] = 0 ; + } + } + if ( target != myrank ) { + while ( time[myrank] >= time[target] ) { + time[target] += deltatime[target] ; + } + } + } + MPIAccessDEC->SetTime( time[myrank] , nextdeltatime[myrank] ) ; + cout << "test" << myrank << "=====TIME " << time[myrank] << "=====DELTATIME " + << nextdeltatime[myrank] << "=====MAXTIME " << maxtime[myrank] << " ======" + << endl ; + double * sendbuf = new double[datamsglength*size] ; +// double * sendbuf = (double *) malloc(sizeof(double)*datamsglength*size) ; + double * recvbuf = new double[datamsglength*size] ; + int j ; + //cout << "test_AllToAllvTimeDoubleDEC" << myrank << " sendbuf" ; + for ( target = 0 ; target < size ; target++ ) { + for ( j = 0 ; j < datamsglength ; j++ ) { + //sendbuf[j] = myrank*10000 + (j/datamsglength)*100 + j ; + sendbuf[target*datamsglength+j] = myrank*1000000 + target*10000 + + (time[myrank]/deltatime[myrank])*100 + j ; + //cout << " " << (int ) sendbuf[target*datamsglength+j] ; + recvbuf[target*datamsglength+j] = -1 ; + } + //cout << endl ; + } + + int sts = MPIAccessDEC->AllToAllvTime( sendbuf, sendcounts , sdispls , MPI_DOUBLE , + recvbuf, recvcounts , rdispls , MPI_DOUBLE ) ; + chksts( sts , myrank , mpi_access ) ; + +// cout << "test_AllToAllvTimeDoubleDEC" << myrank << " recvbuf before CheckSent" ; +// for ( i = 0 ; i < datamsglength*size ; i++ ) { +// cout << " " << recvbuf[i] ; +// } +// cout << endl ; + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; + if ( nRecvReq != 0 ) { + ostringstream strstream ; + strstream << "=============================================================" << endl + << "test_AllToAllvTimeDoubleDEC" << myrank << " WaitAllRecv " + << nRecvReq << " Requests # 0 ERROR" + << endl << "============================================================" + << endl ; + int *ArrayOfRecvRequests = new int[nRecvReq] ; + int nReq = mpi_access->RecvRequestIds( nRecvReq, ArrayOfRecvRequests ) ; + mpi_access->WaitAll( nReq , ArrayOfRecvRequests ) ; + delete [] ArrayOfRecvRequests ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " check of recvbuf" << endl ; + bool badrecvbuf = false ; + for ( target = 0 ; target < size ; target++ ) { + int j ; + for ( j = 0 ; j < datamsglength ; j++ ) { + int index = target*datamsglength+j ; + if ( j < recvcounts[target] ) { + if ( fabs(recvbuf[index] - (target*1000000 + myrank*10000 + + (time[target]/deltatime[target])*100 + j)) > 101) { + badrecvbuf = true ; + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " target " << target << " time[target] " + << time[target] << " recvbuf[" << index << "] " << (int ) recvbuf[index] + << " # " << (int ) (target*1000000 + + myrank*10000 + (time[target]/deltatime[target])*100 + j) + << endl ; + } + else if ( badrecvbuf ) { + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " recvbuf[" << index << "] " + << recvbuf[index] << " ~= " << (int ) (target*1000000 + + myrank*10000 + (time[target]/deltatime[target])*100 + j) << endl ; + } + } + else if ( recvbuf[index] != -1 ) { + badrecvbuf = true ; + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " recvbuf[" << index << "] " + << recvbuf[index] << " # -1" << endl ; + } + } + } + if ( badrecvbuf ) { + ostringstream strstream ; + strstream << "==================================================================" << endl + << "test_AllToAllvTimeDoubleDEC" << myrank << " badrecvbuf" + << endl << "==================================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + delete [] recvbuf ; + } + + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " CheckFinalSent" << endl ; + sts = MPIAccessDEC->CheckFinalSent() ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "=================================================================" << endl + << "test_AllToAllvTimeDoubleDEC" << myrank << " CheckFinalSent ERROR" + << endl << "=================================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " CheckFinalRecv" << endl ; + sts = MPIAccessDEC->CheckFinalRecv() ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "=================================================================" << endl + << "test_AllToAllvTimeDoubleDEC" << myrank << " CheckFinalRecv ERROR" + << endl << "================================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + int nRecvReq = mpi_access->RecvRequestIdsSize() ; + if ( nRecvReq ) { + ostringstream strstream ; + strstream << "===============================================================" << endl + << "test_AllToAllvTimeDoubleDEC" << myrank << " RecvRequestIds " << nRecvReq + << " RecvRequests # 0 Error" + << endl << "===============================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " RecvRequestIds " << nRecvReq + << " RecvRequests = 0 OK" << endl ; + } + + time_t endtime = std::time(NULL) ; + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " begintime " << begintime << " endtime " << endtime + << " elapse " << endtime-begintime << " " << maxtime[myrank]/deltatime[myrank] + << " calls to AllToAll" << endl ; + + cout << "test" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + + delete sourcegroup ; + delete targetgroup ; + delete MPIAccessDEC ; +// delete aLinearInterpDEC ; + + delete [] sendcounts ; + delete [] sdispls ; + delete [] recvcounts ; + delete [] rdispls ; + delete [] sendtimecounts ; + delete [] stimedispls ; + delete [] recvtimecounts ; + delete [] rtimedispls ; + +// MPI_Finalize(); + + endtime = std::time(NULL) ; + + cout << "test_AllToAllvTimeDoubleDEC" << myrank << " OK begintime " << begintime << " endtime " << endtime + << " elapse " << endtime-begintime << " " << maxtime[myrank]/deltatime[myrank] + << " calls to AllToAll" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_Cancel.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_Cancel.cxx new file mode 100644 index 000000000..3e45057fa --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_Cancel.cxx @@ -0,0 +1,302 @@ +#include +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_Cancel() { + + cout << "test_MPI_Access_Cancel" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + ostringstream strstream ; + strstream << "test_MPI_Access_Cancel must be runned with 2 procs" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_MPI_Access_Cancel" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int intsendbuf[5] ; + double doublesendbuf[10] ; + int RequestId[10] ; + int sts ; + int i , j ; + for ( j = 0 ; j < 3 ; j++ ) { + for ( i = 0 ; i < 10 ; i++ ) { + cout << "test" << myrank << " ============================ i " << i + << "============================" << endl ; + if ( myrank == 0 ) { + if ( i < 5 ) { + intsendbuf[i] = i ; + sts = mpi_access.ISend(&intsendbuf[i],1,MPI_INT,target, RequestId[i]) ; + cout << "test" << myrank << " Send MPI_INT RequestId " << RequestId[i] + << endl ; + } + else { + doublesendbuf[i] = i ; + sts = mpi_access.ISend(&doublesendbuf[i],1,MPI_DOUBLE,target, + RequestId[i]) ; + cout << "test" << myrank << " Send MPI_DOUBLE RequestId " << RequestId[i] + << endl ; + } + } + else { + int flag = false ; + while ( !flag ) { + int source, tag, outcount ; + MPI_Datatype datatype ; + sts = mpi_access.IProbe(target, source, tag, datatype, outcount, + flag ) ; + if ( flag ) { + cout << "test" << myrank << " " << i << " IProbe target " << target + << " source " << source << " tag " << tag + << " outcount " << outcount << " flag " << flag << endl ; + } + else { + cout << "test" << myrank << " flag " << flag << endl ; + sleep( 1 ) ; + } + if ( flag ) { + int recvbuf ; + sts = mpi_access.IRecv(&recvbuf,outcount,MPI_INT,source, + RequestId[i] ) ; + if ( datatype == MPI_INT ) { + int source, tag, error, outcount ; + mpi_access.Wait( RequestId[i] ) ; + mpi_access.Status( RequestId[i], source, tag, error, outcount, + true ) ; + if ( (outcount != 1) | (recvbuf != i) ) { + ostringstream strstream ; + strstream << "======================================================" + << endl << "test" << myrank << " outcount " << outcount + << " recvbuf " << recvbuf << " KO" << endl + << "======================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + cout << "========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " recvbuf " << recvbuf << " OK" << endl + << "========================================================" + << endl ; + } + } + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + } + + if ( myrank != 0 ) { + int iprobe ; + for ( iprobe = 5 ; iprobe < 10 ; iprobe++ ) { + cout << "test" << myrank << " ============================ iprobe " + << iprobe << "============================" << endl ; + int source, tag, outcount ; + MPI_Datatype datatype ; + int probeflag = false ; + while ( !probeflag ) { + sts = mpi_access.IProbe( target, source, tag, datatype, outcount, + probeflag ) ; + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " IProbe iprobe " << iprobe + << " target " << target << " probeflag " << probeflag + << " tag " << tag << " outcount " << outcount << " datatype " + << datatype << " lenerr " << lenerr << " " << msgerr << endl ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "==========================================================" + << endl << "test" << myrank << " IProbe KO iprobe " << iprobe + << endl + << "==========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + if ( !probeflag ) { + //cout << "========================================================" + // << endl << "test" << myrank << " IProbe KO(OK) iprobe " << iprobe + // << " probeflag " << probeflag << endl + // << "========================================================" + // << endl ; + } + else { + cout << "test" << myrank << " " << iprobe << " IProbe target " + << target << " source " << source << " tag " << tag + << " outcount " << outcount << " probeflag " << probeflag + << endl ; + if ( datatype != MPI_DOUBLE ) { + ostringstream strstream ; + strstream << "========================================================" + << endl << "test" << myrank << " MPI_DOUBLE KO" << endl + << "========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + int flag ; + sts = mpi_access.Cancel( source, tag, datatype, outcount, flag ) ; + if ( sts != MPI_SUCCESS || !flag ) { + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "======================================================" + << endl << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl << "test" << myrank + << " Cancel PendingIrecv KO flag " << flag << " iprobe " + << iprobe << " Irecv completed" << endl + << "======================================================" + << endl ; + //return 1 ; + } + else { + cout << "======================================================" + << endl << "test" << myrank + << " Cancel PendingIrecv OK RequestId " << " flag " + << flag << " iprobe " << iprobe << endl + << "======================================================" + << endl ; + } + } + int Reqtarget, Reqtag, Reqerror, Reqoutcount ; + mpi_access.Status( RequestId[iprobe], Reqtarget, Reqtag, Reqerror, + Reqoutcount, true ) ; + cout << "test" << myrank << " Status Reqtarget "<< Reqtarget + << " Reqtag " << Reqtag << " Reqoutcount " << Reqoutcount + << endl ; + int Reqflag ; + sts = mpi_access.Cancel( RequestId[iprobe] , Reqflag ) ; + cout << "test" << myrank << " " << iprobe + << " Cancel Irecv done Reqtarget " << Reqtarget + << " Reqtag " << Reqtag << " Reqoutcount " << Reqoutcount + << " Reqflag " << Reqflag << endl ; + if ( sts != MPI_SUCCESS || !Reqflag ) { + mpi_access.Error_String(sts, msgerr, &lenerr) ; + ostringstream strstream ; + strstream << "========================================================" + << endl << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl << "test" << myrank + << " Cancel Irecv KO Reqflag " << Reqflag << " iprobe " + << iprobe << endl + << "========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "========================================================" + << endl << "test" << myrank + << " Cancel Irecv OK RequestId " << RequestId[iprobe] + << " Reqflag " << Reqflag << " iprobe " << iprobe << endl + << "========================================================" + << endl ; + probeflag = Reqflag ; + } + } + } + } + } + mpi_access.WaitAll(10,RequestId) ; + mpi_access.DeleteRequests(10,RequestId) ; + } + + int source, tag, outcount, flag ; + MPI_Datatype datatype ; + sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ; + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + if ( sts != MPI_SUCCESS || flag ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " IProbe KO flag " << flag + << " remaining unread/cancelled message :" << endl + << " source " << source << " tag " << tag << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + mpi_access.TestAll(10,RequestId,flag) ; + mpi_access.WaitAll(10,RequestId) ; + mpi_access.DeleteRequests(10,RequestId) ; + mpi_access.TestAll(10,RequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_Cyclic_ISend_IRecv.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_Cyclic_ISend_IRecv.cxx new file mode 100644 index 000000000..681feab68 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_Cyclic_ISend_IRecv.cxx @@ -0,0 +1,251 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_Cyclic_ISend_IRecv() { + + cout << "test_MPI_Access_Cyclic_ISend_IRecv" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 3 ) { + cout << "test_MPI_Access_Cyclic_ISend_IRecv must be runned with 3 procs" << endl ; + CPPUNIT_FAIL("test_MPI_Access_Cyclic_ISend_IRecv must be runned with 3 procs") ; + } + + cout << "test_MPI_Access_Cyclic_ISend_IRecv" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + +#define maxsend 100 + + if ( myrank >= 3 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int alltarget[3] = {1 , 2 , 0 } ; + int allsource[3] = {2 , 0 , 1 } ; + int SendRequestId[maxsend] ; + int RecvRequestId[maxsend] ; + int sendbuf[maxsend] ; + int recvbuf[maxsend] ; + int sts ; + int i = 0 ; + if ( myrank == 0 ) { + sendbuf[i] = i ; + sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,alltarget[myrank], + SendRequestId[i]) ; + cout << "test" << myrank << " Send RequestId " << SendRequestId[i] + << " tag " << mpi_access.SendMPITag(alltarget[myrank]) << endl ; + } + for ( i = 0 ; i < maxsend ; i++ ) { + recvbuf[i] = -1 ; + sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,allsource[myrank], + RecvRequestId[i]) ; + cout << "test" << myrank << " Recv RequestId " << RecvRequestId[i] + << " tag " << mpi_access.RecvMPITag(allsource[myrank]) << endl ; + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr + << " " << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + int j ; + for (j = 0 ; j <= i ; j++) { + int flag ; + if ( j < i ) { + cout << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j] + << ")" << endl ; + mpi_access.Test( SendRequestId[j], flag ) ; + if ( flag ) { + int target, tag, error, outcount ; + mpi_access.Status( SendRequestId[j], target, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Send RequestId " << SendRequestId[j] + << " target " << target << " tag " << tag << " error " << error + << endl ; + mpi_access.DeleteRequest( SendRequestId[j] ) ; + } + } + cout << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j] + << ")" << endl ; + mpi_access.Test( RecvRequestId[j], flag ) ; + if ( flag ) { + int source, tag, error, outcount ; + mpi_access.Status( RecvRequestId[j], source, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Recv RequestId" << j << " " + << RecvRequestId[j] << " source " << source << " tag " << tag + << " error " << error << " outcount " << outcount << endl ; + if ( (outcount != 1) | (recvbuf[j] != j) ) { + ostringstream strstream ; + strstream << "=====================================================" + << endl << "test" << myrank << " outcount " + << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO" + << endl << "=====================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + } + if ( myrank == 0 ) { + if ( i != maxsend-1 ) { + sendbuf[i+1] = i + 1 ; + sts = mpi_access.ISend(&sendbuf[i+1],1,MPI_INT,alltarget[myrank], + SendRequestId[i+1]) ; + cout << "test" << myrank << " Send RequestId " << SendRequestId[i+1] + << " tag " << mpi_access.SendMPITag(alltarget[myrank]) << endl ; + } + } + else { + sendbuf[i] = i ; + sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,alltarget[myrank], + SendRequestId[i]) ; + cout << "test" << myrank << " Send RequestId " << SendRequestId[i] + << " tag " << mpi_access.SendMPITag(alltarget[myrank]) << endl ; + } + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr + << " " << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + } + + int flag ; + mpi_access.TestAll(maxsend,SendRequestId,flag) ; + mpi_access.TestAll(maxsend,RecvRequestId,flag) ; + mpi_access.WaitAll(maxsend,SendRequestId) ; + mpi_access.DeleteRequests(maxsend,SendRequestId) ; + mpi_access.WaitAll(maxsend,RecvRequestId) ; + mpi_access.DeleteRequests(maxsend,RecvRequestId) ; + mpi_access.Check() ; + mpi_access.TestAll(maxsend,SendRequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " TestAllSendflag " << flag << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " TestAllSendflag " << flag << " OK" << endl + << "=========================================================" << endl ; + } + mpi_access.TestAll(maxsend,RecvRequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " TestAllRecvflag " << flag << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " TestAllRecvflag " << flag << " OK" << endl + << "=========================================================" << endl ; + } + + int sendrequests[maxsend] ; + int sendreqsize = mpi_access.SendRequestIds( alltarget[myrank] , maxsend , + sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + int source, tag, error, outcount ; + mpi_access.Status(sendrequests[0], source, tag, error, outcount, true) ; + cout << "test" << myrank << " RequestId " << sendrequests[0] + << " source " << source << " tag " << tag << " error " << error + << " outcount " << outcount << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl + << "=========================================================" << endl ; + } + int recvrequests[maxsend] ; + int recvreqsize = mpi_access.SendRequestIds( allsource[myrank] , maxsend , + recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl + << "=========================================================" << endl ; + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_Cyclic_Send_Recv.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_Cyclic_Send_Recv.cxx new file mode 100644 index 000000000..a2a6a459c --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_Cyclic_Send_Recv.cxx @@ -0,0 +1,168 @@ +#include +#include +#include +#include +#include +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_Cyclic_Send_Recv() { + + cout << "test_MPI_Access_Cyclic_Send_Recv" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 3 ) { + cout << "test_MPI_Access_Send_Recv must be runned with 3 procs" << endl ; + CPPUNIT_FAIL("test_MPI_Access_Send_Recv must be runned with 3 procs") ; + } + + cout << "test_MPI_Access_Cyclic_Send_Recv" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + + if ( myrank >= 3 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int alltarget[3] = {1 , 2 , 0 } ; + int allsource[3] = {2 , 0 , 1 } ; + int RequestId[10] ; + int sts ; + int i = 0 ; + if ( myrank == 0 ) { + sts = mpi_access.Send(&i,1,MPI_INT,alltarget[myrank], RequestId[i]) ; + cout << "test" << myrank << " Send RequestId " << RequestId[i] + << " tag " << mpi_access.SendMPITag(alltarget[myrank]) << endl ; + } + for ( i = 0 ; i < 10 ; i++ ) { + int recvbuf ; + int outcount ; + if ( i & 1 ) { + outcount = 0 ; + sts = mpi_access.Recv(&recvbuf,1,MPI_INT,allsource[myrank], RequestId[i], + &outcount) ; + } + else { + sts = mpi_access.Recv(&recvbuf,1,MPI_INT,allsource[myrank], RequestId[i]) ; + outcount = 1 ; + } + //int source, tag, error, outcount ; + //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ; + cout << "test" << myrank << " Recv RequestId " << RequestId[i] + << " tag " << mpi_access.RecvMPITag(allsource[myrank]) + << " outcount " << outcount << endl ; + if ( (outcount != 1) | (recvbuf != i) ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " outcount " + << outcount << " recvbuf " << recvbuf << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + if ( myrank == 0 ) { + if ( i != 9 ) { + int ii = i + 1 ; + sts = mpi_access.Send(&ii,1,MPI_INT,alltarget[myrank], RequestId[i]) ; + cout << "test" << myrank << " Send RequestId " << RequestId[i] + << " tag " << mpi_access.SendMPITag(alltarget[myrank]) << endl ; + } + } + else { + sts = mpi_access.Send(&i,1,MPI_INT,alltarget[myrank], RequestId[i]) ; + cout << "test" << myrank << " Send RequestId " << RequestId[i] + << " tag " << mpi_access.SendMPITag(alltarget[myrank]) << endl ; + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr + << " " << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + } + + int flag ; + mpi_access.TestAll(10,RequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.WaitAll(10,RequestId) ; + mpi_access.Check() ; + + int sendrequests[10] ; + int sendreqsize = mpi_access.SendRequestIds( alltarget[myrank] , 10 , + sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + int recvrequests[10] ; + int recvreqsize = mpi_access.SendRequestIds( allsource[myrank] , 10 , + recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_IProbe.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_IProbe.cxx new file mode 100644 index 000000000..52f6e1523 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_IProbe.cxx @@ -0,0 +1,149 @@ +#include +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_IProbe() { + + cout << "test_MPI_Access_IProbe" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + ostringstream strstream ; + strstream << "test_MPI_Access_IProbe must be runned with 2 procs" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_MPI_Access_IProbe" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int sendbuf[10] ; + int RequestId[10] ; + int sts ; + int i ; + for ( i = 0 ; i < 10 ; i++ ) { + if ( myrank == 0 ) { + sendbuf[i] = i ; + sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, RequestId[i]) ; + cout << "test" << myrank << " Send RequestId " << RequestId[i] + << endl ; + } + else { + int flag = false ; + while ( !flag ) { + int source, tag, outcount ; + MPI_Datatype datatype ; + sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ; + if ( flag ) { + cout << "test" << myrank << " " << i << " IProbe target " << target + << " source " << source << " tag " << tag + << " outcount " << outcount << " flag " << flag << endl ; + } + else { + cout << "test" << myrank << " IProbe flag " << flag << endl ; + sleep( 1 ) ; + } + if ( flag ) { + int recvbuf ; + sts = mpi_access.Recv(&recvbuf,outcount,datatype,source, RequestId[i], + &outcount) ; + if ( (outcount != 1) | (recvbuf != i) ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " recvbuf " << recvbuf << " KO" << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + cout << "===========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " recvbuf " << recvbuf << " OK" << endl + << "===========================================================" + << endl ; + } + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + } + int flag ; + mpi_access.TestAll(10,RequestId,flag) ; + mpi_access.WaitAll(10,RequestId) ; + mpi_access.DeleteRequests(10,RequestId) ; + mpi_access.TestAll(10,RequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_ISendRecv.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_ISendRecv.cxx new file mode 100644 index 000000000..ca4da60e4 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_ISendRecv.cxx @@ -0,0 +1,197 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_ISendRecv() { + + cout << "test_MPI_Access_ISendRecv" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + cout << "test_MPI_Access_ISendRecv must be runned with 2 procs" << endl ; + CPPUNIT_FAIL("test_MPI_Access_ISendRecv must be runned with 2 procs") ; + } + + cout << "test_MPI_Access_ISendRecv" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int SendRequestId[10] ; + int RecvRequestId[10] ; + int sendbuf[10] ; + int recvbuf[10] ; + int sts ; + int i ; + for ( i = 0 ; i < 10 ; i++ ) { + sendbuf[i] = i ; + sts = mpi_access.ISendRecv(&sendbuf[i],1,MPI_INT,target, SendRequestId[i], + &recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ; + cout << "test" << myrank << " Send sendRequestId " << SendRequestId[i] + << " tag " << mpi_access.SendMPITag(target) + << " recvRequestId " << RecvRequestId[i] + << " tag " << mpi_access.RecvMPITag(target) << endl ; + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr + << " " << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + int j ; + for (j = 0 ; j <= i ; j++) { + int flag ; + if ( j < i ) { + cout << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j] + << ")" << endl ; + mpi_access.Test( SendRequestId[j], flag ) ; + if ( flag ) { + int target, tag, error, outcount ; + mpi_access.Status( SendRequestId[j], target, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Send RequestId " << SendRequestId[j] + << " target " << target << " tag " << tag << " error " << error + << endl ; + mpi_access.DeleteRequest( SendRequestId[j] ) ; + } + } + cout << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j] + << ")" << endl ; + mpi_access.Test( RecvRequestId[j], flag ) ; + if ( flag ) { + int source, tag, error, outcount ; + mpi_access.Status( RecvRequestId[j], source, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Recv RequestId" << j << " " + << RecvRequestId[j] << " source " << source << " tag " << tag + << " error " << error << " outcount " << outcount << endl ; + if ( (outcount != 1) | (recvbuf[j] != j) ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " outcount " + << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + } + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + mpi_access.Check() ; + } + + int flag ; + mpi_access.TestAll(10,SendRequestId,flag) ; + mpi_access.WaitAll(10,SendRequestId) ; + mpi_access.DeleteRequests(10,SendRequestId) ; + mpi_access.TestAll(10,SendRequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + mpi_access.TestAll(10,RecvRequestId,flag) ; + mpi_access.WaitAll(10,RecvRequestId) ; + mpi_access.DeleteRequests(10,RecvRequestId) ; + mpi_access.TestAll(10,RecvRequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + + int sendrequests[10] ; + int sendreqsize = mpi_access.SendRequestIds( target , 10 , sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl + << "=========================================================" << endl ; + } + int recvrequests[10] ; + int recvreqsize = mpi_access.SendRequestIds( target , 10 , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl + << "=========================================================" << endl ; + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv.cxx new file mode 100644 index 000000000..2338224cc --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv.cxx @@ -0,0 +1,202 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_ISend_IRecv() { + + cout << "test_MPI_Access_ISend_IRecv" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + cout << "test_MPI_Access_ISend_IRecv must be runned with 2 procs" << endl ; + CPPUNIT_FAIL("test_MPI_Access_ISend_IRecv must be runned with 2 procs") ; + } + + cout << "test_MPI_Access_ISend_IRecv" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + +#define maxreq 100 + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int SendRequestId[maxreq] ; + int RecvRequestId[maxreq] ; + int sts ; + int sendbuf[maxreq] ; + int recvbuf[maxreq] ; + int i ; + for ( i = 0 ; i < maxreq ; i++ ) { + if ( myrank == 0 ) { + sendbuf[i] = i ; + sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, SendRequestId[i]) ; + cout << "test" << myrank << " ISend RequestId " << SendRequestId[i] + << " tag " << mpi_access.SendMPITag(target) << endl ; + } + else { + sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ; + cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i] + << " tag " << mpi_access.RecvMPITag(target) << endl ; + } + int j ; + for (j = 0 ; j <= i ; j++) { + int flag ; + if ( myrank == 0 ) { + mpi_access.Test( SendRequestId[j], flag ) ; + } + else { + mpi_access.Test( RecvRequestId[j], flag ) ; + } + if ( flag ) { + int target,source, tag, error, outcount ; + if ( myrank == 0 ) { + mpi_access.Status( SendRequestId[j], target, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j] + << ") : target " << target << " tag " << tag << " error " << error + << " flag " << flag << endl ; + } + else { + mpi_access.Status( RecvRequestId[j], source, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Recv RequestId " + << RecvRequestId[j] << ") : source " << source << " tag " << tag + << " error " << error << " outcount " << outcount + << " flag " << flag << endl ; + if ( (outcount != 1) | (recvbuf[j] != j) ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " outcount " + << outcount << " recvbuf " << recvbuf[j] << " KO" << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + //else { + // cout << "===========================================================" + // << endl << "test" << myrank << " outcount " << outcount + // << " RequestId " << RecvRequestId[j] << " recvbuf " + // << recvbuf[j] << " OK" << endl + // << "===========================================================" + // << endl ; + //} + } + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + + mpi_access.Check() ; + if ( myrank == 0 ) { + mpi_access.WaitAll(maxreq, SendRequestId) ; + mpi_access.DeleteRequests(maxreq, SendRequestId) ; + } + else { + mpi_access.WaitAll(maxreq, RecvRequestId) ; + mpi_access.DeleteRequests(maxreq, RecvRequestId) ; + } + mpi_access.Check() ; + + if ( myrank == 0 ) { + int sendrequests[maxreq] ; + int sendreqsize = mpi_access.SendRequestIds( target , maxreq , sendrequests ) ; + int i ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + for ( i = 0 ; i < sendreqsize ; i++ ) { + cout << "test" << myrank << " sendrequests[ " << i << " ] = " + << sendrequests[i] << endl ; + } + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + else { + int recvrequests[maxreq] ; + int recvreqsize = mpi_access.SendRequestIds( target , maxreq , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_BottleNeck.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_BottleNeck.cxx new file mode 100644 index 000000000..aeee9b600 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_BottleNeck.cxx @@ -0,0 +1,206 @@ +#include +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_ISend_IRecv_BottleNeck() { + + cout << "test_MPI_Access_ISend_IRecv_BottleNeck" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + ostringstream strstream ; + strstream << "test_MPI_Access_ISend_IRecv_BottleNeck must be runned with 2 procs" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_MPI_Access_ISend_IRecv_BottleNeck" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + +#define maxreq 10000 + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int SendRequestId[maxreq] ; + int RecvRequestId[maxreq] ; + int sts ; + int sendbuf[maxreq] ; + int recvbuf[maxreq] ; + int i ; + for ( i = 0 ; i < maxreq ; i++ ) { + if ( myrank == 0 ) { + sendbuf[i] = i ; + sts = mpi_access.ISend(sendbuf,i,MPI_INT,target, SendRequestId[i]) ; + cout << "test" << myrank << " ISend RequestId " << SendRequestId[i] + << " tag " << mpi_access.SendMPITag(target) << endl ; + } + else { + //sleep( 1 ) ; + sts = mpi_access.IRecv(recvbuf,i,MPI_INT,target, RecvRequestId[i]) ; + cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i] + << " tag " << mpi_access.RecvMPITag(target) << endl ; + int recvreqsize = mpi_access.RecvRequestIdsSize() ; + int * recvrequests = new int[ recvreqsize ] ; + recvreqsize = mpi_access.RecvRequestIds( target , recvreqsize , recvrequests ) ; + int j ; + for (j = 0 ; j < recvreqsize ; j++) { + int flag ; + mpi_access.Test( recvrequests[j], flag ) ; + if ( flag ) { + int source, tag, error, outcount ; + mpi_access.Status( recvrequests[j], source, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Recv RequestId " + << recvrequests[j] << ") : source " << source << " tag " << tag + << " error " << error << " outcount " << outcount + << " flag " << flag << " : DeleteRequest" << endl ; + mpi_access.DeleteRequest( recvrequests[j] ) ; + } + else { +// cout << "test" << myrank << " Test(Recv RequestId " +// << recvrequests[j] << ") flag " << flag << endl ; + } + } + delete [] recvrequests ; + } + if ( sts != MPI_SUCCESS ) { + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + } + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + + mpi_access.Check() ; + if ( myrank == 0 ) { + int size = mpi_access.SendRequestIdsSize() ; + cout << "test" << myrank << " before WaitAll sendreqsize " << size << endl ; + mpi_access.WaitAll(maxreq, SendRequestId) ; + size = mpi_access.SendRequestIdsSize() ; + cout << "test" << myrank << " after WaitAll sendreqsize " << size << endl ; + int * ArrayOfSendRequests = new int[ size ] ; + int nSendRequest = mpi_access.SendRequestIds( size , ArrayOfSendRequests ) ; + int i ; + for ( i = 0 ; i < nSendRequest ; i++ ) { + mpi_access.DeleteRequest( ArrayOfSendRequests[i] ) ; + } + delete [] ArrayOfSendRequests ; + } + else { + int size = mpi_access.RecvRequestIdsSize() ; + cout << "test" << myrank << " before WaitAll recvreqsize " << size << endl ; + mpi_access.WaitAll(maxreq, RecvRequestId) ; + size = mpi_access.RecvRequestIdsSize() ; + cout << "test" << myrank << " after WaitAll recvreqsize " << size << endl ; + int * ArrayOfRecvRequests = new int[ size ] ; + int nRecvRequest = mpi_access.RecvRequestIds( size , ArrayOfRecvRequests ) ; + int i ; + for ( i = 0 ; i < nRecvRequest ; i++ ) { + mpi_access.DeleteRequest( ArrayOfRecvRequests[i] ) ; + } + delete [] ArrayOfRecvRequests ; + } + mpi_access.Check() ; + + if ( myrank == 0 ) { + int sendrequests[maxreq] ; + int sendreqsize = mpi_access.SendRequestIds( target , maxreq , sendrequests ) ; + int i ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + for ( i = 0 ; i < sendreqsize ; i++ ) { + cout << "test" << myrank << " sendrequests[ " << i << " ] = " + << sendrequests[i] << endl ; + } + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + else { + int recvrequests[maxreq] ; + int recvreqsize = mpi_access.RecvRequestIds( target , maxreq , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_Length.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_Length.cxx new file mode 100644 index 000000000..eefef4c9f --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_Length.cxx @@ -0,0 +1,215 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_ISend_IRecv_Length() { + + cout << "test_MPI_Access_ISend_IRecv_Length" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + ostringstream strstream ; + strstream << "test_MPI_Access_ISend_IRecv_Length must be runned with 2 procs" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_MPI_Access_ISend_IRecv_Length" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + +#define maxreq 10 + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int SendRequestId[maxreq] ; + int RecvRequestId[maxreq] ; + int sts ; + int sendbuf[1000*(maxreq-1)] ; + int recvbuf[maxreq-1][1000*(maxreq-1)] ; + int i ; + for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) { + sendbuf[i] = i ; + } + for ( i = 0 ; i < maxreq ; i++ ) { + if ( myrank == 0 ) { + sts = mpi_access.ISend( sendbuf, 1000*i, MPI_INT, target, SendRequestId[i] ) ; + cout << "test" << myrank << " ISend RequestId " << SendRequestId[i] + << " tag " << mpi_access.SendMPITag(target) << endl ; + } + else { + sts = mpi_access.IRecv( recvbuf[i], 1000*i, MPI_INT, target, + RecvRequestId[i] ) ; + cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i] + << " tag " << mpi_access.RecvMPITag(target) << endl ; + } + int j ; + for (j = 0 ; j <= i ; j++) { + int flag ; + if ( myrank == 0 ) { + mpi_access.Test( SendRequestId[j], flag ) ; + } + else { + mpi_access.Test( RecvRequestId[j], flag ) ; + } + if ( flag ) { + int target,source, tag, error, outcount ; + if ( myrank == 0 ) { + mpi_access.Status( SendRequestId[j], target, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j] + << ") : target " << target << " tag " << tag << " error " << error + << " flag " << flag << endl ; + } + else { + mpi_access.Status( RecvRequestId[j], source, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Recv RequestId " + << RecvRequestId[j] << ") : source " << source << " tag " << tag + << " error " << error << " outcount " << outcount + << " flag " << flag << endl ; + if ( outcount != 0 ) { + if ( (outcount != 1000*j) | + (recvbuf[j][outcount-1] != (outcount-1)) ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " outcount " + << outcount << " recvbuf " << recvbuf[j][outcount-1] << " KO" + << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "===========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " RequestId " << RecvRequestId[j] << " recvbuf " + << recvbuf[j][outcount-1] << " OK" << endl + << "===========================================================" + << endl ; + } + } + else { + cout << "===========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " RequestId " << RecvRequestId[j] << " OK" << endl + << "===========================================================" + << endl ; + } + } + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + + mpi_access.Check() ; + cout << "test" << myrank << " WaitAll" << endl ; + if ( myrank == 0 ) { + mpi_access.WaitAll(maxreq, SendRequestId) ; + mpi_access.DeleteRequests(maxreq, SendRequestId) ; + } + else { + mpi_access.WaitAll(maxreq, RecvRequestId) ; + mpi_access.DeleteRequests(maxreq, RecvRequestId) ; + } + mpi_access.Check() ; + + if ( myrank == 0 ) { + int sendrequests[maxreq] ; + int sendreqsize = mpi_access.SendRequestIds( target , maxreq , sendrequests ) ; + sendreqsize = mpi_access.SendRequestIds( target , maxreq , sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + else { + int recvrequests[maxreq] ; + int recvreqsize = mpi_access.SendRequestIds( target , maxreq , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_Length_1.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_Length_1.cxx new file mode 100644 index 000000000..c8bc3def3 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_ISend_IRecv_Length_1.cxx @@ -0,0 +1,286 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_ISend_IRecv_Length_1() { + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + ostringstream strstream ; + strstream << "test_MPI_Access_ISend_IRecv_Length_1 must be runned with 2 procs" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_MPI_Access_ISend_IRecv_Length_1" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + +#define maxreq 10 + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int SendRequestId[maxreq] ; + int RecvRequestId[maxreq] ; + int sts ; + int sendbuf[1000*(maxreq-1)] ; + int recvbuf[maxreq-1][1000*(maxreq-1)] ; + int maxirecv = 1 ; + int i ; + RecvRequestId[0] = -1 ; + for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) { + sendbuf[i] = i ; + } + for ( i = 0 ; i < maxreq ; i++ ) { + sts = MPI_SUCCESS ; + if ( myrank == 0 ) { + sts = mpi_access.ISend( sendbuf, 1000*i, MPI_INT, target, SendRequestId[i] ) ; + cout << "test" << myrank << " ISend RequestId " << SendRequestId[i] + << " tag " << mpi_access.SendMPITag(target) << endl ; + } + int j ; + for (j = 1 ; j <= i ; j++) { + int source ; + MPI_Datatype datatype ; + int outcount ; + int flag ; + if ( myrank == 0 ) { + mpi_access.Test( SendRequestId[j], flag ) ; + } + else { + int MPITag ; + sts = mpi_access.IProbe( target , source, MPITag, datatype, + outcount, flag) ; + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " IProbe lenerr " << lenerr << " " + << msgerr << endl ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " IProbe KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + cout << "test" << myrank << " IProbe i/j " << i << "/" << j + << " MPITag " << MPITag << " datatype " << datatype + << " outcount " << outcount << " flag " << flag << endl ; + } + if ( flag ) { + if ( myrank == 0 ) { + int target, tag, error, outcount ; + mpi_access.Status( SendRequestId[j], target, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j] + << ") : target " << target << " tag " << tag << " error " << error + << " flag " << flag << endl ; + } + else { + sts = mpi_access.IRecv( recvbuf[maxirecv], outcount, datatype, source, + RecvRequestId[maxirecv] ) ; + cout << "test" << myrank << " maxirecv " << maxirecv << " IRecv RequestId " + << RecvRequestId[maxirecv] << " source " << source + << " outcount " << outcount << " tag " + << mpi_access.RecvMPITag(target) << endl ; + maxirecv = maxirecv + 1 ; + } + } + else if ( myrank == 1 && i == maxreq-1 && j >= maxirecv ) { + sts = mpi_access.IRecv( recvbuf[j], 1000*j, MPI_INT, target, + RecvRequestId[j] ) ; + cout << "test" << myrank << " maxirecv " << maxirecv << " IRecv RequestId " + << RecvRequestId[j] << " target " << target << " length " << 1000*j + << " tag " << mpi_access.RecvMPITag(target) << endl ; + maxirecv = maxirecv + 1 ; + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " KO" << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + + mpi_access.Check() ; + int flag ; + if ( myrank == 0 ) { + mpi_access.TestAll( maxreq, SendRequestId, flag ) ; + cout << "test" << myrank << " TestAll SendRequest flag " << flag << endl ; + } + else { + int i ; + int source ; + int outcount ; + int flag ; + if ( maxirecv != maxreq ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " KO" << " maxirecv " << maxirecv + << " != maxreq " << maxreq << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + while ( maxirecv > 0 ) { + for ( i = 1 ; i < maxreq ; i++ ) { + cout << "test" << myrank << " IProbe : " << endl ; + sts = mpi_access.Test( RecvRequestId[i] , flag ) ; + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " flag " << flag << " lenerr " + << lenerr << " " << msgerr << " maxirecv " << maxirecv << endl ; + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + cout << "test" << myrank << " Test flag " << flag << endl ; + if ( flag ) { + int tag, error ; + mpi_access.Status( RecvRequestId[i] , source , tag , error , + outcount ) ; + if ( i != 0 ) { + if ( outcount != 1000*i | + (recvbuf[i][outcount-1] != (outcount-1)) ) { + ostringstream strstream ; + strstream << "========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " KO" << " i " << i + << " recvbuf " << recvbuf[i][outcount-1] << endl + << "========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + else if ( outcount != 0 ) { + ostringstream strstream ; + strstream << "========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " KO" << " i " << i << endl + << "========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + maxirecv = maxirecv - 1 ; + } + } + } + mpi_access.TestAll( maxreq, RecvRequestId, flag ) ; + cout << "test" << myrank << " TestAll RecvRequest flag " << flag << endl ; + } + mpi_access.Check() ; + cout << "test" << myrank << " WaitAll :" << endl ; + if ( myrank == 0 ) { + mpi_access.WaitAll( maxreq, SendRequestId ) ; + mpi_access.DeleteRequests( maxreq, SendRequestId ) ; + } + else { + mpi_access.WaitAll( maxreq, RecvRequestId ) ; + mpi_access.DeleteRequests( maxreq, RecvRequestId ) ; + } + + if ( myrank == 0 ) { + int sendrequests[maxreq] ; + int sendreqsize = mpi_access.SendRequestIds( target , maxreq , sendrequests ) ; + sendreqsize = mpi_access.SendRequestIds( target , maxreq , sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + else { + int recvrequests[maxreq] ; + int recvreqsize = mpi_access.SendRequestIds( target , maxreq , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_Probe.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_Probe.cxx new file mode 100644 index 000000000..2e30cac47 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_Probe.cxx @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_Probe() { + + cout << "test_MPI_Access_Probe" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + cout << "test_MPI_Access_Probe must be runned with 2 procs" << endl ; + CPPUNIT_FAIL("test_MPI_Access_Probe must be runned with 2 procs") ; + } + + cout << "test_MPI_Access_Probe" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int RequestId[10] ; + int sts ; + int i ; + for ( i = 0 ; i < 10 ; i++ ) { + if ( myrank == 0 ) { + sts = mpi_access.Send(&i,1,MPI_INT,target, RequestId[i]) ; + cout << "test" << myrank << " Send RequestId " << RequestId[i] + << endl ; + } + else { + int source, tag, outcount ; + MPI_Datatype datatype ; + sts = mpi_access.Probe(target, source, tag, datatype, outcount ) ; + cout << "test" << myrank << " Probe target " << target << " source " << source + << " tag " << tag << " outcount " << outcount << endl ; + int recvbuf ; + sts = mpi_access.Recv(&recvbuf,outcount,datatype,source, RequestId[i], + &outcount) ; + if ( (outcount != 1) | (recvbuf != i) ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " outcount " << outcount + << " recvbuf " << recvbuf << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + } + int flag ; + mpi_access.TestAll(10,RequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.WaitAll(10,RequestId) ; + mpi_access.Check() ; + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_SendRecv.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_SendRecv.cxx new file mode 100644 index 000000000..8b3fe2bf7 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_SendRecv.cxx @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_SendRecv() { + + cout << "MPIAccessTest::test_MPI_Access_SendRecv" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + cout << "MPIAccessTest::test_MPI_Access_SendRecv must be runned with 2 procs" << endl ; + CPPUNIT_FAIL("test_MPI_Access_SendRecv must be runned with 2 procs") ; + } + + cout << "MPIAccessTest::test_MPI_Access_SendRecv" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int sendRequestId[10] ; + int recvRequestId[10] ; + int sts ; + int i ; + for ( i = 0 ; i < 10 ; i++ ) { + int recvbuf ; + int outcount ; + if ( i & 1 ) { + outcount = -1 ; + sts = mpi_access.SendRecv(&i,1,MPI_INT,target, sendRequestId[i], + &recvbuf,1,MPI_INT,target, recvRequestId[i], + &outcount) ; + } + else { + sts = mpi_access.SendRecv(&i,1,MPI_INT,target, sendRequestId[i], + &recvbuf,1,MPI_INT,target, recvRequestId[i]) ; +// outcount = mpi_access.MPIOutCount( recvRequestId[i] ) ; + outcount = 1 ; + } + cout << "test" << myrank << " Send sendRequestId " << sendRequestId[i] + << " tag " << mpi_access.SendMPITag(target) + << " recvRequestId " << recvRequestId[i] + << " tag " << mpi_access.RecvMPITag(target) + << " outcount " << outcount << " MPIOutCount " + << mpi_access.MPIOutCount( recvRequestId[i] ) << endl ; + if ( (outcount != 1) | (recvbuf != i) ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " outcount " << outcount + << " recvbuf " << recvbuf << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + } + + int flag ; + mpi_access.TestAll(10,sendRequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.WaitAll(10,sendRequestId) ; + mpi_access.TestAll(10,recvRequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.WaitAll(10,recvRequestId) ; + mpi_access.Check() ; + + int sendrequests[10] ; + int sendreqsize = mpi_access.SendRequestIds( target , 10 , sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + int recvrequests[10] ; + int recvreqsize = mpi_access.SendRequestIds( target , 10 , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_Send_Recv.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_Send_Recv.cxx new file mode 100644 index 000000000..70dc715ad --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_Send_Recv.cxx @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_Send_Recv() { + + cout << "test_MPI_Access_Send_Recv" << endl ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + cout << "test_MPI_Access_Send_Recv must be runned with 2 procs" << endl ; + CPPUNIT_FAIL("test_MPI_Access_Send_Recv must be runned with 2 procs") ; + } + + cout << "test_MPI_Access_Send_Recv" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int RequestId[10] ; + int sts ; + int i ; + for ( i = 0 ; i < 10 ; i++ ) { + if ( myrank == 0 ) { + sts = mpi_access.Send(&i,1,MPI_INT,target, RequestId[i]) ; + cout << "test" << myrank << " Send RequestId " << RequestId[i] + << " tag " << mpi_access.SendMPITag(target) << endl ; + } + else { + int recvbuf ; + int outcount ; + sts = mpi_access.Recv(&recvbuf,1,MPI_INT,target, RequestId[i],&outcount) ; + //int source, tag, error, outcount ; + //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ; + cout << "test" << myrank << " Recv RequestId " << RequestId[i] + << " tag " << mpi_access.RecvMPITag(target) + << " outcount " << outcount << endl ; + if ( (outcount != 1) | (recvbuf != i) ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " outcount " << outcount + << " recvbuf " << recvbuf << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + } + int flag ; + mpi_access.TestAll(10,RequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.WaitAll(10,RequestId) ; + mpi_access.Check() ; + + if ( myrank == 0 ) { + int sendrequests[10] ; + int sendreqsize = mpi_access.SendRequestIds( target , 10 , sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + else { + int recvrequests[10] ; + int recvreqsize = mpi_access.SendRequestIds( target , 10 , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_Send_Recv_Length.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_Send_Recv_Length.cxx new file mode 100644 index 000000000..bb53630f3 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_Send_Recv_Length.cxx @@ -0,0 +1,171 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_Send_Recv_Length() { + + cout << "test_MPI_Access_Send_Recv_Length" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + ostringstream strstream ; + strstream << "test_MPI_Access_Send_Recv_Length must be runned with 2 procs" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_MPI_Access_Send_Recv_Length" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + + if ( myrank >= 2 ) { + mpi_access.Barrier() ; + delete group ; + return ; + } + + int target = 1 - myrank ; + int RequestId[10] ; + int sendbuf[9000] ; + int recvbuf[9000] ; + bool recvbufok ; + int sts ; + int i , j ; + for ( i = 0 ; i < 9000 ; i++ ) { + sendbuf[i] = i ; + } + for ( i = 0 ; i < 10 ; i++ ) { + if ( myrank == 0 ) { + sts = mpi_access.Send( sendbuf, 1000*i, MPI_INT, target, RequestId[i] ) ; + cout << "test" << myrank << " Send RequestId " << RequestId[i] + << " tag " << mpi_access.SendMPITag(target) << endl ; + } + else { + sts = MPI_SUCCESS ; + RequestId[i] = -1 ; + int outcount = 0 ; + if ( i != 0 ) { + sts = mpi_access.Recv( recvbuf,1000*i+1,MPI_INT,target, RequestId[i], + &outcount ) ; + } + //int source, tag, error, outcount ; + //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ; + cout << "test" << myrank << " Recv RequestId " << RequestId[i] + << " tag " << mpi_access.RecvMPITag(target) + << " outcount " << outcount << endl ; + recvbufok = true ; + for ( j = 0 ; j < outcount ; j++ ) { + if ( recvbuf[j] != j ) { + cout << "test" << myrank << " recvbuf[ " << j << " ] = " << recvbuf[j] + << endl ; + recvbufok = false ; + break ; + } + } + if ( (outcount != 1000*i) | !recvbufok ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " recvbuf " << recvbuf << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.Check() ; + } + int flag ; + mpi_access.TestAll(10,RequestId,flag) ; + if ( !flag ) { + ostringstream strstream ; + strstream << "test" << myrank << " flag " << flag << " KO" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + mpi_access.WaitAll(10,RequestId) ; + mpi_access.Check() ; + + if ( myrank == 0 ) { + int sendrequests[10] ; + int sendreqsize = mpi_access.SendRequestIds( target , 10 , sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + else { + int recvrequests[10] ; + int recvreqsize = mpi_access.SendRequestIds( target , 10 , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + } + + mpi_access.Barrier() ; + + delete group ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_Time.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_Time.cxx new file mode 100644 index 000000000..53099722c --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_Time.cxx @@ -0,0 +1,271 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void MPIAccessTest::test_MPI_Access_Time() { + + cout << "test_MPI_Access_Time" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + ostringstream strstream ; + strstream << "test_MPI_Access_Time must be runned with 2 procs" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + + cout << "test_MPI_Access_Time" << myrank << endl ; + + ParaMEDMEM::CommInterface interface ; + + ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ; + + ParaMEDMEM::MPI_Access mpi_access( group ) ; + +#define maxreq 10 + + if ( myrank >= 2 ) { + cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ; + mpi_access.Barrier() ; + cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ; + delete group ; + cout << "test_MPI_Access_Time" << myrank << " OK" << endl ; + return ; + } + + int target = 1 - myrank ; + int SendTimeRequestId[maxreq] ; + int RecvTimeRequestId[maxreq] ; + int SendRequestId[maxreq] ; + int RecvRequestId[maxreq] ; + int sts ; + int sendbuf[maxreq] ; + int recvbuf[maxreq] ; + int i = 0 ; + ParaMEDMEM::TimeMessage aSendTimeMsg[maxreq] ; + ParaMEDMEM::TimeMessage aRecvTimeMsg[maxreq] ; + double t ; + double dt = 1. ; + double maxt = 10. ; + for ( t = 0 ; t < maxt ; t = t+dt ) { + if ( myrank == 0 ) { + aSendTimeMsg[i].time = t ; + aSendTimeMsg[i].deltatime = dt ; + //aSendTimeMsg[i].maxtime = maxt ; + //sts = mpi_access.ISend( &aSendTimeMsg , mpi_access.TimeExtent() , + sts = mpi_access.ISend( &aSendTimeMsg[i] , 1 , + mpi_access.TimeType() , target , + SendTimeRequestId[i]) ; + cout << "test" << myrank << " ISend RequestId " << SendTimeRequestId[i] + << " tag " << mpi_access.SendMPITag(target) << endl ; + sendbuf[i] = i ; + sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, SendRequestId[i]) ; + cout << "test" << myrank << " ISend RequestId " << SendRequestId[i] + << " tag " << mpi_access.SendMPITag(target) << endl ; + } + else { + //sts = mpi_access.IRecv( &aRecvTimeMsg , mpi_access.TimeExtent() , + sts = mpi_access.IRecv( &aRecvTimeMsg[i] , 1 , + mpi_access.TimeType() , target , + RecvTimeRequestId[i]) ; + cout << "test" << myrank << " IRecv RequestId " << RecvTimeRequestId[i] + << " tag " << mpi_access.RecvMPITag(target) << endl ; + sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ; + cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i] + << " tag " << mpi_access.RecvMPITag(target) << endl ; + } + int j ; + for (j = 0 ; j <= i ; j++) { + int flag ; + if ( myrank == 0 ) { + mpi_access.Test( SendTimeRequestId[j], flag ) ; + } + else { + mpi_access.Test( RecvTimeRequestId[j], flag ) ; + } + if ( flag ) { + int target,source, tag, error, outcount ; + if ( myrank == 0 ) { + mpi_access.Status( SendTimeRequestId[j], target, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Send TimeRequestId " << SendTimeRequestId[j] + << ") : target " << target << " tag " << tag << " error " << error + << " flag " << flag << aSendTimeMsg[j] << endl ; + } + else { + mpi_access.Status( RecvTimeRequestId[j], source, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Recv TimeRequestId " + << RecvTimeRequestId[j] << ") : source " << source << " tag " << tag + << " error " << error << " outcount " << outcount + << " flag " << flag << aRecvTimeMsg[j] << endl ; + if ( (outcount != 1) | (aRecvTimeMsg[j].time != j) ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " outcount " << outcount << " KO" + << " RecvTimeRequestId " << RecvTimeRequestId[j] << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "===========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " RecvTimeRequestId " << RecvTimeRequestId[j] << " OK" << endl + << "===========================================================" + << endl ; + } + } + } + if ( myrank == 0 ) { + mpi_access.Test( SendRequestId[j], flag ) ; + } + else { + mpi_access.Test( RecvRequestId[j], flag ) ; + } + if ( flag ) { + int target,source, tag, error, outcount ; + if ( myrank == 0 ) { + mpi_access.Status( SendRequestId[j], target, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j] + << ") : target " << target << " tag " << tag << " error " << error + << " flag " << flag << endl ; + } + else { + mpi_access.Status( RecvRequestId[j], source, tag, error, outcount, + true ) ; + cout << "test" << myrank << " Test(Recv RequestId " + << RecvRequestId[j] << ") : source " << source << " tag " << tag + << " error " << error << " outcount " << outcount + << " flag " << flag << endl ; + if ( (outcount != 1) | (recvbuf[j] != j) ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " outcount " + << outcount << " recvbuf " << recvbuf[j] << " KO" << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "===========================================================" + << endl << "test" << myrank << " outcount " << outcount + << " RequestId " << RecvRequestId[j] << " OK" << endl + << "===========================================================" + << endl ; + } + } + } + } + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + mpi_access.Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + + if ( sts != MPI_SUCCESS ) { + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + i = i + 1 ; + } + + mpi_access.Check() ; + if ( myrank == 0 ) { + mpi_access.WaitAll(maxreq, SendTimeRequestId) ; + mpi_access.DeleteRequests(maxreq, SendTimeRequestId) ; + mpi_access.WaitAll(maxreq, SendRequestId) ; + mpi_access.DeleteRequests(maxreq, SendRequestId) ; + } + else { + mpi_access.WaitAll(maxreq, RecvTimeRequestId) ; + mpi_access.DeleteRequests(maxreq, RecvTimeRequestId) ; + mpi_access.WaitAll(maxreq, RecvRequestId) ; + mpi_access.DeleteRequests(maxreq, RecvRequestId) ; + } + mpi_access.Check() ; + + if ( myrank == 0 ) { + int sendrequests[2*maxreq] ; + int sendreqsize = mpi_access.SendRequestIds( target , 2*maxreq , sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + else { + int recvrequests[2*maxreq] ; + int recvreqsize = mpi_access.SendRequestIds( target , 2*maxreq , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + + cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ; + mpi_access.Barrier() ; + cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ; + + delete group ; + +// MPI_Finalize(); + + cout << "test_MPI_Access_Time" << myrank << " OK" << endl ; + + return ; +} + + + + diff --git a/src/ParaMEDMEM/Test/test_MPI_Access_Time_0.cxx b/src/ParaMEDMEM/Test/test_MPI_Access_Time_0.cxx new file mode 100644 index 000000000..40b3ea4c9 --- /dev/null +++ b/src/ParaMEDMEM/Test/test_MPI_Access_Time_0.cxx @@ -0,0 +1,452 @@ +#include +#include +#include +#include +#include + +#include "MPIAccessTest.hxx" +#include + +//#include "CommInterface.hxx" +//#include "ProcessorGroup.hxx" +//#include "MPIProcessorGroup.hxx" +#include "MPI_Access.hxx" + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace ParaMEDMEM; + +void chksts( int sts , int myrank , ParaMEDMEM::MPI_Access * mpi_access ) { + char msgerr[MPI_MAX_ERROR_STRING] ; + int lenerr ; + if ( sts != MPI_SUCCESS ) { + mpi_access->Error_String(sts, msgerr, &lenerr) ; + cout << "test" << myrank << " lenerr " << lenerr << " " + << msgerr << endl ; + ostringstream strstream ; + strstream << "===========================================================" + << "test" << myrank << " KO" + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } +return ; +} + +void MPIAccessTest::test_MPI_Access_Time_0() { + + cout << "test_MPI_Access_Time_0" << endl ; + +// MPI_Init(&argc, &argv) ; + + int size ; + int myrank ; + MPI_Comm_size(MPI_COMM_WORLD,&size) ; + MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ; + + if ( size < 2 ) { + ostringstream strstream ; + strstream << "usage :" << endl + << "mpirun -np test_MPI_Access_Time_0" <= 2 ) { + cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ; + mpi_access->Barrier() ; + cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ; + cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ; + mpi_access->Barrier() ; + cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ; + delete group ; + delete mpi_access ; + cout << "test_MPI_Access_Time" << myrank << " OK" << endl ; + return ; + } + + int target = 1 - myrank ; + int SendTimeRequestId[maxreq] ; + int RecvTimeRequestId[maxreq] ; + int SendRequestId[maxreq] ; + int RecvRequestId[maxreq] ; + int sts ; + int sendbuf[maxreq] ; + int recvbuf[maxreq] ; + ParaMEDMEM::TimeMessage aSendTimeMsg[maxreq] ; + int lasttime = -1 ; + ParaMEDMEM::TimeMessage RecvTimeMessages[maxreq+1] ; + ParaMEDMEM::TimeMessage *aRecvTimeMsg = &RecvTimeMessages[1] ; +// mpi_access->Trace() ; + int istep = 0 ; + for ( t = 0 ; t < maxt ; t = t+dt[myrank] ) { + cout << "test" << myrank << " ==========================TIME " << t + << " ==========================" << endl ; + if ( myrank == 0 ) { + aSendTimeMsg[istep].time = t ; + aSendTimeMsg[istep].deltatime = dt[myrank] ; + //aSendTimeMsg[istep].maxtime = maxt ; + if ( t+dt[myrank] >= maxt ) { + aSendTimeMsg[istep].deltatime = 0 ; + } + sts = mpi_access->ISend( &aSendTimeMsg[istep] , 1 , + mpi_access->TimeType() , target , + SendTimeRequestId[istep]) ; + cout << "test" << myrank << " ISend TimeRequestId " << SendTimeRequestId[istep] + << " tag " << mpi_access->MPITag(SendTimeRequestId[istep]) << endl ; + chksts( sts , myrank , mpi_access ) ; + sendbuf[istep] = istep ; + sts = mpi_access->ISend(&sendbuf[istep],1,MPI_INT,target, SendRequestId[istep]) ; + cout << "test" << myrank << " ISend Data RequestId " << SendRequestId[istep] + << " tag " << mpi_access->MPITag(SendRequestId[istep]) << endl ; + chksts( sts , myrank , mpi_access ) ; +//CheckSent +//========= + int sendrequests[2*maxreq] ; + int sendreqsize = mpi_access->SendRequestIds( target , 2*maxreq , + sendrequests ) ; + int j , flag ; + for ( j = 0 ; j < sendreqsize ; j++ ) { + sts = mpi_access->Test( sendrequests[j] , flag ) ; + chksts( sts , myrank , mpi_access ) ; + if ( flag ) { + mpi_access->DeleteRequest( sendrequests[j] ) ; + cout << "test" << myrank << " " << j << ". " << sendrequests[j] + << " sendrequest deleted" << endl ; + } + } + } + else { +//InitRecv +//======== + if ( t == 0 ) { + aRecvTimeMsg[lasttime].time = 0 ; + sts = mpi_access->IRecv( &aRecvTimeMsg[lasttime+1] , 1 , + mpi_access->TimeType() , + target , RecvTimeRequestId[lasttime+1]) ; + cout << "test" << myrank << " t == 0 IRecv TimeRequestId " + << RecvTimeRequestId[lasttime+1] + << " MPITag " << mpi_access->MPITag( RecvTimeRequestId[lasttime+1] ) + << " MPICompleted " + << mpi_access->MPICompleted( RecvTimeRequestId[lasttime+1] ) << endl ; + chksts( sts , myrank , mpi_access ) ; + } + else { + cout << "test" << myrank << " t # 0 lasttime " << lasttime << endl ; +//InitialOutTime +//============== + bool outtime = false ; + if ( lasttime != -1 ) { + if ( t <= aRecvTimeMsg[lasttime-1].time ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " t " << t << " <= " + << "aRecvTimeMsg[ " << lasttime << "-1 ].time " + << aRecvTimeMsg[lasttime-1].time << " KO" << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "===========================================================" + << endl << "test" << myrank << " t " << t << " > " + << "aRecvTimeMsg[ " << lasttime << "-1 ].time " + << aRecvTimeMsg[lasttime-1].time << " OK" << endl + << "===========================================================" + << endl ; + } + //outtime = ((aRecvTimeMsg[lasttime].time + + // aRecvTimeMsg[lasttime].deltatime) >= + // aRecvTimeMsg[lasttime].maxtime) ; + outtime = aRecvTimeMsg[lasttime].deltatime == 0 ; + } +// CheckRecv - CheckTime +// On a lasttime tel que : +// aRecvTimeMsg[ lasttime-1 ].time < T(i-1) <= aRecvTimeMsg[ lasttime ].time +// On cherche lasttime tel que : +// aRecvTimeMsg[ lasttime-1 ].time < T(i) <= aRecvTimeMsg[ lasttime ].time + if ( t <= aRecvTimeMsg[lasttime].time ) { + outtime = false ; + } + cout << "test" << myrank << " while outtime( " << outtime << " && t " << t + << " > aRecvTimeMsg[ " << lasttime << " ] " + << aRecvTimeMsg[lasttime].time << " )" << endl ; + while ( !outtime && (t > aRecvTimeMsg[lasttime].time) ) { + lasttime += 1 ; +//TimeMessage +//=========== + sts = mpi_access->Wait( RecvTimeRequestId[lasttime] ) ; + chksts( sts , myrank , mpi_access ) ; + cout << "test" << myrank << " Wait done RecvTimeRequestId " + << RecvTimeRequestId[lasttime] << " lasttime " << lasttime + << " tag " << mpi_access->MPITag(RecvTimeRequestId[lasttime]) + << aRecvTimeMsg[lasttime] << endl ; + if ( lasttime == 0 ) { + aRecvTimeMsg[lasttime-1] = aRecvTimeMsg[lasttime] ; + } + mpi_access->DeleteRequest( RecvTimeRequestId[lasttime] ) ; + + double deltatime = aRecvTimeMsg[lasttime].deltatime ; + //double maxtime = aRecvTimeMsg[lasttime].maxtime ; + double nexttime = aRecvTimeMsg[lasttime].time + deltatime ; + cout << "test" << myrank << " t " << t << " lasttime " << lasttime + << " deltatime " << deltatime + << " nexttime " << nexttime << endl ; + //if ( nexttime < maxtime && t > nexttime ) { + if ( deltatime != 0 && t > nexttime ) { +//CheckRecv : +//========= + //while ( nexttime < maxtime && t > nexttime ) { + while ( deltatime != 0 && t > nexttime ) { + int source, MPITag, outcount ; + MPI_Datatype datatype ; + sts = mpi_access->Probe( target , source, MPITag, datatype, + outcount ) ; + chksts( sts , myrank , mpi_access ) ; +// Cancel DataMessages jusqu'a un TimeMessage + int cancelflag ; + while ( !mpi_access->IsTimeMessage( MPITag ) ) { + sts = mpi_access->Cancel( source, MPITag, datatype, outcount , + //sts = mpi_access->Cancel( source, datatype, outcount , + //RecvRequestId[lasttime] , + cancelflag ) ; + cout << "test" << myrank << " Recv TO CANCEL RequestId " + << RecvRequestId[lasttime] + << " tag " << mpi_access->RecvMPITag( target ) + << " cancelflag " << cancelflag << endl ; + chksts( sts , myrank , mpi_access ) ; + sts = mpi_access->Probe( target , source, MPITag, datatype, + outcount ) ; + chksts( sts , myrank , mpi_access ) ; + } +//On peut avancer en temps + nexttime += deltatime ; + //if ( nexttime < maxtime && t > nexttime ) { + if ( deltatime != 0 && t > nexttime ) { +// Cancel du TimeMessage + sts = mpi_access->Cancel( source, MPITag, datatype, outcount , + //sts = mpi_access->Cancel( source, datatype, outcount , + //RecvRequestId[lasttime] , + cancelflag ) ; + cout << "test" << myrank << " Time TO CANCEL RequestId " + << RecvRequestId[lasttime] + << " tag " << mpi_access->RecvMPITag( target ) + << " cancelflag " << cancelflag << endl ; + chksts( sts , myrank , mpi_access ) ; + } + } + } + else { +//DoRecv +//====== + cout << "test" << myrank << " Recv target " << target + << " lasttime " << lasttime + << " lasttime-1 " << aRecvTimeMsg[lasttime-1] + << " lasttime " << aRecvTimeMsg[lasttime] + << endl ; + sts = mpi_access->Recv(&recvbuf[lasttime],1,MPI_INT,target, + RecvRequestId[lasttime]) ; + cout << "test" << myrank << " Recv RequestId " + << RecvRequestId[lasttime] + << " tag " << mpi_access->RecvMPITag( target ) + << endl ; + chksts( sts , myrank , mpi_access ) ; + } + //outtime = ((aRecvTimeMsg[lasttime].time + + // aRecvTimeMsg[lasttime].deltatime) >= + // aRecvTimeMsg[lasttime].maxtime) ; + outtime = aRecvTimeMsg[lasttime].deltatime == 0 ; + if ( !outtime ) { +// Une lecture asynchrone d'un message temps a l'avance + sts = mpi_access->IRecv( &aRecvTimeMsg[lasttime+1] , 1 , + mpi_access->TimeType() , target , + RecvTimeRequestId[lasttime+1]) ; + cout << "test" << myrank << " IRecv TimeRequestId " + << RecvTimeRequestId[lasttime+1] << " MPITag " + << mpi_access->MPITag( RecvTimeRequestId[lasttime+1] ) + << " MPICompleted " + << mpi_access->MPICompleted( RecvTimeRequestId[lasttime+1] ) + << endl ; + chksts( sts , myrank , mpi_access ) ; + } + else if ( t <= aRecvTimeMsg[lasttime].time ) { + outtime = false ; + } + } + + //printf("DEBUG t %.15f Msg[lasttime-1] %.15f Msg[lasttime] %.15f \n",t, + // aRecvTimeMsg[lasttime-1].time,aRecvTimeMsg[lasttime].time) ; + if ( ((t <= aRecvTimeMsg[lasttime-1].time) || + (t > aRecvTimeMsg[lasttime].time)) && !outtime ) { + ostringstream strstream ; + strstream << "===========================================================" + << endl << "test" << myrank << " t " << t << " <= " + << "aRecvTimeMsg[ " << lasttime << "-1 ].time " + << aRecvTimeMsg[lasttime-1].time << " ou t " << t << " > " + << "aRecvTimeMsg[ " << lasttime << " ].time " + << aRecvTimeMsg[lasttime].time << endl + << " ou bien outtime " << outtime << " KO RequestTimeIds " + << RecvTimeRequestId[lasttime-1] << " " << RecvTimeRequestId[lasttime] + << " RequestIds " + << RecvRequestId[lasttime-1] << " " << RecvRequestId[lasttime] << endl + << "===========================================================" + << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "===========================================================" + << endl << "test" << myrank + << " aRecvTimeMsg[ " << lasttime << "-1 ].time " + << aRecvTimeMsg[lasttime-1].time << " < t " << t << " <= " + << "aRecvTimeMsg[ " << lasttime << " ].time " + << aRecvTimeMsg[lasttime].time << endl + << " ou bien outtime " << outtime << " OK RequestTimeIds " + << RecvTimeRequestId[lasttime-1] << " " << RecvTimeRequestId[lasttime] + << " RequestIds " + << RecvRequestId[lasttime-1] << " " << RecvRequestId[lasttime] << endl + << "===========================================================" + << endl ; + } + } + } + chksts( sts , myrank , mpi_access ) ; + istep = istep + 1 ; + } + + cout << "test" << myrank << " Barrier :" << endl ; + mpi_access->Barrier() ; + + mpi_access->Check() ; + + if ( myrank == 0 ) { +//CheckFinalSent +//============== + cout << "test" << myrank << " CheckFinalSent :" << endl ; + int sendrequests[2*maxreq] ; + int sendreqsize = mpi_access->SendRequestIds( target , 2*maxreq , sendrequests ) ; + int j ; + for ( j = 0 ; j < sendreqsize ; j++ ) { + sts = mpi_access->Wait( sendrequests[j] ) ; + chksts( sts , myrank , mpi_access ) ; + mpi_access->DeleteRequest( sendrequests[j] ) ; + cout << "test" << myrank << " " << j << ". " << sendrequests[j] << " deleted" + << endl ; + } + } + else { + cout << "test" << myrank << " CheckFinalRecv :" << endl ; + int recvrequests[2*maxreq] ; + int recvreqsize = mpi_access->RecvRequestIds( target , 2*maxreq , recvrequests ) ; + int cancelflag ; + int j ; + for ( j = 0 ; j < recvreqsize ; j++ ) { + sts = mpi_access->Cancel( recvrequests[j] , cancelflag ) ; + chksts( sts , myrank , mpi_access ) ; + mpi_access->DeleteRequest( recvrequests[j] ) ; + cout << "test" << myrank << " " << j << ". " << recvrequests[j] << " deleted" + << " cancelflag " << cancelflag << endl ; + } + int source, MPITag, outcount , flag ; + MPI_Datatype datatype ; + sts = mpi_access->IProbe( target , source, MPITag, datatype, + outcount , flag ) ; + chksts( sts , myrank , mpi_access ) ; + while ( flag ) { + sts = mpi_access->Cancel( source, MPITag, datatype, outcount , + //sts = mpi_access->Cancel( source, datatype, outcount , + //RecvRequestId[lasttime] , + cancelflag ) ; + cout << "test" << myrank << " TO CANCEL RequestId " + << RecvRequestId[lasttime] + << " tag " << mpi_access->RecvMPITag( target ) + << " cancelflag " << cancelflag << endl ; + chksts( sts , myrank , mpi_access ) ; + sts = mpi_access->IProbe( target , source, MPITag, datatype, + outcount , flag ) ; + chksts( sts , myrank , mpi_access ) ; + } + } + mpi_access->Check() ; + + if ( myrank == 0 ) { + int sendrequests[2*maxreq] ; + int sendreqsize = mpi_access->SendRequestIds( target , 2*maxreq , sendrequests ) ; + if ( sendreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + else { + int recvrequests[2*maxreq] ; + int recvreqsize = mpi_access->RecvRequestIds( target , 2*maxreq , recvrequests ) ; + if ( recvreqsize != 0 ) { + ostringstream strstream ; + strstream << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl + << "=========================================================" << endl ; + cout << strstream.str() << endl ; + CPPUNIT_FAIL( strstream.str() ) ; + } + else { + cout << "=========================================================" << endl + << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl + << "=========================================================" << endl ; + } + } + + int i ; + for ( i = 0 ; i <= lasttime ; i++ ) { + cout << "test" << myrank << " " << i << ". RecvTimeMsg " + << aRecvTimeMsg[i].time << " recvbuf " << recvbuf[i] << endl ; + } + + cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ; + mpi_access->Barrier() ; + cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ; + + delete group ; + delete mpi_access ; + +// MPI_Finalize(); + + cout << "test" << myrank << " OK" << endl ; + + return ; +} + + + + -- 2.39.2