CECS Home | ANU Home | Search ANU
ANU College of Engineering and Computer Science
Research School of Computer Science
Printer Friendly Version of this Document

UniSAFE

High Performance Scientific Computing

COMP3320/COMP6464 Cloth Dyanmics Project

Due by 17:00 on Friday 25 May 2012

This assignment is worth 20% of your total course mark.

  • For COMP3320 students your assignment will be marked out of 20
  • For COMP6464 students your assignment will be marked out of 25
Details of how marks are assigned and what you are required to submit are given below.

This project extends the concepts introduced in assignment 1 to build a simulation of a cloth falling under gravity on a stationary spherical object. The cloth is modelled as a 2-D rectangular network, where node (x,y) (x and y are integers) in an (N*N) square network interacts with all other nodes (x+delta,y+delta) where delta is some (low value) integer. Thus if delta=1 a typical node will interact with 8 neigbouring nodes, while if delta=2 there are 24 interactions to consider. When a node is located on the cloth there may be fewer interactions. Thus in contrast to the MD simulation each node in the network interacts with a finite number of other nodes, making evaluation of the total interaction potential O(n), where n is the number of nodes.

Between each pair of nodes we define an interaction given by Hooke's law.

PE12 = K*(R12-Eq12)2
Fx12 = K*(R12-Eq12)*(X1-X2)/R12

Where K is the force constant determining how stiff the spring is, R12 is the Euclidean distance between the two nodes and Eq12 is the equilibrium distance between these two nodes. For example if node (1,1) and node (1,2) have Eq12=1*d then node (1,1) and node (2,2) have Eq12=sqrt(2)*d.

Each node we will assign a mass, noting that the force and accelaration are related by F=ma. The cloth is initially positioned in the xz plane and subjected to a gravitational force g in the y direction. As a consequence the cloth will slowly fall under gravity.

Positioned below the cloth is a ball of radius r, such that the centre of the cloth is located 1+r units above the centre of the ball. The cloth is allowed to fall under gravity until it collides with the ball. You follow the motions of the nodes using the same velocity verlet algorithm that you used for the MD. The difference arises when a node in the cloth hits the ball. You detect this by noticing that the updated position of the node is within the radius of the ball. At this point you move the node to the nearest point on the surface of the ball.


STEP 1: Cloth simulation in Python (1 mark)


    Here is the python code cloth1.py that performs this basic simulation. Download and run this code. Make sure you understand what this code is doing.

    As discussed in lectures, something is not quite right! If you inspect the code you will see that if the new coordinates for the cloth are within the ball, then that node of the cloth is moved back to the surface of the ball. This happens here

    	for node in nodes:
    		dist = node.pos-vector(myball.x,myball.y,myball.z)
    		if dist.mag < myball.radius:
    			fvector=dist/dist.mag*myball.radius
    			node.pos=vector(myball.x,myball.y,myball.z)+fvector
    
    A problem arises in that the velocity of the node remains the same. In this step modify the code such that the component of the velocity that is in the direction of fvector above is set to zero. In other words only the component of the velocity that is tangential to the surface is allowed to be non-zero following a collision of a cloth node with the ball. The objective of this step is to modify the Python code to solve this problem in the velocity computation.

    Step 1 Submission Requirements

    You are required to submit the modified cloth1.py code.

    • Your cloth1.py code will be tested on PARTCH - so make sure it works without errors on this machine.
    • Running of your code shall follow the options provided by typing python cloth1.py -h

    The marks for this step will be given based on the following:

    • compliance with submission process as detailed at end of this assignment;
    • whether your code can display structures correctly;

STEP 2: C and OpenGL implementation (8 marks)


    In this step, you are required to rewrite the cloth simulation code in C and embed it into an OpenGL routine. That is you should have an OpenGL front end that implement the interface and rendering functions, requesting your C functions to initialise and update the simulation. To facilitate this step, we have provided an OpenGL package, which contains the OpenGL code for rendering and control tasks, and an incomplete C code in which you should put your simulation functions in. Please download the package Here.

    Step 2 Submission Requirements

    Put your C code into the provided cloth.c file. Submit it together with the other files provided in the above mentiond package.

    • Your cloth.c code will be tested on PARTCH - so make sure it works without errors on this machine.
    • Running of your code shall allow the command line input options provided in opengl_stuff.c.

    The marks for this step will be given based on the following:

    • compliance with submission process as detailed at end of this assignment;
    • the readability and structure of your C code;
    • whether your code can complete the simulation tasks and display structures correctly.

