mdcore  0.1.5
/home/pedro/work/mdcore/src/engine.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of mdcore.
00003  * Coypright (c) 2010 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
00004  * 
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as published
00007  * by the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program 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
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  * 
00018  ******************************************************************************/
00019 
00020 
00021 /* engine error codes */
00022 #define engine_err_ok                    0
00023 #define engine_err_null                  -1
00024 #define engine_err_malloc                -2
00025 #define engine_err_space                 -3
00026 #define engine_err_pthread               -4
00027 #define engine_err_runner                -5
00028 #define engine_err_range                 -6
00029 #define engine_err_cell                  -7
00030 #define engine_err_domain                -8
00031 #define engine_err_nompi                 -9
00032 #define engine_err_mpi                   -10
00033 #define engine_err_bond                  -11
00034 #define engine_err_angle                 -12
00035 #define engine_err_reader                -13
00036 #define engine_err_psf                   -14
00037 #define engine_err_pdb                   -15
00038 #define engine_err_cpf                   -16
00039 #define engine_err_potential             -17
00040 #define engine_err_exclusion             -18
00041 #define engine_err_sets                  -19
00042 #define engine_err_dihedral              -20
00043 #define engine_err_cuda                  -21
00044 #define engine_err_nocuda                -22
00045 #define engine_err_cudasp                -23
00046 #define engine_err_maxparts              -24
00047 #define engine_err_queue                 -25
00048 
00049 
00050 /* some constants */
00051 #define engine_flag_none                 0
00052 #define engine_flag_tuples               1
00053 #define engine_flag_static               2
00054 #define engine_flag_localparts           4
00055 #define engine_flag_cuda                 8
00056 #define engine_flag_explepot             16
00057 #define engine_flag_verlet               32
00058 #define engine_flag_verlet_pairwise      64
00059 #define engine_flag_affinity             128
00060 #define engine_flag_prefetch             256
00061 #define engine_flag_verlet_pseudo        512
00062 #define engine_flag_unsorted             2048
00063 #define engine_flag_mpi                  4096
00064 #define engine_flag_parbonded            8192
00065 #define engine_flag_async                16384
00066 #define engine_flag_sets                 32768
00067 #define engine_flag_nullpart             65536
00068 #define engine_flag_dispatch             131072
00069 
00070 #define engine_bonds_chunk               100
00071 #define engine_angles_chunk              100
00072 #define engine_rigids_chunk              50
00073 #define engine_dihedrals_chunk           100
00074 #define engine_exclusions_chunk          100
00075 
00076 #define engine_bonded_maxnrthreads       16
00077 #define engine_bonded_nrthreads          ((omp_get_num_threads()<engine_bonded_maxnrthreads)?omp_get_num_threads():engine_bonded_maxnrthreads)
00078 
00080 enum {
00081     engine_timer_step = 0,
00082     engine_timer_prepare,
00083     engine_timer_verlet,
00084     engine_timer_exchange1,
00085     engine_timer_nonbond,
00086     engine_timer_bonded,
00087     engine_timer_bonded_sort,
00088     engine_timer_bonds,
00089     engine_timer_angles,
00090     engine_timer_dihedrals,
00091     engine_timer_exclusions,
00092     engine_timer_advance,
00093     engine_timer_rigid,
00094     engine_timer_exchange2,
00095     engine_timer_shuffle,
00096     engine_timer_cuda_load,
00097     engine_timer_cuda_unload,
00098     engine_timer_cuda_dopairs,
00099     engine_timer_last
00100     };
00101 
00102 
00104 extern int engine_err;
00105 
00107 extern char *engine_err_msg[];
00108 
00109 
00113 struct engine {
00114 
00116     unsigned int flags;
00117 
00119     struct space s;
00120     
00122     int time;
00123     double dt;
00124     
00126     int max_type;
00127     int nr_types;
00128     
00130     struct part_type *types;
00131     
00133     struct potential **p, **p_bond, **p_angle, **p_dihedral;
00134     
00136     struct potential *ep;
00137     
00139         pthread_mutex_t barrier_mutex;
00140         pthread_cond_t barrier_cond;
00141         pthread_cond_t done_cond;
00142     int barrier_count;
00143     
00145     int nr_runners;
00146     
00148     struct runner *runners;
00149     
00151     struct queue *queues;
00152     int nr_queues;
00153     
00155     int nodeID;
00156     int nr_nodes;
00157     
00159     struct engine_comm *send, *recv;
00160     
00162     struct bond *bonds;
00163     
00165     int nr_bonds, bonds_size;
00166     
00168     struct exclusion *exclusions;
00169     
00171     int nr_exclusions, exclusions_size;
00172     
00174     struct rigid *rigids;
00175     
00177     int *part2rigid;
00178     
00180     int nr_rigids, rigids_size, nr_constr, rigids_local, rigids_semilocal;
00181     
00183     double tol_rigid;
00184     
00186     struct angle *angles;
00187     
00189     int nr_angles, angles_size, nr_anglepots, anglepots_size;
00190     
00192     struct dihedral *dihedrals;
00193     
00195     int nr_dihedrals, dihedrals_size, nr_dihedralpots, dihedralpots_size;
00196     
00198     #ifdef WITH_MPI
00199         MPI_Comm comm;
00200         pthread_mutex_t xchg_mutex;
00201         pthread_cond_t xchg_cond;
00202         short int xchg_started, xchg_running;
00203         pthread_t thread_exchg;
00204         pthread_mutex_t xchg2_mutex;
00205         pthread_cond_t xchg2_cond;
00206         short int xchg2_started, xchg2_running;
00207         pthread_t thread_exchg2;
00208     #endif
00209     
00211     #ifdef HAVE_CUDA
00212         void *sortlists_cuda, *sortlists_ind_cuda;
00213         int sortlists_size;
00214         int nrpots_cuda, *pind_cuda, *offsets_cuda;
00215     #endif
00216     
00218     ticks timers[engine_timer_last];
00219     
00221     struct engine_set *sets;
00222     int nr_sets;
00223     
00224     };
00225     
00226     
00230 struct engine_set {
00231 
00232     /* Counts of the different interaction types. */
00233     int nr_bonds, nr_angles, nr_dihedrals, nr_exclusions, weight;
00234     
00235     /* Lists of ID of the relevant bonded types. */
00236     struct bond *bonds;
00237     struct angle *angles;
00238     struct dihedral *dihedrals;
00239     struct exclusion *exclusions;
00240     
00241     /* Nr of sets with which this set conflicts. */
00242     int nr_confl;
00243     
00244     /* IDs of the sets with which this set conflicts. */
00245     int *confl;
00246 
00247     };
00248     
00249     
00253 struct engine_comm {
00254 
00255     /* Size and count of the cellids. */
00256     int count, size;
00257     
00258     int *cellid;
00259     
00260     };
00261     
00262 
00263 /* associated functions */
00264 int engine_addpot ( struct engine *e , struct potential *p , int i , int j );
00265 int engine_addtype ( struct engine *e , double mass , double charge , char *name , char *name2 );
00266 int engine_advance ( struct engine *e );
00267 int engine_angle_addpot ( struct engine *e , struct potential *p );
00268 int engine_angle_add ( struct engine *e , int i , int j , int k , int pid );
00269 int engine_angle_eval ( struct engine *e );
00270 int engine_barrier ( struct engine *e );
00271 int engine_bond_addpot ( struct engine *e , struct potential *p , int i , int j );
00272 int engine_bond_add ( struct engine *e , int i , int j );
00273 int engine_bond_eval ( struct engine *e );
00274 int engine_bonded_eval ( struct engine *e );
00275 int engine_bonded_eval_sets ( struct engine *e );
00276 int engine_bonded_sets ( struct engine *e , int max_sets );
00277 int engine_dihedral_add ( struct engine *e , int i , int j , int k , int l , int pid );
00278 int engine_dihedral_addpot ( struct engine *e , struct potential *p );
00279 int engine_dihedral_eval ( struct engine *e );
00280 int engine_dump_PSF ( struct engine *e , FILE *psf , FILE *pdb , char *excl[] , int nr_excl );
00281 int engine_exclusion_add ( struct engine *e , int i , int j );
00282 int engine_exclusion_eval ( struct engine *e );
00283 int engine_exclusion_shrink ( struct engine *e );
00284 int engine_finalize ( struct engine *e );
00285 int engine_flush_ghosts ( struct engine *e );
00286 int engine_flush ( struct engine *e );
00287 int engine_gettype ( struct engine *e , char *name );
00288 int engine_gettype2 ( struct engine *e , char *name2 );
00289 int engine_init ( struct engine *e , const double *origin , const double *dim , double *L , double cutoff , unsigned int period , int max_type , unsigned int flags );
00290 int engine_load_ghosts ( struct engine *e , double *x , double *v , int *type , int *pid , int *vid , double *q , unsigned int *flags , int N );
00291 int engine_load ( struct engine *e , double *x , double *v , int *type , int *pid , int *vid , double *charge , unsigned int *flags , int N );
00292 int engine_nonbond_eval ( struct engine *e );
00293 int engine_read_cpf ( struct engine *e , FILE *cpf , double kappa , double tol , int rigidH );
00294 int engine_read_psf ( struct engine *e , FILE *psf , FILE *pdb );
00295 int engine_read_xplor ( struct engine *e , FILE *xplor , double kappa , double tol , int rigidH );
00296 int engine_rigid_add ( struct engine *e , int pid , int pjd , double d );
00297 int engine_rigid_eval ( struct engine *e );
00298 int engine_rigid_sort ( struct engine *e );
00299 int engine_rigid_unsort ( struct engine *e );
00300 int engine_setexplepot ( struct engine *e , struct potential *ep );
00301 int engine_shuffle ( struct engine *e );
00302 int engine_split_bisect ( struct engine *e , int N );
00303 int engine_split ( struct engine *e );
00304 int engine_start_SPU ( struct engine *e , int nr_runners );
00305 int engine_start ( struct engine *e , int nr_runners , int nr_queues );
00306 int engine_step ( struct engine *e );
00307 int engine_timers_reset ( struct engine *e );
00308 int engine_unload_marked ( struct engine *e , double *x , double *v , int *type , int *pid , int *vid , double *q , unsigned int *flags , double *epot , int N );
00309 int engine_unload_strays ( struct engine *e , double *x , double *v , int *type , int *pid , int *vid , double *q , unsigned int *flags , double *epot , int N );
00310 int engine_unload ( struct engine *e , double *x , double *v , int *type , int *pid , int *vid , double *charge , unsigned int *flags , double *epot , int N );
00311 int engine_verlet_update ( struct engine *e );
00312 #ifdef WITH_MPI
00313     int engine_init_mpi ( struct engine *e , const double *origin , const double *dim , double *L , double cutoff , unsigned int period , int max_type , unsigned int flags , MPI_Comm comm , int rank );
00314     int engine_exchange ( struct engine *e );
00315     int engine_exchange_async ( struct engine *e );
00316     int engine_exchange_async_run ( struct engine *e );
00317     int engine_exchange_incomming ( struct engine *e );
00318     int engine_exchange_rigid ( struct engine *e );
00319     int engine_exchange_rigid_async ( struct engine *e );
00320     int engine_exchange_rigid_async_run ( struct engine *e );
00321     int engine_exchange_rigid_wait ( struct engine *e );
00322     int engine_exchange_wait ( struct engine *e );
00323 #endif
00324 #if defined(HAVE_CUDA) && defined(WITH_CUDA)
00325     #ifdef __cplusplus
00326         extern "C" int engine_nonbond_cuda ( struct engine *e );
00327         extern "C" int engine_cuda_load ( struct engine *e );
00328         extern "C" int engine_cuda_load_parts ( struct engine *e );
00329         extern "C" int engine_cuda_unload_parts ( struct engine *e );
00330         extern "C" int engine_cuda_setdevice ( int id );
00331     #else
00332         int engine_nonbond_cuda ( struct engine *e );
00333         int engine_cuda_load ( struct engine *e );
00334         int engine_cuda_load_parts ( struct engine *e );
00335         int engine_cuda_unload_parts ( struct engine *e );
00336         int engine_cuda_setdevice ( int id );
00337     #endif
00338 #endif
 All Data Structures Files Functions Variables Typedefs Enumerator Defines