mdcore  0.1.5
Defines | Functions | Variables
/home/pedro/work/mdcore/src/engine.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <math.h>
#include <float.h>
#include <string.h>
#include "../config.h"
#include <omp.h>
#include "cycle.h"
#include "errs.h"
#include "fptype.h"
#include "lock.h"
#include "part.h"
#include "cell.h"
#include "fifo.h"
#include "queue.h"
#include "space.h"
#include "potential.h"
#include "runner.h"
#include "bond.h"
#include "rigid.h"
#include "angle.h"
#include "dihedral.h"
#include "exclusion.h"
#include "reader.h"
#include "engine.h"

Defines

#define error(id)   ( engine_err = errs_register( id , engine_err_msg[-(id)] , __LINE__ , __FUNCTION__ , __FILE__ ) )

Functions

int engine_shuffle (struct engine *e)
 Re-shuffle the particles in the engine.
int engine_timers_reset (struct engine *e)
 Set all the engine timers to 0.
int engine_verlet_update (struct engine *e)
 Check if the Verlet-list needs to be updated.
int engine_split (struct engine *e)
 Set-up the engine for distributed-memory parallel operation.
int engine_split_bisect (struct engine *e, int N)
 Split the computational domain over a number of nodes using bisection.
int engine_flush (struct engine *e)
 Clear all particles from this engine.
int engine_flush_ghosts (struct engine *e)
 Clear all particles from this engine's ghost cells.
int engine_setexplepot (struct engine *e, struct potential *ep)
 Set the explicit electrostatic potential.
int engine_unload (struct engine *e, double *x, double *v, int *type, int *pid, int *vid, double *q, unsigned int *flags, double *epot, int N)
 Unload a set of particle data from the engine.
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)
 Unload a set of particle data from the marked cells of an engine.
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)
 Unload real particles that may have wandered into a ghost cell.
int engine_load (struct engine *e, double *x, double *v, int *type, int *pid, int *vid, double *q, unsigned int *flags, int N)
 Load a set of particle data.
int engine_load_ghosts (struct engine *e, double *x, double *v, int *type, int *pid, int *vid, double *q, unsigned int *flags, int N)
 Load a set of particle data as ghosts.
int engine_gettype (struct engine *e, char *name)
 Look for a given type by name.
int engine_gettype2 (struct engine *e, char *name2)
 Look for a given type by its second name.
int engine_addtype (struct engine *e, double mass, double charge, char *name, char *name2)
 Add a type definition.
int engine_addpot (struct engine *e, struct potential *p, int i, int j)
 Add an interaction potential.
int engine_start (struct engine *e, int nr_runners, int nr_queues)
 Start the runners in the given engine.
int engine_start_SPU (struct engine *e, int nr_runners)
 Start the SPU-associated runners in the given engine.
int engine_nonbond_eval (struct engine *e)
 Compute the nonbonded interactions in the current step.
int engine_advance (struct engine *e)
 Update the particle velocities and positions, re-shuffle if appropriate.
int engine_step (struct engine *e)
 Run the engine for a single time step.
int engine_barrier (struct engine *e)
 Barrier routine to hold the runners back.
int engine_finalize (struct engine *e)
 Initialize an engine with the given data and MPI enabled.
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)
 Initialize an engine with the given data.

Variables

int engine_err = engine_err_ok
char * engine_err_msg [26]

Define Documentation

#define error (   id)    ( engine_err = errs_register( id , engine_err_msg[-(id)] , __LINE__ , __FUNCTION__ , __FILE__ ) )

Function Documentation

int engine_addpot ( struct engine e,
struct potential p,
int  i,
int  j 
)

Add an interaction potential.

Parameters:
eThe engine.
pThe potential to add to the engine.
iID of particle type for this interaction.
jID of second particle type for this interaction.
Returns:
engine_err_ok or < 0 on error (see engine_err).

Adds the given potential for pairs of particles of type i and j, where i and j may be the same type ID.

int engine_addtype ( struct engine e,
double  mass,
double  charge,
char *  name,
char *  name2 
)

Add a type definition.

Parameters:
eThe engine.
massThe particle type mass.
chargeThe particle type charge.
nameParticle name, can be NULL.
name2Particle second name, can be NULL.
Returns:
The type ID or < 0 on error (see engine_err).

The particle type ID must be an integer greater or equal to 0 and less than the value max_type specified in engine_init.

int engine_advance ( struct engine e)

Update the particle velocities and positions, re-shuffle if appropriate.

Parameters:
eThe engine on which to run.
Returns:
engine_err_ok or < 0 on error (see engine_err).
int engine_barrier ( struct engine e)

Barrier routine to hold the runners back.

Parameters:
eThe engine to wait on.
Returns:
engine_err_ok or < 0 on error (see engine_err).

After being initialized, and after every timestep, every runner calls this routine which blocks until all the runners have returned and the engine signals the next timestep.

int engine_finalize ( struct engine e)

