27#ifndef _MDCORE_INCLUDE_TFENGINE_H_
28#define _MDCORE_INCLUDE_TFENGINE_H_
30#include "tf_platform.h"
35#include <tfSubEngine.h>
41#define engine_bonds_chunk 100
42#define engine_angles_chunk 100
43#define engine_rigids_chunk 50
44#define engine_dihedrals_chunk 100
45#define engine_exclusions_chunk 100
46#define engine_readbuff 16384
47#define engine_maxgpu 10
48#define engine_pshake_steps 20
49#define engine_maxKcutoff 2
51#define engine_split_MPI 1
52#define engine_split_GPU 2
54#define engine_bonded_maxnrthreads 16
55#define engine_bonded_nrthreads ((omp_get_num_threads()<engine_bonded_maxnrthreads)?omp_get_num_threads():engine_bonded_maxnrthreads)
57#ifdef MDCORE_MAXNRTYPES
58#define engine_maxnrtypes MDCORE_MAXNRTYPES
60#define engine_maxnrtypes 128
70 engine_flag_static = 1 << 0,
71 engine_flag_localparts = 1 << 1,
72 engine_flag_cuda = 1 << 2,
73 engine_flag_explepot = 1 << 3,
74 engine_flag_verlet = 1 << 4,
75 engine_flag_verlet_pairwise = 1 << 5,
76 engine_flag_affinity = 1 << 6,
77 engine_flag_prefetch = 1 << 7,
78 engine_flag_verlet_pseudo = 1 << 8,
79 engine_flag_shake = 1 << 9,
80 engine_flag_mpi = 1 << 10,
81 engine_flag_parbonded = 1 << 11,
82 engine_flag_async = 1 << 12,
83 engine_flag_sets = 1 << 13,
84 engine_flag_nullpart = 1 << 14,
85 engine_flag_initialized = 1 << 15,
86 engine_flag_velocity_clamp = 1 << 16,
89 enum EngineIntegrator {
96 engine_timer_step = 0,
100 engine_timer_exchange1,
101 engine_timer_nonbond,
103 engine_timer_bonded_sort,
106 engine_timer_dihedrals,
107 engine_timer_exclusions,
108 engine_timer_advance,
110 engine_timer_exchange2,
111 engine_timer_shuffle,
112 engine_timer_cuda_load,
113 engine_timer_cuda_unload,
114 engine_timer_cuda_dopairs,
116 engine_timer_image_data,
117 engine_timer_render_total,
125 ENGINE_TIMER_STEP = 1 << 0,
126 ENGINE_TIMER_PREPARE = 1 << 1,
127 ENGINE_TIMER_VERLET = 1 << 2,
128 ENGINE_TIMER_EXCHANGE1 = 1 << 3,
129 ENGINE_TIMER_NONBOND = 1 << 4,
130 ENGINE_TIMER_BONDED = 1 << 5,
131 ENGINE_TIMER_BONDED_SORT = 1 << 6,
132 ENGINE_TIMER_BONDS = 1 << 7,
133 ENGINE_TIMER_ANGLES = 1 << 8,
134 ENGINE_TIMER_DIHEDRALS = 1 << 9,
135 ENGINE_TIMER_EXCLUSIONS = 1 << 10,
136 ENGINE_TIMER_ADVANCE = 1 << 11,
137 ENGINE_TIMER_RIGID = 1 << 12,
138 ENGINE_TIMER_EXCHANGE2 = 1 << 13,
139 ENGINE_TIMER_SHUFFLE = 1 << 14,
140 ENGINE_TIMER_CUDA_LOAD = 1 << 15,
141 ENGINE_TIMER_CUDA_UNLOAD = 1 << 16,
142 ENGINE_TIMER_CUDA_DOPAIRS = 1 << 17,
143 ENGINE_TIMER_RENDER = 1 << 18,
144 ENGINE_TIMER_LAST = 1 << 19
152 INTEGRATOR_UPDATE_PERSISTENTFORCE = 1 << 0,
155 INTEGRATOR_FLUX_SUBSTEP = 1 << 1
167 unsigned int flags = 0;
176 unsigned int flags_cuda;
214 int nr_fluxsteps = 1;
220 pthread_cond_t barrier_cond;
221 pthread_cond_t done_cond;
264 std::mutex bonds_mutex;
279 int nr_rigids, rigids_size, nr_constr, rigids_local, rigids_semilocal;
321 pthread_mutex_t xchg_mutex;
322 pthread_cond_t xchg_cond;
323 short int xchg_started, xchg_running;
324 pthread_t thread_exchg;
325 pthread_mutex_t xchg2_mutex;
326 pthread_cond_t xchg2_cond;
327 short int xchg2_started, xchg2_running;
328 pthread_t thread_exchg2;
333 void *sortlists_cuda[ engine_maxgpu ];
334 int nr_pots_cuda, nr_pots_cluster_cuda, *pind_cuda[ engine_maxgpu ], *pind_cluster_cuda[ engine_maxgpu ], *offsets_cuda[ engine_maxgpu ];
335 int nr_devices, devices[ engine_maxgpu ], nr_queues_cuda;
336 float *forces_cuda[ engine_maxgpu ];
337 void *parts_pos_cuda[engine_maxgpu];
338 void *parts_vel_cuda[engine_maxgpu];
339 void *parts_datai_cuda[engine_maxgpu];
340 void *part_states_cuda[engine_maxgpu];
341 int *part_species_flags_cuda[engine_maxgpu];
342 void *parts_pos_cuda_local;
343 void *parts_vel_cuda_local;
344 void *parts_datai_cuda_local;
345 void *part_states_cuda_local;
346 int *part_species_flags_cuda_local;
347 int *cells_cuda_local[ engine_maxgpu];
348 int cells_cuda_nr[ engine_maxgpu ];
349 int *counts_cuda[ engine_maxgpu ], *counts_cuda_local[ engine_maxgpu ];
350 int *ind_cuda[ engine_maxgpu ], *ind_cuda_local[ engine_maxgpu ];
351 struct task_cuda *tasks_cuda[ engine_maxgpu ];
352 int *taboo_cuda[ engine_maxgpu ];
353 int nrtasks_cuda[ engine_maxgpu ];
354 void *streams[ engine_maxgpu ];
355 int nr_blocks[engine_maxgpu], nr_threads[engine_maxgpu];
356 int nr_fluxes_cuda, *fxind_cuda[engine_maxgpu];
357 void **fluxes_cuda[engine_maxgpu];
358 float *fluxes_next_cuda[engine_maxgpu];
359 bool bonds_cuda =
false;
360 bool angles_cuda =
false;
364 ticks timers[engine_timer_last];
373 uint32_t timers_mask;
375 long timer_output_period;
400 FPTYPE computed_volume;
402 EngineIntegrator integrator;
427 int nr_bonds, nr_angles, nr_dihedrals, nr_exclusions, weight;
431 struct Angle *angles;
719 const FPTYPE *origin,
726 unsigned int nr_fluxsteps
784 FPTYPE *charge,
unsigned int *flags,
int N
1036 CAPI_FUNC(FPTYPE) engine_steps_per_second();
1039 CAPI_FUNC(
void) engine_dump();
1041 #define ENGINE_DUMP(msg) {std::cout<<msg<<std::endl; engine_dump();}
1043 CAPI_FUNC(FPTYPE) engine_kinetic_energy(
struct engine *e);
1045 CAPI_FUNC(FPTYPE) engine_temperature(
struct engine *e);
1066 CAPI_FUNC(
HRESULT) engine_init_mpi(
1068 const FPTYPE *origin,
1072 unsigned int period,
1114 CAPI_FUNC(
HRESULT) engine_exchange_async_run(
struct engine *e);
1122 CAPI_FUNC(
HRESULT) engine_exchange_incomming(
struct engine *e);
1143 CAPI_FUNC(
HRESULT) engine_exchange_rigid_async(
struct engine *e);
1150 CAPI_FUNC(
HRESULT) engine_exchange_rigid_async_run(
struct engine *e);
1157 CAPI_FUNC(
HRESULT) engine_exchange_rigid_wait(
struct engine *e);
1167 #if defined(HAVE_CUDA)
1192 CAPI_FUNC(
HRESULT) engine_cuda_load_parts(
struct engine *e);
1199 CAPI_FUNC(
HRESULT) engine_cuda_unload_parts(
struct engine *e);
1213 CAPI_FUNC(
HRESULT) engine_cuda_unload_pots(
struct engine *e);
1220 CAPI_FUNC(
HRESULT) engine_cuda_refresh_particles(
struct engine *e);
1227 CAPI_FUNC(
HRESULT) engine_cuda_allocate_particle_states(
struct engine *e);
1234 CAPI_FUNC(
HRESULT) engine_cuda_finalize_particle_states(
struct engine *e);
1241 CAPI_FUNC(
HRESULT) engine_cuda_refresh_particle_states(
struct engine *e);
1250 CAPI_FUNC(
HRESULT) engine_cuda_refresh_pots(
struct engine *e);
1257 CAPI_FUNC(
HRESULT) engine_cuda_load_fluxes(
struct engine *e);
1264 CAPI_FUNC(
HRESULT) engine_cuda_unload_fluxes(
struct engine *e);
1271 CAPI_FUNC(
HRESULT) engine_cuda_refresh_fluxes(
struct engine *e);
1278 CAPI_FUNC(
HRESULT) engine_cuda_boundary_conditions_refresh(
struct engine *e);
1285 CAPI_FUNC(
HRESULT) engine_cuda_queues_finalize(
struct engine *e);
1309 CAPI_FUNC(
HRESULT) engine_cuda_setthreads(
struct engine *e,
int id,
int nr_threads);
1317 CAPI_FUNC(
HRESULT) engine_cuda_setblocks(
struct engine *e,
int id,
int nr_blocks);
1324 CAPI_FUNC(
HRESULT) engine_cuda_setdevice(
struct engine *e,
int id);
1331 CAPI_FUNC(
HRESULT) engine_cuda_setdevices(
struct engine *e,
int nr_devices,
int *ids);
1336 CAPI_FUNC(
HRESULT) engine_cuda_cleardevices(
struct engine *e);
1345 CAPI_FUNC(
HRESULT) engine_split_gpu(
struct engine *e,
int N,
int flags);
1371 CAPI_FUNC(
int) engine_split_METIS(
struct engine *e,
int N,
int flags);
1374 FVector3 engine_origin();
1375 FVector3 engine_dimensions();
1376 FVector3 engine_center();
1386 CPPAPI_FUNC(
struct engine*) engine_get();
1410 FPTYPE x[] = {pos.
x(), pos.
y(), pos.
z()};
1422 inline Particle *Particle_FromId(
int id) {
T & x()
Definition tfVector3.h:60
T & z()
Definition tfVector3.h:66
T & y()
Definition tfVector3.h:63
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
int engine_dihedral_alloc(struct engine *e, Dihedral **out)
HRESULT engine_addfluxes(struct engine *e, struct Fluxes *f, int i, int j)
Add fluxes to a particle of particle types.
HRESULT engine_addpart(struct engine *e, struct Particle *p, FPTYPE *x, struct Particle **result)
Add a #part to a #space at the given coordinates. The given particle p is only used for the attribute...
HRESULT engine_angle_eval(struct engine *e)
Compute the angled interactions stored in this engine.
struct TissueForge::engine engine
HRESULT engine_rigid_eval(struct engine *e)
Resolve the constraints.
HRESULT engine_init(struct engine *e, const FPTYPE *origin, const FPTYPE *dim, int *cells, FPTYPE cutoff, BoundaryConditionsArgsContainer *boundaryConditions, int max_type, unsigned int flags, unsigned int nr_fluxsteps)
Initialize an #engine with the given data.
HRESULT engine_timers_reset(struct engine *e)
Set all the engine timers to 0.
HRESULT engine_shuffle(struct engine *e)
Re-shuffle the particles in the engine.
int engine_bond_alloc(struct engine *e, struct Bond **result)
HRESULT engine_bonded_sets(struct engine *e, int max_sets)
Assemble non-conflicting sets of bonded interactions.
HRESULT engine_barrier(struct engine *e)
Barrier routine to hold the runners back.
HRESULT engine_load_ghosts(struct engine *e, FPTYPE *x, FPTYPE *v, int *type, int *pid, int *vid, FPTYPE *q, unsigned int *flags, int N)
Load a set of particle data as ghosts.
HRESULT engine_finalize(struct engine *e)
Kill all runners and de-allocate the data of an engine.
HRESULT engine_split_bisect(struct engine *e, int N, int particle_flags)
Split the computational domain over a number of nodes using bisection.
HRESULT engine_flush(struct engine *e)
Clear all particles from this #engine.
HRESULT engine_bond_eval(struct engine *e)
Compute the bonded interactions stored in this engine.
int engine_next_partid(struct engine *e)
HRESULT engine_exclusion_eval(struct engine *e)
Compute the exclusioned interactions stored in this engine.
struct TissueForge::engine_set engine_set
HRESULT engine_rigid_add(struct engine *e, int pid, int pjd, FPTYPE d)
Add a rigid constraint to the engine.
HRESULT engine_next_partids(struct engine *e, int nr_ids, int *ids)
HRESULT space_setpos(struct space *s, int id, FPTYPE *x)
Set the absolute position of a particle.
int engine_unload_marked(struct engine *e, FPTYPE *x, FPTYPE *v, int *type, int *pid, int *vid, FPTYPE *q, unsigned int *flags, FPTYPE *epot, int N)
Unload a set of particle data from the marked cells of an #engine.
int engine_addtype(struct engine *e, FPTYPE mass, FPTYPE charge, const char *name, const char *name2)
Add a type definition.
HRESULT engine_del_particle(struct engine *e, int pid)
HRESULT space_getpos(struct space *s, int id, FPTYPE *x)
Get the absolute position of a particle.
HRESULT engine_step(struct engine *e)
Run the engine for a single time step.
HRESULT engine_load(struct engine *e, FPTYPE *x, FPTYPE *v, int *type, int *pid, int *vid, FPTYPE *charge, unsigned int *flags, int N)
Load a set of particle data.
HRESULT engine_split(struct engine *e)
Set-up the engine for distributed-memory parallel operation.
struct ParticleType * engine_type(int id)
HRESULT engine_bonded_eval(struct engine *e)
Compute all bonded interactions stored in this engine.
HRESULT engine_exclusion_add(struct engine *e, int i, int j)
Add a exclusioned interaction to the engine.
HRESULT engine_addpot(struct engine *e, struct Potential *p, int i, int j)
Add an interaction potential.
HRESULT engine_flush_ghosts(struct engine *e)
Clear all particles from this #engine's ghost cells.
int engine_unload(struct engine *e, FPTYPE *x, FPTYPE *v, int *type, int *pid, int *vid, FPTYPE *charge, unsigned int *flags, FPTYPE *epot, int N)
Unload a set of particle data from the #engine.
HRESULT engine_rigid_sort(struct engine *e)
Split the rigids into local, semilocal and non-local.
HRESULT engine_reset(struct engine *e)
HRESULT engine_dihedral_eval(struct engine *e)
Compute the dihedral interactions stored in this engine.
HRESULT engine_verlet_update(struct engine *e)
Check if the Verlet-list needs to be updated.
int engine_unload_strays(struct engine *e, FPTYPE *x, FPTYPE *v, int *type, int *pid, int *vid, FPTYPE *q, unsigned int *flags, FPTYPE *epot, int N)
Unload real particles that may have wandered into a ghost cell.
HRESULT engine_start(struct engine *e, int nr_runners, int nr_queues)
Start the runners in the given #engine.
int engine_gettype(struct engine *e, char *name)
Look for a given type by name.
HRESULT engine_force_prep(struct engine *e)
HRESULT engine_add_singlebody_force(struct engine *e, struct Force *p, int typeId)
int engine_angle_alloc(struct engine *e, Angle **out)
HRESULT engine_addparts(struct engine *e, int nr_parts, struct Particle **parts, FPTYPE **x)
Add parts to space at given coordinates.
HRESULT engine_rigid_unsort(struct engine *e)
Shuffle the rigid constraints randomly.
HRESULT engine_nonbond_eval(struct engine *e)
Compute the nonbonded interactions in the current step.
struct TissueForge::engine_comm engine_comm
HRESULT engine_bonded_eval_sets(struct engine *e)
Compute all bonded interactions stored in this engine.
HRESULT engine_fluxonly_eval(struct engine *e)
Compute the flux interaction only in the current step.
HRESULT engine_exclusion_shrink(struct engine *e)
Remove duplicate exclusions.
HRESULT engine_force(struct engine *e)
Fluxes * engine_getfluxes(struct engine *e, int i, int j)
Get a fluxes between two particles.
int engine_gettype2(struct engine *e, char *name2)
Look for a given type by its second name.
A bond concerning an angle.
Definition tfAngle.h:60
Bonds apply a potential to a particular set of particles.
Definition tfBond.h:68
Definition tfBoundaryConditions.h:224
The BoundaryConditions class serves as a container for the six instances of the :class:BoundaryCondit...
Definition tfBoundaryConditions.h:117
Definition tfDihedral.h:54
A flux is defined between a pair of types, and acts on the state vector between a pair of instances.
Definition tfFlux.h:88
Force is a metatype, in that Tissue Forge has lots of different instances of force functions,...
Definition tfForce.h:69
Particle * part()
Gets the actual particle of this handle.
Definition tfEngine.h:1414
int id
Definition tfParticle.h:315
ParticleType * type()
Gets the particle type of this handle.
Definition tfEngine.h:1418
Definition tfParticle.h:101
void set_global_position(const FVector3 &pos)
Set the global position.
Definition tfEngine.h:1409
Particle * particle(int i)
Definition tfEngine.h:1399
int32_t * parts
Definition tfParticle.h:209
FVector3 global_position()
Get the global position.
Definition tfEngine.h:1403
Structure containing information on each particle type.
Definition tfParticle.h:768
TissueForge::Particle * particle(int i)
get the i'th particle that's a member of this type.
Definition tfEngine.h:1429
TissueForge::ParticleList parts
list of particles that belong to this type.
Definition tfParticle.h:844
A Potential object is a compiled interpolation of a given function. The Universe applies potentials t...
Definition tfPotential.h:213
Definition tfEngine.h:447
Definition tfEngine.h:424
Definition tfEngine.h:164
int bonds_size
Definition tfEngine.h:261
unsigned int integrator_flags
Definition tfEngine.h:172
std::vector< CustomForce * > custom_forces
Definition tfEngine.h:382
struct Fluxes ** fluxes
Definition tfEngine.h:212
struct Bond * bonds
Definition tfEngine.h:245
int * part2rigid
Definition tfEngine.h:276
int nr_active_bonds
Definition tfEngine.h:256
FPTYPE particle_max_dist_fraction
Definition tfEngine.h:395
pthread_mutex_t barrier_mutex
Definition tfEngine.h:219
FPTYPE tol_rigid
Definition tfEngine.h:282
int nr_rigids
Definition tfEngine.h:279
struct queue * queues
Definition tfEngine.h:231
struct engine_set * sets
Definition tfEngine.h:367
long time
Definition tfEngine.h:183
struct exclusion * exclusions
Definition tfEngine.h:267
struct runner * runners
Definition tfEngine.h:228
int nr_angles
Definition tfEngine.h:290
int nodeID
Definition tfEngine.h:235
static const int max_type
Definition tfEngine.h:193
static struct ParticleType * types
Definition tfEngine.h:197
std::vector< SubEngine * > subengines
Borrowed references to registered subengines.
Definition tfEngine.h:410
int dihedrals_size
Definition tfEngine.h:316
struct Dihedral * dihedrals
Definition tfEngine.h:302
int nr_active_dihedrals
Definition tfEngine.h:313
struct Potential ** p
Definition tfEngine.h:200
int angles_size
Definition tfEngine.h:299
struct engine_comm * send
Definition tfEngine.h:239
int nr_bonds
Definition tfEngine.h:250
int nr_runners
Definition tfEngine.h:225
BoundaryConditionsArgsContainer * _init_boundary_conditions
Definition tfEngine.h:416
struct Angle * angles
Definition tfEngine.h:285
struct rigid * rigids
Definition tfEngine.h:273
struct space s
Definition tfEngine.h:180
int nr_dihedrals
Definition tfEngine.h:307
struct Force ** forces
Definition tfEngine.h:206
int nr_exclusions
Definition tfEngine.h:270
std::set< unsigned int > pids_avail
Definition tfEngine.h:242
int nr_active_angles
Definition tfEngine.h:296
Definition tfExclusion.h:38
Definition tfRunner.h:115
struct Particle ** partlist
Definition tfSpace.h:179
int32_t HRESULT
Definition tf_port.h:255