#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 namespace netgen { #ifdef OLD #ifdef PARALLEL template inline 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; } template <> inline MPI_Datatype MyGetMPIType ( ) { return MPI_CHAR; } template<> inline MPI_Datatype MyGetMPIType ( ) { return MPI_UINT64_T; } #else typedef int MPI_Datatype; template inline MPI_Datatype MyGetMPIType ( ) { return 0; } #endif #endif #ifdef PARALLEL enum { MPI_TAG_CMD = 110 }; enum { MPI_TAG_MESH = 210 }; enum { MPI_TAG_VIS = 310 }; [[deprecated("mympi_send int, use comm.Send instead")]] inline void MyMPI_Send (int i, int dest, int tag, MPI_Comm comm) { int hi = i; MPI_Send( &hi, 1, MPI_INT, dest, tag, comm); } [[deprecated("mympi_revc int, use comm.Recv instead")]] inline void MyMPI_Recv (int & i, int src, int tag, MPI_Comm comm) { MPI_Status status; MPI_Recv( &i, 1, MPI_INT, src, tag, comm, &status); } [[deprecated("mympi_send string, use comm.Send instead")]] inline void MyMPI_Send (const string & s, int dest, int tag, MPI_Comm comm) { MPI_Send( const_cast (s.c_str()), s.length(), MPI_CHAR, dest, tag, comm); } [[deprecated("mympi_revc string, use comm.Recv instead")]] inline void MyMPI_Recv (string & s, int src, int tag, MPI_Comm comm) { MPI_Status status; int len; MPI_Probe (src, tag, MPI_COMM_WORLD, &status); MPI_Get_count (&status, MPI_CHAR, &len); s.assign (len, ' '); MPI_Recv( &s[0], len, MPI_CHAR, src, tag, comm, &status); } template [[deprecated("mympi_send ngflatarray, use comm.send instead")]] inline void MyMPI_Send (NgFlatArray s, int dest, int tag, MPI_Comm comm) { MPI_Send( &s.First(), s.Size(), GetMPIType(), dest, tag, comm); } template [[deprecated("mympi_recv ngflatarray, use comm.Recv instead")]] inline void MyMPI_Recv ( NgFlatArray s, int src, int tag, MPI_Comm comm) { MPI_Status status; MPI_Recv( &s.First(), s.Size(), GetMPIType(), src, tag, comm, &status); } template inline void MyMPI_Recv ( NgArray & s, int src, int tag, MPI_Comm comm) { MPI_Status status; int len; MPI_Probe (src, tag, comm, &status); MPI_Get_count (&status, GetMPIType(), &len); s.SetSize (len); MPI_Recv( &s.First(), len, GetMPIType(), src, tag, comm, &status); } template inline int MyMPI_Recv ( NgArray & s, int tag, MPI_Comm comm) { MPI_Status status; int len; MPI_Probe (MPI_ANY_SOURCE, tag, comm, &status); int src = status.MPI_SOURCE; MPI_Get_count (&status, GetMPIType(), &len); s.SetSize (len); MPI_Recv( &s.First(), len, GetMPIType(), src, tag, comm, &status); return src; } /* template inline void MyMPI_ISend (NgFlatArray 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_IRecv (NgFlatArray s, int dest, int tag, MPI_Request & request) { MPI_Irecv( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, & request); } */ template [[deprecated("mympi_isend ngflatarray, use comm.send instead")]] inline MPI_Request MyMPI_ISend (NgFlatArray s, int dest, int tag, MPI_Comm comm) { MPI_Request request; MPI_Isend( &s.First(), s.Size(), GetMPIType(), dest, tag, comm, &request); return request; } template [[deprecated("mympi_irecv ngflatarray, use comm.recv instead")]] inline MPI_Request MyMPI_IRecv (NgFlatArray s, int dest, int tag, MPI_Comm comm) { MPI_Request request; MPI_Irecv( &s.First(), s.Size(), GetMPIType(), dest, tag, comm, &request); return request; } /* template inline void MyMPI_ISend (NgFlatArray s, int dest, int tag) { MPI_Request request; MPI_Isend( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, &request); MPI_Request_free (&request); } template inline void MyMPI_IRecv (NgFlatArray s, int dest, int tag) { MPI_Request request; MPI_Irecv( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, &request); MPI_Request_free (&request); } */ /* send a table entry to each of the processes in the group ... receive-table entries will be set */ template inline void MyMPI_ExchangeTable (TABLE & send_data, TABLE & recv_data, int tag, const NgMPI_Comm & comm) { int rank = comm.Rank(); int ntasks = comm.Size(); Array send_sizes(ntasks); Array recv_sizes(ntasks); for (int i = 0; i < ntasks; i++) send_sizes[i] = send_data[i].Size(); comm.AllToAll (send_sizes, recv_sizes); for (int i = 0; i < ntasks; i++) recv_data.SetEntrySize (i, recv_sizes[i], sizeof(T)); Array requests; for (int dest = 0; dest < ntasks; dest++) if (dest != rank && send_data[dest].Size()) requests.Append (comm.ISend (FlatArray(send_data[dest]), dest, tag)); for (int dest = 0; dest < ntasks; dest++) if (dest != rank && recv_data[dest].Size()) requests.Append (comm.IRecv (FlatArray(recv_data[dest]), dest, tag)); MyMPI_WaitAll (requests); } extern void MyMPI_SendCmd (const char * cmd); extern string MyMPI_RecvCmd (); template inline void MyMPI_Bcast (T & s, MPI_Comm comm) { MPI_Bcast (&s, 1, GetMPIType(), 0, comm); } template inline void MyMPI_Bcast (NgArray & s, NgMPI_Comm comm) { int size = s.Size(); MyMPI_Bcast (size, comm); // if (MyMPI_GetId(comm) != 0) s.SetSize (size); if (comm.Rank() != 0) s.SetSize (size); MPI_Bcast (&s[0], size, GetMPIType(), 0, comm); } template inline void MyMPI_Bcast (NgArray & s, int root, MPI_Comm comm) { int id; MPI_Comm_rank(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, GetMPIType(), root, comm); } template [[deprecated("mympi_allgather deprecated, use comm.allgather")]] inline void MyMPI_Allgather (const T & send, NgFlatArray recv, MPI_Comm comm) { MPI_Allgather( const_cast (&send), 1, GetMPIType(), &recv[0], 1, GetMPIType(), comm); } template [[deprecated("mympi_alltoall deprecated, use comm.alltoall")]] inline void MyMPI_Alltoall (NgFlatArray send, NgFlatArray recv, MPI_Comm comm) { MPI_Alltoall( &send[0], 1, GetMPIType(), &recv[0], 1, GetMPIType(), comm); } #endif // PARALLEL } #endif