#ifndef FILE_PARALLEL #define FILE_PARALLEL #ifdef VTRACE #include "vt_user.h" #else #define VT_USER_START(n) #define VT_USER_END(n) #define VT_TRACER(n) #endif #ifndef PARALLEL namespace netgen { //using namespace netgen; enum { id = 0 }; enum { ntasks = 0 }; } #else // if PARALLEL // #include #include #include "incvis.hpp" //#include "parallelfunc.hpp" extern MPI_Group MPI_HIGHORDER_WORLD; extern MPI_Comm MPI_HIGHORDER_COMM; namespace netgen { extern int id, ntasks; template MPI_Datatype MyGetMPIType ( ) { cerr << "ERROR in GetMPIType() -- no type found" << endl;return 0;} template <> inline MPI_Datatype MyGetMPIType ( ) { return MPI_INT; } template <> inline MPI_Datatype MyGetMPIType ( ) { return MPI_DOUBLE; } // damit gehen auch echte Konstante ohne Adresse inline void MyMPI_Send (int i, int dest) { int hi = i; MPI_Send( &hi, 1, MPI_INT, dest, 1, MPI_COMM_WORLD); } inline void MyMPI_Recv (int & i, int src) { MPI_Status status; MPI_Recv( &i, 1, MPI_INT, src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } inline void MyMPI_Send (const string & s, int dest) { MPI_Send( const_cast (s.c_str()), s.length(), MPI_CHAR, dest, 1, MPI_COMM_WORLD); } inline void MyMPI_Recv (string & s, int src) { MPI_Status status; int len; MPI_Probe (src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); MPI_Get_count (&status, MPI_CHAR, &len); s.assign (len, ' '); MPI_Recv( &s[0], len, MPI_CHAR, src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } template inline void MyMPI_Send (FlatArray s, int dest) { MPI_Send( &s.First(), s.Size(), MyGetMPIType(), dest, 1, MPI_COMM_WORLD); } template inline void MyMPI_Recv ( FlatArray s, int src) { MPI_Status status; MPI_Recv( &s.First(), s.Size(), MyGetMPIType(), src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } template inline void MyMPI_Recv ( ARRAY & s, int src) { MPI_Status status; int len; MPI_Probe (src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); MPI_Get_count (&status, MyGetMPIType(), &len); s.SetSize (len); MPI_Recv( &s.First(), len, MyGetMPIType(), src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } template inline int MyMPI_Recv ( ARRAY & s) { MPI_Status status; int len; MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); int src = status.MPI_SOURCE; MPI_Get_count (&status, MyGetMPIType(), &len); s.SetSize (len); MPI_Recv( &s.First(), len, MyGetMPIType(), src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); return src; } template inline void MyMPI_ISend (FlatArray s, int dest, MPI_Request & request) { MPI_Isend( &s.First(), s.Size(), MyGetMPIType(), dest, 1, MPI_COMM_WORLD, & request); } template inline void MyMPI_IRecv (FlatArray s, int dest, MPI_Request & request) { MPI_Irecv( &s.First(), s.Size(), MyGetMPIType(), dest, 1, MPI_COMM_WORLD, & request); } template inline void MyMPI_ISendTag (FlatArray s, int dest, int tag, MPI_Request & request) { MPI_Isend( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, & request); } template inline void MyMPI_IRecvTag (FlatArray s, int dest, int tag, MPI_Request & request) { MPI_Irecv( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, & request); } template inline MPI_Request MyMPI_ISend (FlatArray s, int dest) { MPI_Request request; MPI_Isend( &s.First(), s.Size(), MyGetMPIType(), dest, 1, MPI_COMM_WORLD, &request); return request; // MPI_Request_free (&request); } template inline MPI_Request MyMPI_IRecv (FlatArray s, int dest) { MPI_Request request; MPI_Irecv( &s.First(), s.Size(), MyGetMPIType(), dest, 1, MPI_COMM_WORLD, &request); return request; // MPI_Request_free (&request); } template inline void MyMPI_Bcast (T & s, MPI_Comm comm = MPI_COMM_WORLD) { MPI_Bcast (&s, 1, MyGetMPIType(), 0, comm); } template inline void MyMPI_Bcast (ARRAY & s, MPI_Comm comm = MPI_COMM_WORLD) { int size = s.Size(); MyMPI_Bcast (size, comm); if (id != 0) s.SetSize (size); MPI_Bcast (&s[0], size, MyGetMPIType(), 0, comm); } template inline void MyMPI_Bcast (ARRAY & s, int root, MPI_Comm comm = MPI_COMM_WORLD) { int id; MPI_Comm_rank(MPI_HIGHORDER_COMM, &id); int size = s.Size(); MPI_Bcast (&size, 1, MPI_INT, root, comm); if (id != root) s.SetSize (size); if ( !size ) return; MPI_Bcast (&s[0], size, MyGetMPIType(), root, comm); } template inline void MyMPI_Allgather (const T & send, FlatArray recv, MPI_Comm comm) { MPI_Allgather( const_cast (&send), 1, MyGetMPIType(), &recv[0], 1, MyGetMPIType(), comm); } template inline void MyMPI_Alltoall (FlatArray send, FlatArray recv, MPI_Comm comm) { MPI_Alltoall( &send[0], 1, MyGetMPIType(), &recv[0], 1, MyGetMPIType(), comm); } // template // inline void MyMPI_Alltoall_Block (FlatArray send, FlatArray recv, int blocklen, MPI_Comm comm) // { // MPI_Alltoall( &send[0], blocklen, MyGetMPIType(), &recv[0], blocklen, MyGetMPIType(), comm); // } inline void MyMPI_Send ( int *& s, int & len, int dest) { MPI_Send( &len, 1, MPI_INT, dest, 1, MPI_COMM_WORLD); MPI_Send( s, len, MPI_INT, dest, 1, MPI_COMM_WORLD); } inline void MyMPI_Recv ( int *& s, int & len, int src) { MPI_Status status; MPI_Recv( &len, 1, MPI_INT, src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); if ( s ) delete [] s; s = new int [len]; MPI_Recv( s, len, MPI_INT, src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } inline void MyMPI_Send ( double * s, int len, int dest) { MPI_Send( &len, 1, MPI_INT, dest, 1, MPI_COMM_WORLD); MPI_Send( s, len, MPI_DOUBLE, dest, 1, MPI_COMM_WORLD); } inline void MyMPI_Recv ( double *& s, int & len, int src) { MPI_Status status; MPI_Recv( &len, 1, MPI_INT, src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); if ( s ) delete [] s; s = new double [len]; MPI_Recv( s, len, MPI_DOUBLE, src, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } // #include "parallelmesh.hpp" #include "paralleltop.hpp" #include "parallelinterface.hpp" } #endif // PARALLEL #endif