[Swift-commit] r8128 - SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md

wozniak at ci.uchicago.edu wozniak at ci.uchicago.edu
Wed Aug 13 11:02:28 CDT 2014


Author: wozniak
Date: 2014-08-13 11:02:28 -0500 (Wed, 13 Aug 2014)
New Revision: 8128

Added:
   SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/main.c
   SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.h
Modified:
   SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/Makefile
   SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c
Log:
Working version - split out main.c 


Modified: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/Makefile
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/Makefile	2014-08-13 15:55:17 UTC (rev 8127)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/Makefile	2014-08-13 16:02:28 UTC (rev 8128)
@@ -1,12 +1,17 @@
 bin = md
-src = md.c
 
 CC = gcc
-#CFLAGS = -O3 -ffast-math
+CFLAGS = -O0 -g -fPIC
+# CFLAGS = -O3 -ffast-math -g -fPIC
 
-$(bin): $(src)
-	$(CC) -o $@ $(bin).c -lm
+SRC = main.c md.c 
+OBJ = $(patsubst %.c,%.o,$(SRC))
 
+all: $(bin)
+
+$(bin): $(OBJ)
+	$(CC) -o $(@) $(OBJ) -lm
+
 .PHONY: clean
 clean:
 	rm -f $(obj) $(bin)

Added: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/main.c
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/main.c	                        (rev 0)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/main.c	2014-08-13 16:02:28 UTC (rev 8128)
@@ -0,0 +1,298 @@
+
+/*
+ * 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 *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
+  {
+    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 );
+/*
+  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;
+  }
+
+  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" );
+
+  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++ )
+  {
+    compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
+
+    if ( step == step_print )
+    {
+      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;
+    snap ( np, nd, 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;
+}

Modified: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c	2014-08-13 15:55:17 UTC (rev 8127)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c	2014-08-13 16:02:28 UTC (rev 8128)
@@ -3,7 +3,8 @@
 # include <time.h>
 # include <math.h>
 
-int main ( int argc, char *argv[] );
+#include "md.h"
+
 void compute ( int np, int nd, double pos[], double vel[], 
   double mass, double f[], double *pot, double *kin );
 double cpu_time ( void );
@@ -19,293 +20,9 @@
 
 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";
 
-
 /******************************************************************************/
 
-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 *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
-  {
-    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 );
-/*
-  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;
-  }
-
-  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" );
-
-  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++ )
-  {
-    compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
-
-    if ( step == step_print )
-    {
-      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;
-    snap ( np, nd, 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;
-}
-/******************************************************************************/
-
 void compute ( int np, int nd, double pos[], double vel[], 
   double mass, double f[], double *pot, double *kin )
 

Added: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.h
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.h	                        (rev 0)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.h	2014-08-13 16:02:28 UTC (rev 8128)
@@ -0,0 +1,14 @@
+/*
+ * md.h
+ *
+ *  Created on: Aug 13, 2014
+ *      Author: wozniak
+ */
+
+#ifndef MD_H
+#define MD_H
+
+extern double scale_factor, scale_offset;
+extern char *printinfo;
+
+#endif




More information about the Swift-commit mailing list