1. Trang chủ
  2. » Luận Văn - Báo Cáo

A Parallel Algorithm based on Convexityfor the Computing of DelaunayTessellation

77 205 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 77
Dung lượng 1,53 MB

Nội dung

A Parallel Algorithm based on Convexityfor the Computing of DelaunayTessellation

VIETNAM NATIONAL UNIVERSITY, HANOI UNIVERSITY OF SCIENCE FACULTY OF MATHEMATICS, MECHANICS AND INFORMATICS ———–OOO———— DONG VAN VIET A Parallel Algorithm based on Convexity for the Computing of Delaunay Tessellation Undergraduate Thesis Advanced Undergraduate Program in Mathematics HANOI - 2012 VIETNAM NATIONAL UNIVERSITY, HANOI UNIVERSITY OF SCIENCE FACULTY OF MATHEMATICS, MECHANICS AND INFORMATICS ———–OOO———— DONG VAN VIET A Parallel Algorithm based on Convexity for the Computing of Delaunay Tessellation Undergraduate Thesis Advanced Undergraduate Program in Mathematics Instructor: Assoc Prof Dr Phan Thanh An Institute of Mathematics Vietnam Academy of Science and Technology HANOI - 2012 Acknowledgements This thesis is based on the following two papers: “A parallel algorithm based on convexity for the computing of Delaunay tessellation” (by Phan Thanh An and Le Hong Trang, published in Numerical Algorithms, Vol 59, No 3, pp 347-357, 2012) and “Spines for constructing convex hulls in 2D and their applications” (by Phan Thanh An, Dong Van Viet, and Dinh Thanh Giang, in preparation, 2012) In the process of doing this thesis, I received much important encouraging factor and support from university, teachers, family and friends I would like to thank those people who have contributed significantly to this thesis The work on this thesis could not have been started if it were not for the generous support and the detail guide provided by my instructor, Associate Professor Phan Thanh An I am indebted to his advice during time of writing this thesis He provided helpful feedback, support and valuable advice in writing this thesis This work was partially supported by the Center for High-Performance Computing I want to thank Associate Professor Nguyen Huu Dien, Master of Science Le Hoang Son, and Mr Pham Duy Linh, who kindly provided a chance me to execute an parallel program on parallel computer and supervised when the parallel program was executing I want to show my gratitude to all teachers from Faculty of Mathematics, Mechanics, and Informatics, who had taught me a lot of knowledge through four years Students at K1 Advanced Mathematics class have been extremely helpful in providing suggestions and constructive criticism during the preparation of the manuscript Outside Hanoi University of Science, there are many people who have provided me with their insightful comments and generously shared their document and knowledge I would like to thank, in particular, Miss Dinh Thanh Giang for her advice Finally, I want to thank to my family, mostly for their understanding of the time commitment necessary to write such a thesis To all of them I wishes to express my sincere gratitude Hanoi, October 28, 2012 Dong Van Viet List of Symbols ∠ Angle Triangle ∆ Diameter of a set of points µ Rounding unit θab The angle of a segment ab θ(ab, cd) The angle of two segments ab and cd ab The segment joining a and b CH(P ) The convex hull of a set of points P D A domain in Ed D(P ) The Delaunay tessellation of a set of points P Ed d-dimensional Euclidean space H A Delaunay path L Median line P A set of points Qi A monotonic sequence End of a proof 2D Two-dimensional space 3D Three-dimensional space Contents Acknowledgements List of Symbols Introduction Convex Sets and Convex Hulls 10 1.1 Geometric Preliminaries 10 1.2 Convex Sets and Convex Hulls 11 1.3 Algorithms for Computing Convex Hulls 13 1.4 Graham’s Convex Hull Algorithm 14 1.4.1 Pseudocode, Version A 14 1.4.2 Pseudocode, Version B 17 1.4.3 Implementation of Graham’s Convex Hull Algorithm 18 Spines for Constructing Convex Hulls in 2D 22 1.5.1 Arithmetic Model 22 1.5.2 Calculating Angles 23 1.5.3 Generating Monotonic Sequences 25 1.5.4 Extracting a Spine 27 1.5 Delaunay Triangulations 2.1 35 Delaunay Triangulations 35 2.1.1 Definition of Delaunay Triangulations 35 2.1.2 Basic Properties of Delaunay Triangulations 37 2.2 Algorithms for Computing Delaunay Triangulations 41 2.3 Delaunay Triangulations and Connection to Convex Hulls 42 2.4 Delaunay Triangulations and Restricted Areas 46 A Parallel Algorithm for Computing Delaunay Triangulations 51 3.1 Parallel Algorithms 51 3.2 Correctness and Implementation of the Parallel Algorithm 54 3.3 Remarks 55 Conclusion 57 Appendix A 58 Introduction to MPI Library 58 Getting Started with MPI on the Cluster 58 Compilation 58 Running MPI 59 The Basis of Writing MPI Programs 59 Initialization, Communicators, Handles, and Clean-Up 59 MPI Indispensable Functions 60 Example 63 Timing Programs 65 Debugging Methods 66 Appendix B 67 C Codes for Graham’s Convex Hull Algorithm 67 C Code for Computing Delaunay Triangulations 70 A Parallel Code for Computing Delaunay Triangulations 72 Appendix C 75 Center for High Performance Computing CPHC-HUS References 75 76 Introduction Computational geometry is a branch of computer science concerned with the design and analysis of algorithms to solve geometric problems (such as pattern recognition, computer graphics, operations research, computer-aided design, robotics, etc.) that require real-time speeds Until recently, these problems were solved using conventional sequential computer, computers whose design more or less follows the model proposed by John von Neumann and his team in the late 1940s (see [14]) The model consists of a single processor capable of executing exactly one instruction of a program during each time unit Computers built according to this paradigm have been able to perform at tremendous speeds However, it seems today that this approach has been pushed as far as it will go For example, the speed of light imposes a limit that cannot be surpassed by any electronic device On the other hand, our appetite appears to grow continually for ever more powerful computers capable of processing large amounts of data at great speeds One solution to this predicament that has recently gained credibility and popularity is parallel processing The main purpose of parallel processing is to perform computations faster than can be done with a single processor by using a number of processors concurrently A parallel computer is simply a collection of processors, typically of the same type, interconnected in a certain fashion to allow the coordination of their activities and the exchange of data (see [14]) In order to solve a problem efficiently on a parallel machine, it is usually necessary to design an algorithm that specifies multiple operations on each step, i.e., a parallel algorithm This algorithm can be executed a piece at a time on many different processors, and then put back together at the end to get the correct result MPI (Message Passing Interface) is one of the most popular library for messagepassing within a parallel program It is a standardized and portable message-passing system designed by a group of researchers from academia and industry to function on a wide variety of parallel computers The standard defines the syntax and semantics of a core of library routines useful to a wide range of users writing portable message-passing programs in Fortran or C/C++ In En , a Delaunay tessellation (i.e Delaunay triangulation in the plane) is an important problem in many domains, including pattern recognition, terrain modeling, and mesh generation for the solution of partial differential equations In many of these domains the tessellation is a bottleneck in the overall computation, making it important to develop fast algorithms As a result, there are many sequential algorithms available for Delaunay tessellation, along with efficient implementations (see [17, 20]) Among others, Aurenhammer et al.’s method based on a beautiful connection between Delaunay tessellation and convex hull in one higher dimension (see [7, 9, 12]) Since these sequential algorithms are time and memory intensive, parallel implementation are important both for improved performance and to allow the solution of problems that are too large for sequential machines However, although several parallel algorithms for Delaunay triangulation have been presented, practical implementations have been slower to appear (see [8]) For the convex hull problem in 2D and 3D, we find the convex hull boundary in the domain formed by a rectangular (or rectangular parallelepiped) Then the domain is restricted to a smaller domain, namely, restricted area to a simple detection rather than a complete computation (see [2, 3]) Recently, some problem in the area of computational geometry has focused on the numerical issues that arise when geometric algorithms are implemented using rounded floating point arithmetic Unlike other types of numerical algorithms, most geometric algorithms require that all arithmetic be performed over the field of reals or rationals, and they behave erratically when implemented with a non-associative number system such as rounded arithmetic The term robust has arisen to describe algorithms whose correctness is not spoiled by round-off error The assumption is we not “cheat”: each real varible in the algorithm is replaced by a floating point variable, and each real addition, subtraction, multiplication and division is replaced by a single corresponding floating point operation Clearly, robust algorithms are of great practical interest Section 1.5 present the first rounded arithmetic convex hull algorithm which guarantees a convex hull output and which has error independent of the number of input points ([16]) Some our initial results about spines are also presented in this section In this thesis, we present a parallel algorithm introduced by P.T An [5] based on divide-and-conquer strategy (see [14]) At each process of parallel algorithm, the Aurenhammer et al.’s method (the lift-up to the paraboloid of revolution) is used The convexity in the plane as a crucial factor of efficience of the new parallel algorithm over corresponding sequential algorithm is shown In particular, a restricted area obtained from a paraboloid given in [8] is used to discard non-Delaunay edges (Proposition 2.2) Some advantages of the parallel algorithm are shown Its implementation in plane is executed easily on both PC clusters and parallel computers (Section 3.2) Compare with a previous work, the resulting implementation (done at the Center for HighPerformance Computing, Hanoi University of Science [10]) significantly achieves better speedups over corresponding sequential code given in [18] (see Table 3.1) This thesis has three chapters and three appendices: Chapter 1: Convex Sets and Convex Hulls We deal with basis geometric preliminaries, convex set and convex hull notions This chapter shows some algorithms for computing convex hull and goes in detail for only Graham’s convex hull algorithm Li and Milenkovic’s concept of spines for a point set is presented We present some initial results about the use of spines for constructing convex hulls in 2D Chapter 2: Delaunay Triangulations Chapter majors on the definition of Delaunay triangulation and properties of Delaunay triangulation Then it deals with some algorithms for computing Delaunay triangulation This chapter also shows a beautiful connection between Delaunay tessellation and convex hulls in one higher dimension The so-called restricted area is presented Chapter 3: A Parallel Algorithm for Computing Delaunay Triangulations This chapter comes into contact with parallel algorithms The algorithms are executed on parallel computer and the results shows that the parallel algorithms run much faster Appendices: These appendices are designed to give a brief overview of some of the basis and important routines of MPI Library Some C codes are represented here These appendices also include some information about the IBM System Cluster 1350 of the Center for High-Performance Computing, Hanoi University of Science, which was used to execute the algorithms Some new initial results about the use of spines for constructing convex hulls in 2D were presented at the seminar of the Department of Numerical Analysis and Scientific Computing, Institute of Mathematics, Hanoi on October 10, 2012 Chapter Convex Sets and Convex Hulls The most ubiquitous structure in computational geometry is the convex hull It is useful in its own right and useful as a tool for constructing other structures in a wide variety of circumstances The construction of the convex hull, in two dimensions, is the subject of this chapter For the reader’s convenience, this chapter presents some basic geometrical notions that will be commonly used in this text 1.1 Geometric Preliminaries The objects considered in Computational Geometry are normally sets of points in Euclidean space A coordinate system of reference is assumed, so that each point is represented as a vector of cartesian coordinates of the appropriate dimension The geometric objects not necessarily consist of finite sets of points, but must comply with the convention to be finitely specifiable So we shall consider, besides individual points, the straight line containing two given points, the straight line segment defined by its two extreme points, the plane containing three given points, the polygon defined by an (ordered) sequence of points, etc This section has no pretence of providing formal definitions of the geometric concepts used in this paper; it has just the objectives of refreshing notions that are certainly known to the reader and of introducing the adopted notation (see [20], pp.17-19) A Cartesian coordinate system specifies each point uniquely in a plane by a pair of numerical coordinates, which are the signed distances from the point to two fixed perpendicular directed lines, measured in the same unit of length Each reference line is called a coordinate axis or just axis of the system, and the point where they meet is their origin, usually at ordered pair (0, 0) By Ed we denote the d−dimensional Euclidean space, i.e., the space of the d-tuples (x1 , , xd ) of real numbers xi , i = 1, , d with metric ( d 1/2 i=1 xi ) We shall now review the definition of the principal objects considered by Computational Geometry Point: A d-tuple (x1 , , xd ) denotes a point p of Ed ; this point may be also 10 comm - communicator (handle) h, MPI_Reduce This routine combines values on all processes into a single value using the operation defined by the parameter op int MPI_Reduce (void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) Input: sendbuf - address of send buffer (choice) count - number of elements in send buffer (integer) datatype - data type of elements of send buffer (handle) op - reduce operation (handle) comm - communication (handle) Output: recvbuf - address of receive buffer (choice, significant only at root) Example Consider this demo program: /*The Parallel Hello World Program*/ #include #include int main (int argc, char **argv) { int rank; MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &rank); printf ("Hello World form Node %d \n", rank); MPI_Finalize(); } To compile and execute this demo, we use the following commands: mpicc -o hello hello.c mpirun -np 10 hello 63 In the nutshell, this program sets up a communication group of processes, where each process gets its rank, prints it, and exits It is important for you to understand that in MPI, this program will start simultaneously on all machines For example, if we had ten machines, the running this program would mean that ten separate instances of this program would start running together on the different machines This is a fundamental difference from ordinary C programs, where, when someone said “run the program”, it was assumed that there was only one instance of the program running The first line, #include should be familiar to all C programmers It includes the standard input/output routines like printf The second line, #include includes the MPI functions The file mpi.h contains prototypes for all the MPI routines in this program; this file is located in usr/include/mpi/mpi.h in case you actually want to look at it The program starts with the main line which takes the usual two arguments argc and argv, and the program declares one integer variable, node The first step of the program, MPI_Init (&argc, &argv); Calls MPI_Init to initialize the MPI environment, and generally set up everything This should be the first command executed in all programs This routine takes pointers to argc and argv, looks at them, pulls out the purely MPI_relevan things, and generally fixed them so you can use command line arguments as normal Next, program runs MPI_Comm_rank, passing it an address to rank MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_rank will set node to the rank of the machine on which the program is running These process will each receive a unique number from MPI_Comm_rank Because the program is running on multiple machines, each will execute not only all of the command thus far explained, but also the hello world message printf, which includes their own rank printf("Hello World from Node %d ",rank); If the program is run on ten computers, printf is called ten times on the different machines silmultaneously The order in which each process executes the message is 64 undetermined, based on when they each reach that point in their execution of the program, and how they travel on the network So, the ten messages will get dumped to your screen in some undetermined order, such as: Hello World from Node Hello World from Node Hello World from Node Hello World from Node Hello World from Node Hello World from Node Hello World from Node Hello World from Node Hello World from Node Hello World from Node Note that all the printf’s, though they come from different machines, will send their output intact to your shell window; this is generally true of output commands Input commands, like scanf, will only work on the process with rank zero After doing everything else, the program call MPI_Finalize, which generally terminates everything and shuts down MPI This should be the last command executed in all programs Timing Programs For timing parallel programs, MPI includes the routine MPI_Wtime() which returns elapsed wall clock time in seconds The timer has no defined starting point, so in order to time something, two calls are needed and the difference should be taken between the returned times As a simple example, we can time each of the process in the “Hello World program” as below: /*Timing the Parallel Hello World Program*/ #include #include /*NOTE: The MPI_Wtime calls can be places anywhere between the MPI_Init and MPI_Finalize calls.*/ int main (int argc, char **argv) { int rank; double mytime; // declare a variable to hold the time returned MPI_Init (&argc, &argv); mytime = MPI_Wtime(); // get the time just before work to be timed 65 MPI_Comm_rank (MPI_COMM_WORLD, &rank); printf ("Hello World form Node %d \n", rank); mytime = MPI_Wtime() - mytime; printf ("Timing from node %d is %lf seconds.\n",rank, mytime); MPI_Finalize(); } Run this code by commands: mpicc -o hello hello.c mpirun -np hello And, what we may get is: Hello World form Node Timing from node is 0.000026 seconds Hello World form Node Timing from node is 0.000028 seconds Hello World form Node Timing from node is 0.000030 seconds Hello World form Node Timing from node is 0.000034 seconds Hello World form Node Timing from node is 0.000055 seconds Hello World form Node Timing from node is 0.000131 seconds Debugging Methods The following method is suggested for debugging MPI programs First, if possible, write the program as a serial program This will allow you to debug most syntax, logic, and indexing errors Then, modify the program and run it with 2-4 processes on the same machine This step will allow you to catch syntax and logic errors concerning intertask communication A common error found at this point is the use of non-unique message tags The final step in debugging your application is to run the same processes on different machines You should first try to find the bug using a few printf statements If some of these routines not run then you can find some where that the program doesn’t work So you can identify where the bug is 66 Appendix B C Codes for Graham’s Convex Hull Algorithm All of these codes presented here, from Code 1.1 to Code 1.8, can be found in [18, 19] Code 1.1 Point type #define X #define Y typedef enum {FALSE, TRUE} bool; #define DIM // Dimension of points typedef int tPointi[DIM]; // Type interger points Code 1.2 Points structure typedef struct tPointStructure tsPoint; typedef tsPoint *tPoint; struct tPointStructure { itn vnum; tPointi v; bool delete; }; #define PMAX 1000 // max # of points typedef tsPoint tPointArray[PMAX]; static tPointArry P; int n = 0; // Actual # of points int ndelete = 0; // Number deleted Code 1.3 Stack structure typedef struct tStackCell tsStack; typedef tsStack *tStack; struct tStackCell { tPoint p; tStack next; 67 }; Code 1.4 Stack routines tStack Pop( tStack s ) { tStack top; top = s->next; FREE( s ); return top; } tStack Push( tPoint p, tStack top ) { tStack s; //Get new cell and fill it with point NEW( s, tsStack ); s->p = p; s->next = top; return s; } void PrintStack( tStack t ) { if (!t) printf("Empty stack\n"); while (t) { printf("vnum=%d\tx=%d\ty=%d\n", t->p->vnum,t->p->v[X],t->p->v[Y]); t = t->next; } } Code 1.5 FindLowest void FindLowest( void ) { int i; int m = 0; // Index of lowest so far for ( i = 1; i < n; i++ ) if ( (P[i].v[Y] < P[m].v[Y]) || ((P[i].v[Y] == P[m].v[Y]) && (P[i].v[X] > P[m].v[X])) ) m = i; 68 printf("Swapping %d with 0\n", m); Swap(0,m); // Swap P[0] and P[m] } Code 1.6 main main() { tStack top; n = ReadPoints(); FindLowest(); qsort(&P[1], n-1 sizeof (tsPoint), comapre); Squash(); top = Graham(); PrintStack (tops); } Code 1.7 Squash void Squash( void ) { int i, j; i = 0; j = 0; while ( i < n ) { if ( !P[i].delete ) { // if not marked for deletion Copy( i, j ); // Copy P[i] to P[j] j++; } i++; } n = j; printf("After Squash: n=%d\n",n); PrintPoints(); } void Copy( int i, int j ) { P[j].v[X] = P[i].v[X]; P[j].v[Y] = P[i].v[Y]; P[j].vnum = P[i].vnum; P[j].delete = P[i].delete; 69 } Code 1.8 Graham tStack Graham() { tStack top; int i; tPoint p1, p2; // Top two points on stack top = NULL; // Initialize stack top = Push ( &P[0], top ); top = Push ( &P[1], top ); // Bottom two elements will never be removed i = 2; while ( i < n ) { printf("Stack at top of while loop, i=%d, vnum=%d:\n", i, P[i].vnum); PrintStack( top ); if( !top->next) printf("Error\n"),exit(EXIT_FAILURE); p1 = top->next->p; p2 = top->p; if ( Left( p1->v , p2->v, P[i].v ) ) { top = Push ( &P[i], top ); i++; } else top = Pop( top ); printf("Stack at bot of while loop, i=%d, vnum=%d:\n", i, P[i].vnum); PrintStack( top ); putchar(’\n’); } return top; } C Code for Computing Delaunay Triangulations Code 2.1 dt4 /* Implementation of Delaunay triangulation by 70 J O’Rourke, Computational Geometry in C, 1998 */ #include #define NMAX 1001 main() { int x[NMAX],y[NMAX],z[NMAX]; /* input points xy,z=x^2+y^2 */ int n; int i, j, k, m; /* indices of four points */ int xn, yn, zn; /* outward vector normal to (i,j,k) */ int flag; int F = 0; /* number of input points */ /* t if m above of (i,j,k) */ /* # of lower faces */ /* Input points and compute z = x^2 + y^2 */ scanf("%d", &n); for ( i = 0; i < n; i++ ) { scanf("%d %d", &x[i], &y[i]); z[i] = x[i] * x[i] + y[i] * y[i]; } for ( i = 0; i < n - 2; i++ ) for ( j = i + 1; j < n; j++ ) for ( k = i + 1; k < n; k++ ) if ( j != k ) { /* Compute normal to triangle (i,j,k) */ xn = (y[j]-y[i])*(z[k]-z[i]) - (y[k]-y[i])*(z[j]-z[i]); yn = (x[k]-x[i])*(z[j]-z[i]) - (x[j]-x[i])*(z[k]-z[i]); zn = (x[j]-x[i])*(y[k]-y[i]) - (x[k]-x[i])*(y[j]-y[i]); /* Only examine faces on bottom of paraboloid: zn < */ if ( flag = (zn < 0) ) for (m = 0; m < n; m++) /* Check if m above (i,j,k) */ flag = flag && ((x[m]-x[i])*xn + (y[m]-y[i])*yn + (z[m]-z[i])*zn

Ngày đăng: 08/11/2014, 11:18

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w