Initialize an engine with the given data and MPI enabled.

Parameters:
eThe engine to initialize.
originAn array of three doubles containing the cartesian origin of the space.
dimAn array of three doubles containing the size of the space.
LThe minimum cell edge length, should be at least cutoff.
cutoffThe maximum interaction cutoff to use.
periodA bitmask describing the periodicity of the domain (see space_periodic_full).
max_typeThe maximum number of particle types that will be used by this engine.
flagsBit-mask containing the flags for this engine.
commThe MPI comm to use.
rankThe ID of this node.
Returns:
engine_err_ok or < 0 on error (see engine_err). Kill all runners and de-allocate the data of an engine.
Parameters:
ethe engine to finalize.
Returns:
engine_err_ok or < 0 on error (see engine_err).
int engine_flush ( struct engine e)

Clear all particles from this engine.

Parameters:
eThe engine to flush.
Returns:
engine_err_ok or < 0 on error (see engine_err).
int engine_flush_ghosts ( struct engine e)

Clear all particles from this engine's ghost cells.

Parameters:
eThe engine to flush.
Returns:
engine_err_ok or < 0 on error (see engine_err).
int engine_gettype ( struct engine e,
char *  name 
)

Look for a given type by name.

Parameters:
eThe engine.
nameThe type name.
Returns:
The type ID or < 0 on error (see engine_err).
int engine_gettype2 ( struct engine e,
char *  name2 
)

Look for a given type by its second name.

Parameters:
eThe engine.
name2The type name2.
Returns:
The type ID or < 0 on error (see engine_err).
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 
)

Initialize an engine with the given data.

Parameters:
eThe engine to initialize.
originAn array of three doubles containing the cartesian origin of the space.
dimAn array of three doubles containing the size of the space.
LThe minimum cell edge length in each dimension.
cutoffThe maximum interaction cutoff to use.
periodA bitmask describing the periodicity of the domain (see space_periodic_full).
max_typeThe maximum number of particle types that will be used by this engine.
flagsBit-mask containing the flags for this engine.
Returns:
engine_err_ok or < 0 on error (see engine_err).
int engine_load ( struct engine e,
double *  x,
double *  v,
int *  type,
int *  pid,
int *  vid,
double *  q,
unsigned int *  flags,
int  N 
)

Load a set of particle data.

Parameters:
eThe engine.
xAn N times 3 array of the particle positions.
vAn N times 3 array of the particle velocities.
typeA vector of length N of the particle type IDs.
pidA vector of length N of the particle IDs.
vidA vector of length N of the particle virtual IDs.
qA vector of length N of the individual particle charges.
flagsA vector of length N of the particle flags.
Nthe number of particles to load.
Returns:
engine_err_ok or < 0 on error (see engine_err).

If the parameters v, flags, vid or q are NULL, then these values are set to zero.

int engine_load_ghosts ( struct engine e,
double *  x,
double *  v,
int *  type,
int *  pid,
int *  vid,
double *  q,
unsigned int *  flags,
int  N 
)

Load a set of particle data as ghosts.

Parameters:
eThe engine.
xAn N times 3 array of the particle positions.
vAn N times 3 array of the particle velocities.
typeA vector of length N of the particle type IDs.
pidA vector of length N of the particle IDs.
vidA vector of length N of the particle virtual IDs.
qA vector of length N of the individual particle charges.
flagsA vector of length N of the particle flags.
Nthe number of particles to load.
Returns:
engine_err_ok or < 0 on error (see engine_err).

If the parameters v, flags, vid or q are NULL, then these values are set to zero.

int engine_nonbond_eval ( struct engine e)

Compute the nonbonded interactions in the current step.

Parameters:
eThe engine on which to run.
Returns:
engine_err_ok or < 0 on error (see engine_err).

This routine advances the timestep counter by one, prepares the space for a timestep, releases the runner's associated with the engine and waits for them to finnish.

int engine_setexplepot ( struct engine e,
struct potential ep 
)

Set the explicit electrostatic potential.

Parameters:
eThe engine.
epThe electrostatic potential.
Returns:
engine_err_ok or < 0 on error (see engine_err).

If ep is not NULL, the flag engine_flag_explepot is set, otherwise it is cleared.

int engine_shuffle ( struct engine e)

Re-shuffle the particles in the engine.

Parameters:
eThe engine on which to run.
Returns:
engine_err_ok or < 0 on error (see engine_err).
int engine_split ( struct engine e)

Set-up the engine for distributed-memory parallel operation.

Parameters:
eThe engine to set-up.
Returns:
engine_err_ok or < 0 on error (see engine_err).

This function assumes that engine_split_bisect or some similar function has already been called and that #nodeID, #nr_nodes as well as the cell nodeIDs have been set.

int engine_split_bisect ( struct engine e,
int  N 
)

Split the computational domain over a number of nodes using bisection.

Parameters:
eThe engine to split up.
NThe number of computational nodes.
Returns:
engine_err_ok or < 0 on error (see engine_err).
int engine_start ( struct engine e,
int  nr_runners,
int  nr_queues 
)

Start the runners in the given engine.

Parameters:
eThe engine to start.
nr_runnersThe number of runners start.
Returns:
engine_err_ok or < 0 on error (see engine_err).

Allocates and starts the specified number of runner. Also initializes the Verlet lists.

int engine_start_SPU ( struct engine e,
int  nr_runners 
)

Start the SPU-associated runners in the given engine.

Parameters:
eThe engine to start.
nr_runnersThe number of runners start.
Returns:
engine_err_ok or < 0 on error (see engine_err).

Allocates and starts the specified number of runner.

int engine_step ( struct engine e)

Run the engine for a single time step.

Parameters:
eThe engine on which to run.
Returns:
engine_err_ok or < 0 on error (see engine_err).

This routine advances the timestep counter by one, prepares the space for a timestep, releases the runner's associated with the engine and waits for them to finnish.

Once all the runner's are done, the particle velocities and positions are updated and the particles are re-sorted in the space.

int engine_timers_reset ( struct engine e)

Set all the engine timers to 0.

Parameters:
eThe engine.
Returns:
engine_err_ok or < 0 on error (see engine_err).
int engine_unload ( struct engine e,
double *  x,
double *  v,
int *  type,
int *  pid,
int *  vid,
double *  q,
unsigned int *  flags,
double *  epot,
int  N 
)

Unload a set of particle data from the engine.

Parameters:
eThe engine.
xAn N times 3 array of the particle positions.
vAn N times 3 array of the particle velocities.
typeA vector of length N of the particle type IDs.
pidA vector of length N of the particle IDs.
vidA vector of length N of the particle virtual IDs.
qA vector of length N of the individual particle charges.
flagsA vector of length N of the particle flags.
epotA pointer to a #double in which to store the total potential energy.
Nthe maximum number of particles.
Returns:
The number of particles unloaded or < 0 on error (see engine_err).

The fields x, v, type, pid, vid, q, epot and/or flags may be NULL.

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 
)

Unload a set of particle data from the marked cells of an engine.

Parameters:
eThe engine.
xAn N times 3 array of the particle positions.
vAn N times 3 array of the particle velocities.
typeA vector of length N of the particle type IDs.
pidA vector of length N of the particle IDs.
vidA vector of length N of the particle virtual IDs.
qA vector of length N of the individual particle charges.
flagsA vector of length N of the particle flags.
epotA pointer to a #double in which to store the total potential energy.
Nthe maximum number of particles.
Returns:
The number of particles unloaded or < 0 on error (see engine_err).

The fields x, v, type, pid, vid, q, epot and/or flags may be NULL.

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 
)

Unload real particles that may have wandered into a ghost cell.

Parameters:
eThe engine.
xAn N times 3 array of the particle positions.
vAn N times 3 array of the particle velocities.
typeA vector of length N of the particle type IDs.
pidA vector of length N of the particle IDs.
vidA vector of length N of the particle virtual IDs.
qA vector of length N of the individual particle charges.
flagsA vector of length N of the particle flags.
epotA pointer to a #double in which to store the total potential energy.
Nthe maximum number of particles.
Returns:
The number of particles unloaded or < 0 on error (see engine_err).

The fields x, v, type, vid, pid, q, epot and/or flags may be NULL.

int engine_verlet_update ( struct engine e)

Check if the Verlet-list needs to be updated.

Parameters:
eThe engine.
Returns:
engine_err_ok or < 0 on error (see engine_err).

Variable Documentation

ID of the last error.

char* engine_err_msg[26]
Initial value:
 {
        "Nothing bad happened.",
    "An unexpected NULL pointer was encountered.",
    "A call to malloc failed, probably due to insufficient memory.",
    "An error occured when calling a space function.",
    "A call to a pthread routine failed.",
    "An error occured when calling a runner function.",
    "One or more values were outside of the allowed range.",
    "An error occured while calling a cell function.",
    "The computational domain is too small for the requested operation.",
    "mdcore was not compiled with MPI.",
    "An error occured while calling an MPI function.",
    "An error occured when calling a bond function.", 
    "An error occured when calling an angle function.",
    "An error occured when calling a reader function.",
    "An error occured while interpreting the PSF file.",
    "An error occured while interpreting the PDB file.",
    "An error occured while interpreting the CPF file.",
    "An error occured when calling a potential function.", 
    "An error occured when calling an exclusion function.", 
    "An error occured while computing the bonded sets.", 
    "An error occured when calling a dihedral funtion.", 
    "An error occured when calling a CUDA funtion.", 
    "mdcore was not compiled with CUDA support.", 
    "CUDA support is only available in single-precision.", 
    "Max. number of parts per cell exceeded.",
    "An error occured when calling a queue funtion.", 
        }

List of error messages.

 All Data Structures Files Functions Variables Typedefs Enumerator Defines