00001 /* 00002 COSTA: Problem solving environment for data assimilation 00003 Copyright (C) 2005 Nils van Velzen 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 #ifndef CTA_PAR_H 00020 #define CTA_PAR_H 00021 #include "cta_system.h" 00022 #include "cta_handles.h" 00023 #include "cta_datatypes.h" 00024 00025 #ifdef USE_MPI 00026 #include "mpi.h" 00027 #endif 00028 00029 /** 00030 \file cta_par.h 00031 00032 \brief Interface for creating parallel applications with COSTA */ 00033 00034 /** Type of processes */ 00035 enum CTA_ParProcType {CTA_ParMaster, CTA_ParWorker, CTA_ParOther}; 00036 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00042 /** Flag to indicate whether this is a filter process or model/worker process */ 00043 CTAEXPORT extern int CTA_FILTER_PROCESS; 00044 00045 00046 /** Flag CTA_TRUE/CTA_FALSE to indicate whether run is in a parallel 00047 * environment */ 00048 CTAEXPORT extern int CTA_IS_PARALLEL; 00049 00050 /** Rank in world of all processes Note this variable is only 00051 * used for debugging and output. */ 00052 CTAEXPORT extern int CTA_PAR_MY_RANK; 00053 00054 /** Kind of this process */ 00055 CTAEXPORT extern enum CTA_ParProcType CTA_MY_PROC_TYPE; 00056 00057 #ifdef USE_MPI 00058 /** The whole communication universe */ 00059 CTAEXPORT extern MPI_Comm CTA_COMM_WORLD; 00060 00061 /** My own communication group */ 00062 CTAEXPORT extern MPI_Comm CTA_COMM_MYWORLD; 00063 00064 /** Group consisting of master process and all worker processes the master 00065 * communicates with */ 00066 CTAEXPORT extern MPI_Comm CTA_COMM_MASTER_WORKER; 00067 00068 #endif 00069 00070 /** \brief Initialises parallel environment for a process that spawned 00071 * The executable is spawned using MPI_COMM_SPAWN or MPI_COMM_SPAWN_MULTIPLE 00072 * 00073 * It will set up the communication groups and optionally starts the parallel 00074 * model builder 00075 * 00076 * \param StartPar I CTA_TRUE/CTA_FALSE start parallel model builder 00077 * 00078 * Note when a worker process is part of a Master-Worker model and it does 00079 * not implement the COSTA model interface it should not start the parallel model builder 00080 * 00081 * \return error status: CTA_OK if successful 00082 */ 00083 CTAEXPORT int CTA_Par_WorkerSpawn(int StartPar); 00084 00085 00086 /** \brief Initialises parallel environment and create process groups 00087 * 00088 * \param parConfig I configuration input from XML-file 00089 * \param StartPar I CTA_TRUE/CTA_FALSE start parallel model builder 00090 * 00091 * Note when a worker process is part of a Master-Worker model and it does 00092 * not implement the COSTA model interface it should not start the parallel model builder 00093 * 00094 * \return error status: CTA_OK if successful 00095 */ 00096 CTAEXPORT int CTA_Par_CreateGroups(int parConfig, int StartPar); 00097 00098 /** \brief Get the Fortran (integer handles) of the communicators 00099 * 00100 * \param cta_comm_world O Fortran communcator CTA_COMM_WORLD 00101 * \param cta_comm_myworld O Fortran communcator CTA_COMM_MYWORLD 00102 * \param cta_comm_master_worker O Fortran communcator CTA_COMM_MASTER_WORKER 00103 * 00104 */ 00105 #ifdef USE_MPI 00106 CTAEXPORT int CTA_Par_CreateNewCreateGetComm(CTA_ModelClass modelCls, MPI_Comm *comm); 00107 #endif 00108 00109 /** \brief Get a communicator for a process group by index 00110 * 00111 * \param indx I indx of communicator 00112 * \param comm O MPI communicator 00113 * \return CTA_OK when succesfull. The value is CTA_CANNOT_FIND_PROCESS_GROUP is 00114 * returned when the communicator cannot be found 00115 * 00116 */ 00117 #ifdef USE_MPI 00118 CTAEXPORT int CTA_Par_GetAllCommByIndex(int indx, MPI_Comm *comm); 00119 #endif 00120 00121 /** \brief Get the global number of COSTA process group and index of this process 00122 * 00123 * \param itime O The index of this process in the group 00124 * \param iGroup O The group number of this process belongs to (1..nGroups) 00125 * 00126 * \note If this function is called by the COSTA master process or in a sequential run it will return 0 for iGroup 00127 * 00128 */ 00129 CTAEXPORT void CTA_Par_GetGroupInfo(int *iGroup, int *itime); 00130 00131 00132 00133 #ifdef __cplusplus 00134 } 00135 #endif 00136 #endif 00137 00138