Epetra Package Browser (Single Doxygen Collection) Development
Epetra_MpiDistributor.h
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 //
00005 //               Epetra: Linear Algebra Services Package
00006 //                 Copyright 2011 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef EPETRA_MPIDISTRIBUTOR_H
00045 #define EPETRA_MPIDISTRIBUTOR_H
00046 #include "Epetra_Object.h"
00047 #include "Epetra_Distributor.h"
00048 class Epetra_MpiComm;
00049 #include <mpi.h>
00050 
00059 class Epetra_MpiDistributor: public Epetra_Object, public virtual Epetra_Distributor {
00060 
00061   public:
00062 
00064 
00065 
00067   Epetra_MpiDistributor(const Epetra_MpiComm & Comm);
00068 
00070   Epetra_MpiDistributor(const Epetra_MpiDistributor & Distributor);
00071 
00073   Epetra_Distributor * Clone(){return(dynamic_cast<Epetra_Distributor *>(new Epetra_MpiDistributor(*this)));};
00074 
00076 
00079   Epetra_Distributor * ReverseClone();
00080 
00082   virtual ~Epetra_MpiDistributor();
00084 
00085 
00087 
00088 
00104   int CreateFromSends( const int & NumExportIDs,
00105                        const int * ExportPIDs,
00106            bool Deterministic,
00107                        int & NumRemoteIDs );
00108 
00133   int CreateFromRecvs( const int & NumRemoteIDs,
00134                        const int * RemoteGIDs,
00135                        const int * RemotePIDs,
00136            bool Deterministic,
00137                        int & NumExportIDs,
00138                        int *& ExportGIDs,
00139                        int *& ExportPIDs);
00140 
00141 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00142   int CreateFromRecvs( const int & NumRemoteIDs,
00143                        const long long * RemoteGIDs,
00144                        const int * RemotePIDs,
00145            bool Deterministic,
00146                        int & NumExportIDs,
00147                        long long *& ExportGIDs,
00148                        int *& ExportPIDs);
00149 #endif
00150 
00151 
00152 
00153 
00156 
00179 
00180  int CreateFromSendsAndRecvs( const int & NumExportIDs,
00181              const int * ExportPIDs,
00182              const int & NumRemoteIDs,
00183              const int * RemoteGIDs,
00184              const int * RemotePIDs,
00185              bool Deterministic);
00186 
00187 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00188   int CreateFromSendsAndRecvs( const int & NumExportIDs,
00189              const int * ExportPIDs,
00190              const int & NumRemoteIDs,
00191              const long long * RemoteGIDs,
00192              const int * RemotePIDs,
00193              bool Deterministic);
00194 #endif
00195       
00196 
00198 
00200 
00201 
00203   int Do( char * export_objs,
00204           int obj_size,
00205           int & len_import_objs,
00206           char *& import_objs );
00207 
00209   int DoReverse( char * export_objs,
00210                  int obj_size,
00211                  int & len_import_objs,
00212                  char *& import_objs );
00213 
00215   int DoPosts( char * export_objs,
00216                int obj_size,
00217                int & len_import_objs,
00218                char *& import_objs );
00220   int DoWaits();
00221 
00223   int DoReversePosts( char * export_objs,
00224                       int obj_size,
00225                       int & len_import_objs,
00226                       char *& import_objs );
00227 
00229   int DoReverseWaits();
00231 
00233 
00234 
00236   int Do( char * export_objs,
00237           int obj_size,
00238           int *& sizes,
00239           int & len_import_objs,
00240           char *& import_objs );
00241 
00243   int DoReverse( char * export_objs,
00244                  int obj_size,
00245                  int *& sizes,
00246                  int & len_import_objs,
00247                  char *& import_objs );
00248 
00250   int DoPosts( char * export_objs,
00251                int obj_size,
00252                int *& sizes,
00253                int & len_import_objs,
00254                char *& import_objs);
00255 
00257   int DoReversePosts( char * export_objs,
00258                       int obj_size,
00259                       int *& sizes,
00260                       int & len_import_objs,
00261                       char *& import_objs );
00263 
00264 
00266 
00267 
00268   int NumReceives() const {return nrecvs_;}
00269 
00271   int NumSends() const {return nsends_;}
00272 
00274   int MaxSendLength() const {return max_send_length_;}
00275 
00277   int TotalReceiveLength() const { return total_recv_length_;}
00278 
00280   const int * ProcsFrom() const {return procs_from_;}
00281 
00283   const int * ProcsTo() const {return procs_to_;}
00284 
00286 
00287   const int * LengthsFrom() const {return lengths_from_;}
00288 
00290 
00291   const int * LengthsTo() const {return lengths_to_;}
00292 
00294 
00296 
00297   void Print(std::ostream & os) const;
00299   private:
00300   int CreateSendStructures_(int my_proc,
00301           int nprocs,
00302           const int & NumExportIDs,
00303           const int * ExportPIDs);
00304 
00305 
00306   int CreateRecvStructures_(const int & NumRemoteIDs,
00307           const int * RemotePIDs);
00308 
00309 
00310   int ComputeRecvs_( int my_proc,
00311          int nprocs );
00312 
00313   template<typename id_type>
00314     int ComputeSends_( int num_imports,
00315            const id_type *& import_ids,
00316            const int *& import_procs,
00317            int & num_exports,
00318            id_type *& export_ids,
00319            int *& export_procs,
00320            int my_proc );
00321 
00322 
00323     int Resize_(int *sizes);
00324 
00325     int Sort_ints_( int *vals, int *other, int nvals );
00326 
00327   private:
00328     Epetra_MpiDistributor& operator=(const Epetra_MpiDistributor& src);
00329 
00330     void CreateReverseDistributor();
00331 
00332     int * lengths_to_;
00333     int * procs_to_;
00334     int * indices_to_;
00335     int   size_indices_to_;
00336 
00337     int * lengths_from_;
00338     int * procs_from_;
00339     int * indices_from_;
00340     int   size_indices_from_;
00341 
00342     bool  resized_;
00343     int * sizes_;
00344 
00345     int * sizes_to_;
00346     int * starts_to_;
00347     int * starts_to_ptr_;
00348     int * indices_to_ptr_;
00349 
00350     int * sizes_from_;
00351     int * starts_from_;
00352     int * starts_from_ptr_;
00353     int * indices_from_ptr_;
00354 
00355     int   nrecvs_;
00356     int   nsends_;
00357     int   nexports_;
00358 
00359     int   self_msg_;
00360 
00361     int   max_send_length_;
00362     int   total_recv_length_;
00363 
00364     int   tag_;
00365 
00366     const Epetra_MpiComm * epComm_;
00367     const MPI_Comm      comm_;
00368 
00369     MPI_Request * request_;
00370     MPI_Status  * status_;
00371 
00372     bool no_delete_;
00373 
00374     char * send_array_;
00375     int send_array_size_;
00376 
00377     Epetra_MpiDistributor * comm_plan_reverse_;
00378 
00379 };
00380 #endif /* EPETRA_MPIDISTRIBUTOR_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines