Skip to content

Commit

Permalink
Revert "[DRAFT] SENPAI Parallel computing SENPAI-Molecular-Dynamics#9
Browse files Browse the repository at this point in the history
…-- OpenMP implementation"
  • Loading branch information
raresraf authored Apr 6, 2020
1 parent 32b053a commit 9aeeea2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OBJS := $(shell find $(SRC_DIR) -name "*.o")
NAME := senpai

WARNINGS := -Wall -Wextra -Werror -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wuninitialized -Wstrict-prototypes
OPTIONS := -fopenmp -std=c99 -O2 -g -U__STRICT_ANSI__
OPTIONS := -std=c99 -O2 -g -U__STRICT_ANSI__
LIBS := -lm
CFLAGS := -I$(HDR_DIR) $(WARNINGS) $(OPTIONS) $(LIBS) -o $(NAME).bin

Expand Down
1 change: 0 additions & 1 deletion headers/universe.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct atom_s

/* MECHANICS */
vec3d_t pos; /* Position */
vec3d_t pos_backup; /* Position backup */
vec3d_t vel; /* Velocity */
vec3d_t acc; /* Acceleration */
vec3d_t frc; /* Force */
Expand Down
35 changes: 17 additions & 18 deletions sources/force.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,19 @@ universe_t *force_angle(vec3d_t *frc, universe_t *universe, const size_t a1, con
pos_backup = ligand->pos;

if (to_ligand.x > 0.5*(universe->size))
ligand->pos_backup.x -= universe->size;
ligand->pos.x -= universe->size;
else if (to_ligand.x <= -0.5*(universe->size))
ligand->pos_backup.x += universe->size;
ligand->pos.x += universe->size;

if (to_ligand.y > 0.5*(universe->size))
ligand->pos_backup.y -= universe->size;
ligand->pos.y -= universe->size;
else if (to_ligand.y <= -0.5*(universe->size))
ligand->pos_backup.y += universe->size;
ligand->pos.y += universe->size;

if (to_ligand.z > 0.5*(universe->size))
ligand->pos_backup.z -= universe->size;
ligand->pos.z -= universe->size;
else if (to_ligand.z <= -0.5*(universe->size))
ligand->pos_backup.z += universe->size;
ligand->pos.z += universe->size;
/* PERIODIC BOUNDARY CONDITIONS */

/* Get its magnitude */
Expand Down Expand Up @@ -256,7 +256,7 @@ universe_t *force_total(vec3d_t *frc, universe_t *universe, const size_t atom_id
{
size_t i;
vec3d_t to_target;
//vec3d_t pos_backup;
vec3d_t pos_backup;
vec3d_t vec_bond;
vec3d_t vec_electrostatic;
vec3d_t vec_lennardjones;
Expand All @@ -270,27 +270,26 @@ universe_t *force_total(vec3d_t *frc, universe_t *universe, const size_t atom_id
{
/* PERIODIC BOUNDARY CONDITIONS */
/* Backup the atom's coordinates */
// pos_backup = universe->atom[i].pos;
universe->atom[i].pos_backup = universe->atom[i].pos;
pos_backup = universe->atom[i].pos;

/* Get the vector going to the target atom */
vec3d_sub(&to_target, &(universe->atom[i].pos), &(universe->atom[atom_id].pos));

/* Temporarily undo the PBC enforcement, if needed */
if (to_target.x > 0.5*(universe->size))
universe->atom[i].pos_backup.x -= universe->size;
universe->atom[i].pos.x -= universe->size;
else if (to_target.x <= -0.5*(universe->size))
universe->atom[i].pos_backup.x += universe->size;
universe->atom[i].pos.x += universe->size;

if (to_target.y > 0.5*(universe->size))
universe->atom[i].pos_backup.y -= universe->size;
universe->atom[i].pos.y -= universe->size;
else if (to_target.y <= -0.5*(universe->size))
universe->atom[i].pos_backup.y += universe->size;
universe->atom[i].pos.y += universe->size;

if (to_target.z > 0.5*(universe->size))
universe->atom[i].pos_backup.z -= universe->size;
universe->atom[i].pos.z -= universe->size;
else if (to_target.z <= -0.5*(universe->size))
universe->atom[i].pos_backup.z += universe->size;
universe->atom[i].pos.z += universe->size;
/* PERIODIC BOUNDARY CONDITIONS */

/* Bonded interractions */
Expand All @@ -301,7 +300,7 @@ universe_t *force_total(vec3d_t *frc, universe_t *universe, const size_t atom_id
return (retstr(NULL, TEXT_FORCE_TOTAL_FAILURE, __FILE__, __LINE__));
if (force_angle(&vec_angle, universe, atom_id, i) == NULL)
return (retstr(NULL, TEXT_FORCE_TOTAL_FAILURE, __FILE__, __LINE__));
;

/* Sum the forces */
vec3d_add(frc, frc, &vec_bond);
vec3d_add(frc, frc, &vec_angle);
Expand All @@ -315,13 +314,13 @@ universe_t *force_total(vec3d_t *frc, universe_t *universe, const size_t atom_id
return (retstr(NULL, TEXT_FORCE_TOTAL_FAILURE, __FILE__, __LINE__));
if (force_lennardjones(&vec_lennardjones, universe, atom_id, i) == NULL)
return (retstr(NULL, TEXT_FORCE_TOTAL_FAILURE, __FILE__, __LINE__));
;

/* Sum the forces */
vec3d_add(frc, frc, &vec_electrostatic);
vec3d_add(frc, frc, &vec_lennardjones);
}
/* Restore the backup coordinates */
//universe->atom[i].pos = pos_backup;
universe->atom[i].pos = pos_backup;
}
}

Expand Down
16 changes: 8 additions & 8 deletions sources/potential.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,25 @@ universe_t *potential_total(double *pot, universe_t *universe, const size_t atom
/* PERIODIC BOUNDARY CONDITIONS */
/* Backup the atom's coordinates */
pos_backup = universe->atom[i].pos;
universe->atom[i].pos_backup = universe->atom[i].pos;

/* Get the vector going to the target atom */
vec3d_sub(&to_target, &(universe->atom[i].pos), &(universe->atom[atom_id].pos));

/* Temporarily undo the PBC enforcement, if needed */
if (to_target.x > 0.5*(universe->size))
universe->atom[i].pos_backup.x -= universe->size;
universe->atom[i].pos.x -= universe->size;
else if (to_target.x <= -0.5*(universe->size))
universe->atom[i].pos_backup.x += universe->size;
universe->atom[i].pos.x += universe->size;

if (to_target.y > 0.5*(universe->size))
universe->atom[i].pos_backup.y -= universe->size;
universe->atom[i].pos.y -= universe->size;
else if (to_target.y <= -0.5*(universe->size))
universe->atom[i].pos_backup.y += universe->size;
universe->atom[i].pos.y += universe->size;

if (to_target.z > 0.5*(universe->size))
universe->atom[i].pos_backup.z -= universe->size;
universe->atom[i].pos.z -= universe->size;
else if (to_target.z <= -0.5*(universe->size))
universe->atom[i].pos_backup.z += universe->size;
universe->atom[i].pos.z += universe->size;
/* PERIODIC BOUNDARY CONDITIONS */

/* Bonded interractions */
Expand Down Expand Up @@ -298,7 +298,7 @@ universe_t *potential_total(double *pot, universe_t *universe, const size_t atom
}

/* Restore the backup coordinates */
universe->atom[i].pos_backup = pos_backup;
universe->atom[i].pos = pos_backup;
}
}

Expand Down
20 changes: 8 additions & 12 deletions sources/universe.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,47 +376,43 @@ universe_t *universe_iterate(universe_t *universe, const args_t *args)
{
size_t i; /* Iterator */

{
/* We update the position vector first, as part of the Velocity-Verley integration */
for (i=0; i<(universe->atom_nb); ++i)
if (atom_update_pos(universe, args, i) == NULL)
{;} //return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));
return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));

/* We enforce the periodic boundary conditions */

for (i=0; i<(universe->atom_nb); ++i)
if (atom_enforce_pbc(universe, i) == NULL)
{;} //return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));
return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));

/* Update the force vectors */
/* By numerically differentiating the potential energy... */
if (args->numerical == MODE_NUMERICAL)
{
#pragma omp parallel for num_threads(NUM_THREADS)
for (i=0; i<(universe->atom_nb); ++i)
if (atom_update_frc_numerical(universe, i) == NULL)
{;} //return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));
return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));
}

/* Or analytically solving for force */
else
{
#pragma omp parallel for num_threads(NUM_THREADS)
for (i=0; i<(universe->atom_nb); ++i)
if (atom_update_frc_analytical(universe, i) == NULL)
{;} //return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));
return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));
}

/* Update the acceleration vectors */
for (i=0; i<(universe->atom_nb); ++i)
if (atom_update_acc(universe, i) == NULL)
{;} //return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));
return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));

/* Update the speed vectors */
for (i=0; i<(universe->atom_nb); ++i)
if (atom_update_vel(universe, args, i) == NULL)
{;} //return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));
}
return (retstr(NULL, TEXT_UNIVERSE_ITERATE_FAILURE, __FILE__, __LINE__));

return (universe);
}

Expand Down Expand Up @@ -678,4 +674,4 @@ universe_t *universe_parameters_print(universe_t *universe, const args_t *args)
printf(TEXT_INFO_ITERATIONS, (long)ceil(args->max_time/args->timestep));

return (universe);
}
}

0 comments on commit 9aeeea2

Please sign in to comment.