[Swift-commit] r8136 - demo/xsede.2014.0425/src/md
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Wed Aug 13 11:59:15 CDT 2014
Author: wozniak
Date: 2014-08-13 11:59:15 -0500 (Wed, 13 Aug 2014)
New Revision: 8136
Added:
demo/xsede.2014.0425/src/md/main.c
demo/xsede.2014.0425/src/md/md.h
demo/xsede.2014.0425/src/md/test-md.sh
Modified:
demo/xsede.2014.0425/src/md/Makefile
demo/xsede.2014.0425/src/md/md.c
Log:
Latest
Modified: demo/xsede.2014.0425/src/md/Makefile
===================================================================
--- demo/xsede.2014.0425/src/md/Makefile 2014-08-13 16:43:02 UTC (rev 8135)
+++ demo/xsede.2014.0425/src/md/Makefile 2014-08-13 16:59:15 UTC (rev 8136)
@@ -1,15 +1,43 @@
bin = md
-src = md.c
CC = gcc
-#CFLAGS = -O3 -ffast-math
+INCLUDES :=
+OPTZ = -O0
+OPTS = -O3 -ffast-math
+CFLAGS = $(OPTZ) -g -fPIC -std=gnu99 $(INCLUDES)
-$(bin): $(src)
- $(CC) -o $@ $(bin).c -lm
+SRC = main.c md.c
+OBJ = $(patsubst %.c,%.o,$(SRC))
+
+
+all: $(bin)
+
+# Link stand-alone executable:
+$(bin): $(OBJ)
+ $(CC) -o $(@) $(OBJ) -lm
+
+# Swift/T integration:
+
+USE_SWIFT = 1
+ifeq ($(USE_SWIFT),1)
+
+TCL_HOME = $(HOME)/sfw/tcl-8.6.0
+INCLUDES += -I $(TCL_HOME)/include
+
+swift-pkg: libtclmd.so
+
+md_wrap.c: md.i
+ swig $(<)
+
+libtclmd.so: md_wrap.o $(OBJ)
+ gcc -shared -o $(@) $(^) -L $(TCL_HOME)/lib -l tcl8.6
+
+endif
+
.PHONY: clean
clean:
- rm -f $(obj) $(bin)
+ rm -f $(OBJ) $(bin)
.PHONY: install
install:
@@ -18,3 +46,4 @@
.PHONY: uninstall
uninstall:
rm -f ../../bin/$(bin)
+
Added: demo/xsede.2014.0425/src/md/main.c
===================================================================
--- demo/xsede.2014.0425/src/md/main.c (rev 0)
+++ demo/xsede.2014.0425/src/md/main.c 2014-08-13 16:59:15 UTC (rev 8136)
@@ -0,0 +1,221 @@
+
+/*
+ * main.c
+ *
+ * Created on: Aug 13, 2014
+ * Author: wozniak
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "md.h"
+
+
+char *outfile = "md.dat";
+char *trjfile = "md.trj.tgz";
+
+
+/******************************************************************************/
+
+int main ( int argc, char *argv[] )
+
+/******************************************************************************/
+/*
+ Purpose:
+
+ MAIN is the main program for MD.
+
+ Discussion:
+
+ MD implements a simple molecular dynamics simulation.
+
+ The velocity Verlet time integration scheme is used.
+
+ The particles interact with a central pair potential.
+
+ Usage:
+
+ md nd np step_num print_step_num dt mass printinfo scale_factor scale_offset seed outFile trajectoryFile
+ where
+ * nd is the spatial dimension (2 or 3);
+ * np is the number of particles (500, for instance);
+ * step_num is the number of time steps (500, for instance);
+ * print_step_num is the number of snapshot prints (10 for instance);
+ * dt is size of timestep;
+ * mass is particle mass;
+ * printinfo is a string to append to each particle coord
+ * scale_offset and scale_factor are used to scale particle positions for logging/rendering (FIXME)
+ * seed sets the initial configuration
+
+
+ Licensing:
+
+ This code is distributed under the GNU LGPL license.
+
+ Modified:
+
+ 05 November 2010
+
+ Author:
+
+ Original FORTRAN90 version by Bill Magro.
+ C version by John Burkardt.
+
+ Parameters:
+
+ None
+*/
+{
+
+ double ctime;
+ double ctime1;
+ double ctime2;
+ double dt = 0.0001;
+ double e0;
+ double *force;
+ int i;
+ int id;
+ double kinetic;
+ double mass = 1.0 * .0001;
+ int nd;
+ int np;
+
+ double potential;
+ int seed = 123456789;
+ int step;
+ int step_num;
+ int step_print;
+ int step_print_index = 0;
+ int step_print_num = 10;
+ double *vel;
+
+ timestamp ( );
+ printf ( "\n" );
+ printf ( "MD\n" );
+ printf ( " C version\n" );
+ printf ( " A molecular dynamics program.\n" );
+/*
+ Get the spatial dimension.
+*/
+ if ( 1 < argc )
+ {
+ nd = atoi ( argv[1] );
+ }
+ else
+ {
+ printf ( "\n" );
+ printf ( " Enter ND, the spatial dimension (2 or 3).\n" );
+ scanf ( "%d", &nd );
+ }
+//
+// Get the number of points.
+//
+ if ( 2 < argc )
+ {
+ np = atoi ( argv[2] );
+ }
+ else
+ {
+ printf ( "\n" );
+ printf ( " Enter NP, the number of points (500, for instance).\n" );
+ scanf ( "%d", &np );
+ }
+//
+// Get the number of time steps.
+//
+ if ( 3 < argc )
+ {
+ step_num = atoi ( argv[3] );
+ }
+ else
+ {
+ printf ( "\n" );
+ printf ( " Enter ND, the number of time steps (500 or 1000, for instance).\n" );
+ scanf ( "%d", &step_num );
+ }
+ /*
+ Get any additional args (command-line only)
+ md nd np step_num [ step__print_num dt mass printinfo scale_factor scale_offset randomseed outfile trjfile ]
+ */
+ if ( 4 < argc )
+ {
+ step_print_num = atoi ( argv[4] );
+ }
+ if ( 5 < argc )
+ {
+ dt = atof ( argv[5] );
+ }
+ if ( 6 < argc )
+ {
+ mass = atof ( argv[6] );
+ }
+ if ( 7 < argc )
+ {
+ printinfo = ( argv[7] );
+ }
+ if ( 8 < argc )
+ {
+ scale_factor = atof ( argv[8] );
+ }
+ if ( 9 < argc )
+ {
+ scale_offset = atof ( argv[9] );
+ }
+ if ( 10 < argc )
+ {
+ seed = atof ( argv[10] );
+ }
+ if ( 11 < argc )
+ {
+ outfile = argv[11];
+ }
+ if ( 12 < argc )
+ {
+ trjfile = argv[12];
+ }
+
+/*
+ Report.
+*/
+ printf ( "\n" );
+ printf ( " MD: Argument count: %d\n", argc );
+ printf ( " ND, the spatial dimension, is %d\n", nd );
+ printf ( " NP, the number of particles in the simulation, is %d\n", np );
+ printf ( " STEP_NUM, the number of time steps, is %d\n", step_num );
+ printf ( " STEP_PRINT_NUM, the number of snapshots to print, is %d\n", step_print_num );
+ printf ( " DT, the size of each time step, is %f\n", dt );
+ printf ( " MASS, the particle mass, is %f\n", mass );
+ printf ( " PRINTINFO, the pass-through info to c-ray, is %s\n", printinfo );
+ printf ( " SCALE_FACTOR, the particle position scaling factor, is %f\n", scale_factor );
+ printf ( " SCALE_OFFSET, the particle position scaling offset, is %f\n", scale_offset );
+ printf ( " SEED, the simulation randomization seed, is %d\n", seed );
+
+ ctime1 = cpu_time ( );
+
+ simulate (step_num, step_print_num, step_print, step_print_index,
+ np, nd, mass, potential, kinetic, e0,
+ dt, seed, outfile);
+
+ ctime2 = cpu_time ( );
+ ctime = ctime2 - ctime1;
+
+ printf ( "\n" );
+ printf ( " Elapsed cpu time for main computation:\n" );
+ printf ( " %f seconds.\n", ctime );
+
+
+ char tarcmd[2000];
+ sprintf(tarcmd,"tar zcf %s md??.trj",trjfile);
+ system(tarcmd);
+/*
+ Terminate.
+*/
+ printf ( "\n" );
+ printf ( "MD\n" );
+ printf ( " Normal end of execution.\n" );
+
+ printf ( "\n" );
+ timestamp ( );
+
+ return 0;
+}
Modified: demo/xsede.2014.0425/src/md/md.c
===================================================================
--- demo/xsede.2014.0425/src/md/md.c 2014-08-13 16:43:02 UTC (rev 8135)
+++ demo/xsede.2014.0425/src/md/md.c 2014-08-13 16:59:15 UTC (rev 8136)
@@ -1,3 +1,4 @@
+# include <assert.h>
# include <stdlib.h>
# include <stdio.h>
# include <time.h>
@@ -3,262 +4,92 @@
# include <math.h>
-int main ( int argc, char *argv[] );
-void compute ( int np, int nd, double pos[], double vel[],
- double mass, double f[], double *pot, double *kin );
-double cpu_time ( void );
-double dist ( int nd, double r1[], double r2[], double dr[] );
-void initialize ( int np, int nd, double box[], int *seed, double pos[],
- double vel[], double acc[] );
-double r8_uniform_01 ( int *seed );
-void timestamp ( void );
-void update ( int np, int nd, double pos[], double vel[], double f[],
- double acc[], double mass, double dt );
-void snap ( int np, int nd, double pos[], double vel[], double f[],
- double acc[], double mass, double dt );
+#include "md.h"
double scale_factor = 2.5, scale_offset = -2.0;
char *printinfo = "0.05 1.0 0.2 0.05 50.0 0.1";
-char *outfile = "md.dat";
-char *trjfile = "md.trj.tgz";
-/******************************************************************************/
+double dist ( int nd, double r1[], double r2[], double dr[] );
-int main ( int argc, char *argv[] )
+double r8_uniform_01 ( int *seed );
+void update ( int np, int nd, double pos[], double vel[], double f[],
+ double acc[], double mass, double dt );
+void snap ( int np, int nd, double t, double pos[], double vel[], double f[],
+ double acc[], double mass, double dt );
-/******************************************************************************/
-/*
- Purpose:
+static void snap_file_open(void);
+static void snap_file_close(void);
- MAIN is the main program for MD.
+void simulate (int step_num, int step_print_num,
+ int step_print, int step_print_index,
+ int np, int nd,
+ double mass,
+ double potential, double kinetic, double e0,
+ double dt,
+ int seed,
+ char* outfile)
+{
+ /*
+ Allocate memory.
+ */
+ double* acc = ( double * ) malloc ( nd * np * sizeof ( double ) );
+ double* box = ( double * ) malloc ( nd * sizeof ( double ) );
+ double* force = ( double * ) malloc ( nd * np * sizeof ( double ) );
+ double* pos = ( double * ) malloc ( nd * np * sizeof ( double ) );
+ double* vel = ( double * ) malloc ( nd * np * sizeof ( double ) );
+ /*
+ Set the dimensions of the box.
+ */
+ for (int i = 0; i < nd; i++ )
+ {
+ box[i] = 10.0;
+ }
- Discussion:
+ printf ( "\n" );
+ printf ( " Initializing positions, velocities, and accelerations.\n" );
- MD implements a simple molecular dynamics simulation.
+ snap_file_open();
- The velocity Verlet time integration scheme is used.
+ /*
+ Set initial positions, velocities, and accelerations.
+ */
+ initialize ( np, nd, box, &seed, pos, vel, acc );
+ /*
+ Compute the forces and energies.
+ */
+ printf ( "\n" );
+ printf ( " Computing initial forces and energies.\n" );
- The particles interact with a central pair potential.
+ compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
- Usage:
-
- md nd np step_num print_step_num dt mass printinfo scale_factor scale_offset seed outFile trajectoryFile
- where
- * nd is the spatial dimension (2 or 3);
- * np is the number of particles (500, for instance);
- * step_num is the number of time steps (500, for instance);
- * print_step_num is the number of snapshot prints (10 for instance);
- * dt is size of timestep;
- * mass is particle mass;
- * printinfo is a string to append to each particle coord
- * scale_offset and scale_factor are used to scale particle positions for logging/rendering (FIXME)
- * seed sets the initial configuration
-
-
- Licensing:
-
- This code is distributed under the GNU LGPL license.
-
- Modified:
-
- 05 November 2010
-
- Author:
-
- Original FORTRAN90 version by Bill Magro.
- C version by John Burkardt.
-
- Parameters:
-
- None
-*/
-{
- double *acc;
- double *box;
- double ctime;
- double ctime1;
- double ctime2;
- double dt = 0.0001;
- double e0;
- double *force;
- int i;
- int id;
- double kinetic;
- double mass = 1.0 * .0001;
- int nd;
- int np;
- double *pos;
- double potential;
- int seed = 123456789;
- int step;
- int step_num;
- int step_print;
- int step_print_index;
- int step_print_num=10;
- double *vel;
-
- timestamp ( );
- printf ( "\n" );
- printf ( "MD\n" );
- printf ( " C version\n" );
- printf ( " A molecular dynamics program.\n" );
-/*
- Get the spatial dimension.
-*/
- if ( 1 < argc )
- {
- nd = atoi ( argv[1] );
- }
- else
- {
+ e0 = potential + kinetic;
+ /*
+ This is the main time stepping loop:
+ Compute forces and energies,
+ Update positions, velocities, accelerations.
+ */
printf ( "\n" );
- printf ( " Enter ND, the spatial dimension (2 or 3).\n" );
- scanf ( "%d", &nd );
- }
-//
-// Get the number of points.
-//
- if ( 2 < argc )
- {
- np = atoi ( argv[2] );
- }
- else
- {
+ printf ( " At each step, we report the potential and kinetic energies.\n" );
+ printf ( " The sum of these energies should be a constant.\n" );
+ printf ( " As an accuracy check, we also print the relative error\n" );
+ printf ( " in the total energy.\n" );
printf ( "\n" );
- printf ( " Enter NP, the number of points (500, for instance).\n" );
- scanf ( "%d", &np );
- }
-//
-// Get the number of time steps.
-//
- if ( 3 < argc )
- {
- step_num = atoi ( argv[3] );
- }
- else
- {
+ printf ( " Step Potential Kinetic (P+K-E0)/E0\n" );
+ printf ( " Energy P Energy K Relative Energy Error\n" );
printf ( "\n" );
- printf ( " Enter ND, the number of time steps (500 or 1000, for instance).\n" );
- scanf ( "%d", &step_num );
- }
- /*
- Get any additional args (command-line only)
- md nd np step_num [ step__print_num dt mass printinfo scale_factor scale_offset randomseed outfile trjfile ]
- */
- if ( 4 < argc )
- {
- step_print_num = atoi ( argv[4] );
- }
- if ( 5 < argc )
- {
- dt = atof ( argv[5] );
- }
- if ( 6 < argc )
- {
- mass = atof ( argv[6] );
- }
- if ( 7 < argc )
- {
- printinfo = ( argv[7] );
- }
- if ( 8 < argc )
- {
- scale_factor = atof ( argv[8] );
- }
- if ( 9 < argc )
- {
- scale_offset = atof ( argv[9] );
- }
- if ( 10 < argc )
- {
- seed = atof ( argv[10] );
- }
- if ( 11 < argc )
- {
- outfile = argv[11];
- }
- if ( 12 < argc )
- {
- trjfile = argv[12];
- }
-/*
- Report.
-*/
- printf ( "\n" );
- printf ( " MD: Argument count: %d\n", argc );
- printf ( " ND, the spatial dimension, is %d\n", nd );
- printf ( " NP, the number of particles in the simulation, is %d\n", np );
- printf ( " STEP_NUM, the number of time steps, is %d\n", step_num );
- printf ( " STEP_PRINT_NUM, the number of snapshots to print, is %d\n", step_print_num );
- printf ( " DT, the size of each time step, is %f\n", dt );
- printf ( " MASS, the particle mass, is %f\n", mass );
- printf ( " PRINTINFO, the pass-through info to c-ray, is %s\n", printinfo );
- printf ( " SCALE_FACTOR, the particle position scaling factor, is %f\n", scale_factor );
- printf ( " SCALE_OFFSET, the particle position scaling offset, is %f\n", scale_offset );
- printf ( " SEED, the simulation randomization seed, is %d\n", seed );
-/*
- Allocate memory.
-*/
- acc = ( double * ) malloc ( nd * np * sizeof ( double ) );
- box = ( double * ) malloc ( nd * sizeof ( double ) );
- force = ( double * ) malloc ( nd * np * sizeof ( double ) );
- pos = ( double * ) malloc ( nd * np * sizeof ( double ) );
- vel = ( double * ) malloc ( nd * np * sizeof ( double ) );
-/*
- Set the dimensions of the box.
-*/
- for ( i = 0; i < nd; i++ )
- {
- box[i] = 10.0;
- }
+ FILE *ofile = fopen(outfile,"w");
+ fprintf (ofile, " Step Potential Kinetic RelativeErr\n" );
- printf ( "\n" );
- printf ( " Initializing positions, velocities, and accelerations.\n" );
-/*
- Set initial positions, velocities, and accelerations.
-*/
- initialize ( np, nd, box, &seed, pos, vel, acc );
-/*
- Compute the forces and energies.
-*/
- printf ( "\n" );
- printf ( " Computing initial forces and energies.\n" );
+ int step = 0;
+ printf ( " %8d %14f %14f %14e\n",
+ step, potential, kinetic, ( potential + kinetic - e0 ) / e0 );
+ fprintf ( ofile, " %8d %14f %14f %14e\n",
+ step, potential, kinetic, ( potential + kinetic - e0 ) / e0 );
+ step_print_index = step_print_index + 1;
+ step_print = ( step_print_index * step_num ) / step_print_num;
- compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
- e0 = potential + kinetic;
-/*
- This is the main time stepping loop:
- Compute forces and energies,
- Update positions, velocities, accelerations.
-*/
- printf ( "\n" );
- printf ( " At each step, we report the potential and kinetic energies.\n" );
- printf ( " The sum of these energies should be a constant.\n" );
- printf ( " As an accuracy check, we also print the relative error\n" );
- printf ( " in the total energy.\n" );
- printf ( "\n" );
- printf ( " Step Potential Kinetic (P+K-E0)/E0\n" );
- printf ( " Energy P Energy K Relative Energy Error\n" );
- printf ( "\n" );
-
- FILE *ofile = fopen(outfile,"w");
- fprintf (ofile, " Step Potential Kinetic RelativeErr\n" );
-
- step_print = 0;
- step_print_index = 0;
-
- step = 0;
- printf ( " %8d %14f %14f %14e\n",
- step, potential, kinetic, ( potential + kinetic - e0 ) / e0 );
- fprintf ( ofile, " %8d %14f %14f %14e\n",
- step, potential, kinetic, ( potential + kinetic - e0 ) / e0 );
- step_print_index = step_print_index + 1;
- step_print = ( step_print_index * step_num ) / step_print_num;
-
- ctime1 = cpu_time ( );
-
- for ( step = 1; step <= step_num; step++ )
+ for (step = 1; step <= step_num; step++ )
{
compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
@@ -267,43 +98,26 @@
if ( step == step_print )
{
printf ( " %8d %14f %14f %14e\n", step, potential, kinetic,
- ( potential + kinetic - e0 ) / e0 );
+ ( potential + kinetic - e0 ) / e0 );
fprintf ( ofile, " %8d %14f %14f %14e\n", step, potential, kinetic,
- ( potential + kinetic - e0 ) / e0 );
+ ( potential + kinetic - e0 ) / e0 );
step_print_index = step_print_index + 1;
step_print = ( step_print_index * step_num ) / step_print_num;
- snap ( np, nd, pos, vel, force, acc, mass, dt );
+ snap (np, nd, step*dt, pos, vel, force, acc, mass, dt );
}
update ( np, nd, pos, vel, force, acc, mass, dt );
}
- ctime2 = cpu_time ( );
- ctime = ctime2 - ctime1;
- printf ( "\n" );
- printf ( " Elapsed cpu time for main computation:\n" );
- printf ( " %f seconds.\n", ctime );
-
free ( acc );
free ( box );
free ( force );
free ( pos );
free ( vel );
- char tarcmd[2000];
- sprintf(tarcmd,"tar zcf %s md??.trj",trjfile);
- system(tarcmd);
-/*
- Terminate.
-*/
- printf ( "\n" );
- printf ( "MD\n" );
- printf ( " Normal end of execution.\n" );
- printf ( "\n" );
- timestamp ( );
-
fclose(ofile);
- return 0;
+ snap_file_close();
}
+
/******************************************************************************/
void compute ( int np, int nd, double pos[], double vel[],
@@ -766,22 +580,32 @@
}
static int snapid = 0;
+static FILE *snap_file = NULL;
-void snap ( int np, int nd, double pos[], double vel[], double f[],
- double acc[], double mass, double dt )
+static void snap_file_open()
{
- int j;
-
char snapfile[100];
sprintf(snapfile, "md%02d.trj", snapid);
+ snap_file = fopen(snapfile, "w");
+ assert(snap_file != NULL);
+}
- FILE *sf = fopen(snapfile, "w");
+static void snap_file_close()
+{
+ fclose(snap_file);
+ snap_file = NULL;
+}
+void snap ( int np, int nd, double t, double pos[], double vel[], double f[],
+ double acc[], double mass, double dt )
+{
+ int j;
+
for ( j = 0; j < np; j++ )
{
- fprintf(sf, "s %f %f %f %s\n", scale(pos[0+j*nd]), scale(pos[1+j*nd]), scale(pos[2+j*nd]), printinfo);
+ fprintf(snap_file, "%f s %f %f %f %s\n",
+ t, scale(pos[0+j*nd]), scale(pos[1+j*nd]), scale(pos[2+j*nd]), printinfo);
}
- fclose(sf);
snapid++;
}
Added: demo/xsede.2014.0425/src/md/md.h
===================================================================
--- demo/xsede.2014.0425/src/md/md.h (rev 0)
+++ demo/xsede.2014.0425/src/md/md.h 2014-08-13 16:59:15 UTC (rev 8136)
@@ -0,0 +1,33 @@
+/*
+ * md.h
+ *
+ * Created on: Aug 13, 2014
+ * Author: wozniak
+ */
+
+#ifndef MD_H
+#define MD_H
+
+extern double scale_factor, scale_offset;
+extern char *printinfo;
+
+double cpu_time ( void );
+
+void timestamp ( void );
+
+void initialize ( int np, int nd, double box[], int *seed, double pos[],
+ double vel[], double acc[] );
+
+void compute ( int np, int nd, double pos[], double vel[],
+ double mass, double f[], double *pot, double *kin );
+
+void simulate (int step_num, int step_print_num,
+ int step_print, int step_print_index,
+ int np, int nd,
+ double mass,
+ double potential, double kinetic, double e0,
+ double dt,
+ int seed,
+ char* outfile);
+
+#endif
Added: demo/xsede.2014.0425/src/md/test-md.sh
===================================================================
--- demo/xsede.2014.0425/src/md/test-md.sh (rev 0)
+++ demo/xsede.2014.0425/src/md/test-md.sh 2014-08-13 16:59:15 UTC (rev 8136)
@@ -0,0 +1,10 @@
+#!/bin/sh -eu
+
+NPART=4
+STEPS=10
+MASS=1
+SEED=42
+OUT=output.txt
+TRJ=output.trj
+
+./md 3 ${NPART} ${STEPS} 10 ".0001" ${MASS} "0.1 1.0 0.2 0.05 50.0 0.1" 2.5 2.0 ${SEED} ${OUT} ${TRJ}
Property changes on: demo/xsede.2014.0425/src/md/test-md.sh
___________________________________________________________________
Added: svn:executable
+ *
More information about the Swift-commit
mailing list