STEP 3: Parallelising the cloth simulation and benchmarking(11 marks)


    The aim of this step is to parallelise the cloth simulation portion of your code that is written in C using OpenMP, and perform benchmark test on both Partch and XE. You are required to produce a pure C version of the simulation which can implement the functions in Step 2 but without display. Name this file cloth_c.c. Then, you should extend it to parallel version using OpenMP in a file named cloth_omp.c. You are required to add another input flag to your program denoted -p that reads in an integer that is used to set the maximum number of OpenMP threads used by your code.

    Run your OpenMP code on both partch and Xe. Provide a detailed comparison of the parallel performance on XE and on Partch.

    Step 3 Submission Requirements

    You are required to provide a single makefile for all versions of C source code that will build and run the cloth simulation on both XE and Partch for cloth_omp.c. The only difference between the two machines should be the instructions to make, eg make cloth_xe, or make cloth_partch, which shall generate exexutable files cloth_xe and cloth_partch. For non-parallelised version of the pure C code cloth_c.c, the makefile shall run as make cloth_c, and generate cloth_c (You can use difference compiling options for cloth_c.c on Partch and Xe. If you do so, please explain it in the README file). This details should be explained in your README file. Please note that running of your code shall accept command line input options as listed in opengl_stuff.c, and output per-iteration potential energy. The submission shall include a report titled Step3_Report.pdf (up to 4 A4 pages), which include performance analysis and comparison on the following topics

    • consideration of how your code scales as the number of threads increases and with problem size;
    • relate observed performance to what you have learnt in the course regarding Amdahl's law and thread synchronization;
    • comparison on speed of execution for non-parallelised and OpenMP versions of codes on Partch and XE;
    • influence of performance from hardware architectures;
    • discussion of TWO additional points that are NOT covered in the above.

    The marks for this step will be given based on the following:

    • compliance with submission process as detailed at end of this assignment;
    • the readability, structure and speed of your code;
    • consistency of the potential energy generated by your non-parallelised C code and that from the OpenGL/C version;
    • whether your OpenMP codes run correctly;
    • quality of interpretation and analysis of the results in terms of correctness, breadth and depth.

STEP 4: (COMP6464 ONLY): SSE Implemention


    In this step, you are required to explore SSE extension to further improve the performance of your cloth simulation code. Using the knowledge you have learned from the lecture and lab session, you are required to modify your non-parallelised C code to include SSE instructions, and run it on XE.

    Step 4 Submission Requirements

    Name your SSE version of the C code as cloth_sse.c. Submit it together with a makefile that can make it in XE System.

    • Your cloth_sse.c code will be tested on XE - so make sure it works without errors on this machine.
    • Please note that running of your code shall accept command line inputs as listed in opengl_stuff.c, and output per-iteration potential energy.

    You should write a report named Step4_Report.pdf(up to 2 A4 pages) to describe what you have done and compare the performance of the code before and after SSE has been applied.

    The marks for this step will be given based on the following:

    • correctness your code;
    • quality of your report in terms of correctness, breadth and depth.

BONUS STEP: Only if you complete the above steps to high standard


    You can gain 2 bonus marks (from 20 or 25) if you complete this section. These marks will add to your normal mark, with the latter capped at 20 (COMP3320) or 25 (COMNP6464). This section will NOT be marked unless you have completed the previous steps (1-3 for COMP3320, 1-4 for COMP6464) AND then only if you have obtained a mark of at least 12/20 for those steps.

    Your task here is to implement a concept of the cloth ripping based on the OpenGL/C code. To do this add another input parameter -R that reads in a floating point number greater than 1.0 that indicates how much one of the springs can extend before they break. Give this parameter a default value of 1.5. Here we assume that the level of interaction is 1. You have to define a data structure that stores the connectivity of neighboring nodes. Augment your code to render the simulation process, and print out the number of broken springs (along with the potential energy) if run in verbose mode. The visualisation can be implemented in two options:

    • (Simple option) In the noshade mode, change triangle primitives to line primitives for connection between nodes, then remove it if the connection is broken. Don't consider other display mode.
    • (Advance option) In all display modes, have the OpenGL code remove from the visualization any "convex" if any spring that connects any two of the four vertices is broken.

MARKING AND SUBMISSION


Submission Details

All your submitted code should include this header at the top:

    Name:
    Student Number:
    Course:
    Assignment Number:
    Name of this file:
    Lab Group:
    
    I declare that the material I am submitting in this file is entirely
    my own work. I have not collaborated with anyone to produce it, nor
    have I copied it, in part or in full, from work produced by someone else.
    I have not given access to this material to any other student in this course.
    

You are required to submit a tar file using the submit tool on one of the student computers:

    submit comp3320 cloth_project cloth.tar
or if you are a COMP6464 student
    submit comp6464 cloth_project cloth.tar
The tar file should expand to give the following:
  • a directory called YOURSTUDENTID_ass2_part1 (such as u1000000_ass2_part1) that contains cloth1.py, cloth.c, and the other files in the provided OpenGL package. This directory should also contains a plain text file called README that tells the users (me) exactly how to run your code.
  • a directory called YOURSTUDENTID_ass2_part2 which contains cloth_c.c, cloth_omp.c in step 3, and the Makefile. A README file shall be provided to explain how to run the codes. You also should put your Step3_Report.pdf here.
  • (COMP6464 student only:) a directory called YOURSTUDENTID_ass2_part3 that contains cloth_sse.c, a makefile, and Step4_Report.pdf.
  • a directory called YOURSTUDENTID_ass2_part4 that contains cloth2.c, opengl_stuff2.c, a makefile, a README, and the other supporting files for the bonus step if you have completed it.