2011年12月14日

Compile and run SELFE on windows 32 bit

1. Compile and run parallel SELFE on windows

a. Compile metis and parallel metis using visual studio 2008. The MPI library use MSMPI. (make sure the MPI library is the same as SELFE mpi library)

b. Compile and run the SELFE program.

c. Working SELFE project: “SELFE_3.0b_WINDOWS_netcdf”.

d. The post processing program is tested by the lock exchange benchmark. The vertical profile of salinity is extract to TECPLOT format. A TECPLOT template is created and named as “salt.lay”.

2011年12月12日

计算几何算法概览 - GameRes.com

 

计算几何算法概览 - GameRes.com

计算几何算法概览


一、引言

计算机的出现使得很多原本十分繁琐的工作得以大幅度简化,但是也有一些在人们直观看来很容易的问题却需要拿出一套并不简单的通用解决方案,比如几何问题。作为计算机科学的一个分支,计算几何主要研究解决几何问题的算法。在现代工程和数学领域,计算几何在图形学、机器人技术、超大规模集成电路设计和统计等诸多领域有着十分重要的应用。在本文中,我们将对计算几何常用的基本算法做一个全面的介绍,希望对您了解并应用计算几何的知识解决问题起到帮助。

二、目录

本文整理的计算几何基本概念和常用算法包括如下内容:

矢量的概念

矢量加减法

矢量叉积

折线段的拐向判断

判断点是否在线段上

判断两线段是否相交

判断线段和直线是否相交

判断矩形是否包含点

判断线段、折线、多边形是否在矩形中

判断矩形是否在矩形中

判断圆是否在矩形中

判断点是否在多边形中

判断线段是否在多边形内

判断折线是否在多边形内

判断多边形是否在多边形内

判断矩形是否在多边形内

判断圆是否在多边形内

判断点是否在圆内

判断线段、折线、矩形、多边形是否在圆内

判断圆是否在圆内

计算点到线段的最近点

计算点到折线、矩形、多边形的最近点

计算点到圆的最近距离及交点坐标

计算两条共线的线段的交点

计算线段或直线与线段的交点

求线段或直线与折线、矩形、多边形的交点

求线段或直线与圆的交点

凸包的概念

凸包的求法

三、算法介绍

矢量的概念

如果一条线段的端点是有次序之分的,我们把这种线段成为有向线段(directed segment)。如果有向线段p1p2的起点p1在坐标原点,我们可以把它称为矢量(vector)p2。

矢量加减法

设二维矢量P = ( x1, y1 ),Q = ( x2 , y2 ),则矢量加法定义为: P + Q = ( x1 + x2 , y1 + y2 ),同样的,矢量减法定义为: P - Q = ( x1 - x2 , y1 - y2 )。显然有性质 P + Q = Q + P,P - Q = - ( Q - P )。

矢量叉积

计算矢量叉积是与直线和线段相关算法的核心部分。设矢量P = ( x1, y1 ),Q = ( x2, y2 ),则矢量叉积定义为由(0,0)、p1、p2和p1+p2所组成的平行四边形的带符号的面积,即:P × Q = x1*y2 - x2*y1,其结果是一个标量。显然有性质 P × Q = - ( Q × P ) 和 P × ( - Q ) = - ( P × Q )。一般在不加说明的情况下,本文下述算法中所有的点都看作矢量,两点的加减法就是矢量相加减,而点的乘法则看作矢量叉积。

叉积的一个非常重要性质是可以通过它的符号判断两矢量相互之间的顺逆时针关系:

若 P × Q > 0 , 则P在Q的顺时针方向。
若 P × Q < 0 , 则P在Q的逆时针方向。
若 P × Q = 0 , 则P与Q共线,但可能同向也可能反向。

折线段的拐向判断

折线段的拐向判断方法可以直接由矢量叉积的性质推出。对于有公共端点的线段p0p1和p1p2,通过计算(p2 - p0) × (p1 - p0)的符号便可以确定折线段的拐向:

若(p2 - p0) × (p1 - p0) > 0,则p0p1在p1点拐向右侧后得到p1p2。

若(p2 - p0) × (p1 - p0) < 0,则p0p1在p1点拐向左侧后得到p1p2。

若(p2 - p0) × (p1 - p0) = 0,则p0、p1、p2三点共线。

具体情况可参照下图:

判断点是否在线段上

设点为Q,线段为P1P2 ,判断点Q在该线段上的依据是:( Q - P1 ) × ( P2 - P1 ) = 0 且 Q 在以 P1,P2为对角顶点的矩形内。前者保证Q点在直线P1P2上,后者是保证Q点不在线段P1P2的延长线或反向延长线上,对于这一步骤的判断可以用以下过程实现:

ON-SEGMENT(pi,pj,pk)

if min(xi,xj) <= xk <= max(xi,xj) and min(yi,yj) <= yk <= max(yi,yj)

then return true;

else return false;

特别要注意的是,由于需要考虑水平线段和垂直线段两种特殊情况,min(xi,xj)<=xk<=max(xi,xj)和min(yi,yj)<=yk<=max(yi,yj)两个条件必须同时满足才能返回真值。

判断两线段是否相交

我们分两步确定两条线段是否相交:

(1)快速排斥试验

设以线段 P1P2 为对角线的矩形为R, 设以线段 Q1Q2 为对角线的矩形为T,如果R和T不相交,显然两线段不会相交。

(2)跨立试验
如果两线段相交,则两线段必然相互跨立对方。若P1P2跨立Q1Q2 ,则矢量 ( P1 - Q1 ) 和( P2 - Q1 )位于矢量( Q2 - Q1 ) 的两侧,即( P1 - Q1 ) × ( Q2 - Q1 ) * ( P2 - Q1 ) × ( Q2 - Q1 ) < 0。上式可改写成( P1 - Q1 ) × ( Q2 - Q1 ) * ( Q2 - Q1 ) × ( P2 - Q1 ) > 0。当 ( P1 - Q1 ) × ( Q2 - Q1 ) = 0 时,说明 ( P1 - Q1 ) 和 ( Q2 - Q1 )共线,但是因为已经通过快速排斥试验,所以 P1 一定在线段 Q1Q2上;同理,( Q2 - Q1 ) ×(P2 - Q1 ) = 0 说明 P2 一定在线段 Q1Q2上。所以判断P1P2跨立Q1Q2的依据是:( P1 - Q1 ) × ( Q2 - Q1 ) * ( Q2 - Q1 ) × ( P2 - Q1 ) >= 0。同理判断Q1Q2跨立P1P2的依据是:( Q1 - P1 ) × ( P2 - P1 ) * ( P2 - P1 ) × ( Q2 - P1 ) >= 0。具体情况如下图所示:

在相同的原理下,对此算法的具体的实现细节可能会与此有所不同,除了这种过程外,大家也可以参考《算法导论》上的实现。

判断线段和直线是否相交

有了上面的基础,这个算法就很容易了。如果线段P1P2和直线Q1Q2相交,则P1P2跨立Q1Q2,即:( P1 - Q1 ) × ( Q2 - Q1 ) * ( Q2 - Q1 ) × ( P2 - Q1 ) >= 0。

判断矩形是否包含点

只要判断该点的横坐标和纵坐标是否夹在矩形的左右边和上下边之间。

判断线段、折线、多边形是否在矩形中

因为矩形是个凸集,所以只要判断所有端点是否都在矩形中就可以了。

判断矩形是否在矩形中

只要比较左右边界和上下边界就可以了。

判断圆是否在矩形中

很容易证明,圆在矩形中的充要条件是:圆心在矩形中且圆的半径小于等于圆心到矩形四边的距离的最小值。

判断点是否在多边形中

判断点P是否在多边形中是计算几何中一个非常基本但是十分重要的算法。以点P为端点,向左方作射线L,由于多边形是有界的,所以射线L的左端一定在多边形外,考虑沿着L从无穷远处开始自左向右移动,遇到和多边形的第一个交点的时候,进入到了多边形的内部,遇到第二个交点的时候,离开了多边形,……所以很容易看出当L和多边形的交点数目C是奇数的时候,P在多边形内,是偶数的话P在多边形外。

但是有些特殊情况要加以考虑。如图下图(a)(b)(c)(d)所示。在图(a)中,L和多边形的顶点相交,这时候交点只能计算一个;在图(b)中,L和多边形顶点的交点不应被计算;在图(c)和(d) 中,L和多边形的一条边重合,这条边应该被忽略不计。如果L和多边形的一条边重合,这条边应该被忽略不计。

为了统一起见,我们在计算射线L和多边形的交点的时候,1。对于多边形的水平边不作考虑;2。对于多边形的顶点和L相交的情况,如果该顶点是其所属的边上纵坐标较大的顶点,则计数,否则忽略;3。对于P在多边形边上的情形,直接可判断P属于多边行。由此得出算法的伪代码如下:
count ← 0;
以P为端点,作从右向左的射线L;
for 多边形的每条边s
do if P在边s上
then return true;
if s不是水平的
then if s的一个端点在L上
if 该端点是s两端点中纵坐标较大的端点
then count ← count+1
else if s和L相交
then count ← count+1;
if count mod 2 = 1
then return true;
else return false;
其中做射线L的方法是:设P'的纵坐标和P相同,横坐标为正无穷大(很大的一个正数),则P和P'就确定了射线L。

判断点是否在多边形中的这个算法的时间复杂度为O(n)。

另外还有一种算法是用带符号的三角形面积之和与多边形面积进行比较,这种算法由于使用浮点数运算所以会带来一定误差,不推荐大家使用。

判断线段是否在多边形内

线段在多边形内的一个必要条件是线段的两个端点都在多边形内,但由于多边形可能为凹,所以这不能成为判断的充分条件。如果线段和多边形的某条边内交(两线段内交是指两线段相交且交点不在两线段的端点),因为多边形的边的左右两侧分属多边形内外不同部分,所以线段一定会有一部分在多边形外(见图a)。于是我们得到线段在多边形内的第二个必要条件:线段和多边形的所有边都不内交。

线段和多边形交于线段的两端点并不会影响线段是否在多边形内;但是如果多边形的某个顶点和线段相交,还必须判断两相邻交点之间的线段是否包含于多边形内部(反例见图b)。

因此我们可以先求出所有和线段相交的多边形的顶点,然后按照X-Y坐标排序(X坐标小的排在前面,对于X坐标相同的点,Y坐标小的排在前面,这种排序准则也是为了保证水平和垂直情况的判断正确),这样相邻的两个点就是在线段上相邻的两交点,如果任意相邻两点的中点也在多边形内,则该线段一定在多边形内。

证明如下:

命题1:
如果线段和多边形的两相邻交点P1 ,P2的中点P' 也在多边形内,则P1, P2之间的所有点都在多边形内。

证明:
假设P1,P2之间含有不在多边形内的点,不妨设该点为Q,在P1, P'之间,因为多边形是闭合曲线,所以其内外部之间有界,而P1属于多边行内部,Q属于多边性外部,P'属于多边性内部,P1-Q-P'完全连续,所以P1Q和QP'一定跨越多边形的边界,因此在P1,P'之间至少还有两个该线段和多边形的交点,这和P1P2是相邻两交点矛盾,故命题成立。证毕。

由命题1直接可得出推论:
推论2:
设多边形和线段PQ的交点依次为P1,P2,……Pn,其中Pi和Pi+1是相邻两交点,线段PQ在多边形内的充要条件是:P,Q在多边形内且对于i =1, 2,……, n-1,Pi ,Pi+1的中点也在多边形内。
在实际编程中,没有必要计算所有的交点,首先应判断线段和多边形的边是否内交,倘若线段和多边形的某条边内交则线段一定在多边形外;如果线段和多边形的每一条边都不内交,则线段和多边形的交点一定是线段的端点或者多边形的顶点,只要判断点是否在线段上就可以了。
至此我们得出算法如下:
if 线端PQ的端点不都在多边形内
then return false;
点集pointSet初始化为空;
for 多边形的每条边s
do if 线段的某个端点在s上
then 将该端点加入pointSet;
else if s的某个端点在线段PQ上
then 将该端点加入pointSet;
else if s和线段PQ相交 // 这时候已经可以肯定是内交了
then return false;
将pointSet中的点按照X-Y坐标排序;
for pointSet中每两个相邻点 pointSet[i] , pointSet[ i+1]
do if pointSet[i] , pointSet[ i+1] 的中点不在多边形中
then return false;
return true;
这个过程中的排序因为交点数目肯定远小于多边形的顶点数目n,所以最多是常数级的复杂度,几乎可以忽略不计。因此算法的时间复杂度也是O(n)。

判断折线是否在多边形内

只要判断折线的每条线段是否都在多边形内即可。设折线有m条线段,多边形有n个顶点,则该算法的时间复杂度为O(m*n)。

判断多边形是否在多边形内

只要判断多边形的每条边是否都在多边形内即可。判断一个有m个顶点的多边形是否在一个有n个顶点的多边形内复杂度为O(m*n)。

判断矩形是否在多边形内

将矩形转化为多边形,然后再判断是否在多边形内。

判断圆是否在多边形内

只要计算圆心到多边形的每条边的最短距离,如果该距离大于等于圆半径则该圆在多边形内。计算圆心到多边形每条边最短距离的算法在后文阐述。

判断点是否在圆内

计算圆心到该点的距离,如果小于等于半径则该点在圆内。

判断线段、折线、矩形、多边形是否在圆内

因为圆是凸集,所以只要判断是否每个顶点都在圆内即可。

判断圆是否在圆内

设两圆为O1,O2,半径分别为r1, r2,要判断O2是否在O1内。先比较r1,r2的大小,如果r1<r2则O2不可能在O1内;否则如果两圆心的距离大于r1 - r2 ,则O2不在O1内;否则O2在O1内。

计算点到线段的最近点

如果该线段平行于X轴(Y轴),则过点point作该线段所在直线的垂线,垂足很容易求得,然后计算出垂足,如果垂足在线段上则返回垂足,否则返回离垂足近的端点;如果该线段不平行于X轴也不平行于Y轴,则斜率存在且不为0。设线段的两端点为pt1和pt2,斜率为:k = ( pt2.y - pt1. y ) / (pt2.x - pt1.x );该直线方程为:y = k* ( x - pt1.x) + pt1.y。其垂线的斜率为 - 1 / k,垂线方程为:y = (-1/k) * (x - point.x) + point.y 。

联立两直线方程解得:x = ( k^2 * pt1.x + k * (point.y - pt1.y ) + point.x ) / ( k^2 + 1) ,y = k * ( x - pt1.x) + pt1.y;然后再判断垂足是否在线段上,如果在线段上则返回垂足;如果不在则计算两端点到垂足的距离,选择距离垂足较近的端点返回。

计算点到折线、矩形、多边形的最近点

只要分别计算点到每条线段的最近点,记录最近距离,取其中最近距离最小的点即可。

计算点到圆的最近距离及交点坐标

如果该点在圆心,因为圆心到圆周任一点的距离相等,返回UNDEFINED。

连接点P和圆心O,如果PO平行于X轴,则根据P在O的左边还是右边计算出最近点的横坐标为centerPoint.x - radius 或 centerPoint.x + radius。如果PO平行于Y轴,则根据P在O的上边还是下边计算出最近点的纵坐标为 centerPoint.y -+radius或 centerPoint.y - radius。如果PO不平行于X轴和Y轴,则PO的斜率存在且不为0,这时直线PO斜率为k = ( P.y - O.y )/ ( P.x - O.x )。直线PO的方程为:y = k * ( x - P.x) + P.y。设圆方程为:(x - O.x ) ^2 + ( y - O.y ) ^2 = r ^2,联立两方程组可以解出直线PO和圆的交点,取其中离P点较近的交点即可。

计算两条共线的线段的交点

对于两条共线的线段,它们之间的位置关系有下图所示的几种情况。图(a)中两条线段没有交点;图 (b) 和 (d) 中两条线段有无穷焦点;图 (c) 中两条线段有一个交点。设line1是两条线段中较长的一条,line2是较短的一条,如果line1包含了line2的两个端点,则是图(d)的情况,两线段有无穷交点;如果line1只包含line2的一个端点,那么如果line1的某个端点等于被line1包含的line2的那个端点,则是图(c)的情况,这时两线段只有一个交点,否则就是图(b)的情况,两线段也是有无穷的交点;如果line1不包含line2的任何端点,则是图(a)的情况,这时两线段没有交点。

计算线段或直线与线段的交点:

设一条线段为L0 = P1P2,另一条线段或直线为L1 = Q1Q2 ,要计算的就是L0和L1的交点。
1. 首先判断L0和L1是否相交(方法已在前文讨论过),如果不相交则没有交点,否则说明L0和L1一定有交点,下面就将L0和L1都看作直线来考虑。

2. 如果P1和P2横坐标相同,即L0平行于Y轴

a) 若L1也平行于Y轴,

i. 若P1的纵坐标和Q1的纵坐标相同,说明L0和L1共线,假如L1是直线的话他们有无穷的交点,假如L1是线段的话可用"计算两条共线线段的交点"的算法求他们的交点(该方法在前文已讨论过);
ii. 否则说明L0和L1平行,他们没有交点;

b) 若L1不平行于Y轴,则交点横坐标为P1的横坐标,代入到L1的直线方程中可以计算出交点纵坐标;

3. 如果P1和P2横坐标不同,但是Q1和Q2横坐标相同,即L1平行于Y轴,则交点横坐标为Q1的横坐标,代入到L0的直线方程中可以计算出交点纵坐标;

4. 如果P1和P2纵坐标相同,即L0平行于X轴

a) 若L1也平行于X轴,

i. 若P1的横坐标和Q1的横坐标相同,说明L0和L1共线,假如L1是直线的话他们有无穷的交点,假如L1是线段的话可用"计算两条共线线段的交点"的算法求他们的交点(该方法在前文已讨论过);
ii. 否则说明L0和L1平行,他们没有交点;

b) 若L1不平行于X轴,则交点纵坐标为P1的纵坐标,代入到L1的直线方程中可以计算出交点横坐标;

5. 如果P1和P2纵坐标不同,但是Q1和Q2纵坐标相同,即L1平行于X轴,则交点纵坐标为Q1的纵坐标,代入到L0的直线方程中可以计算出交点横坐标;

6. 剩下的情况就是L1和L0的斜率均存在且不为0的情况

a) 计算出L0的斜率K0,L1的斜率K1 ;

b) 如果K1 = K2

i. 如果Q1在L0上,则说明L0和L1共线,假如L1是直线的话有无穷交点,假如L1是线段的话可用"计算两条共线线段的交点"的算法求他们的交点(该方法在前文已讨论过);
ii. 如果Q1不在L0上,则说明L0和L1平行,他们没有交点。
c) 联立两直线的方程组可以解出交点来
这个算法并不复杂,但是要分情况讨论清楚,尤其是当两条线段共线的情况需要单独考虑,所以在前文将求两条共线线段的算法单独写出来。另外,一开始就先利用矢量叉乘判断线段与线段(或直线)是否相交,如果结果是相交,那么在后面就可以将线段全部看作直线来考虑。需要注意的是,我们可以将直线或线段方程改写为ax+by+c=0的形式,这样一来上述过程的部分步骤可以合并,缩短了代码长度,但是由于先要求出参数,这种算法将花费更多的时间。

求线段或直线与折线、矩形、多边形的交点

分别求与每条边的交点即可。

求线段或直线与圆的交点:

设圆心为O,圆半径为r,直线(或线段)L上的两点为P1,P2。

1. 如果L是线段且P1,P2都包含在圆O内,则没有交点;否则进行下一步。

2. 如果L平行于Y轴,

a) 计算圆心到L的距离dis;
b) 如果dis > r 则L和圆没有交点;
c) 利用勾股定理,可以求出两交点坐标,但要注意考虑L和圆的相切情况。
3. 如果L平行于X轴,做法与L平行于Y轴的情况类似;

4. 如果L既不平行X轴也不平行Y轴,可以求出L的斜率K,然后列出L的点斜式方程,和圆方程联立即可求解出L和圆的两个交点;

5. 如果L是线段,对于2,3,4中求出的交点还要分别判断是否属于该线段的范围内。

凸包的概念

点集Q的凸包(convex hull)是指一个最小凸多边形,满足Q中的点或者在多边形边上或者在其内。下图中由红色线段表示的多边形就是点集Q={p0,p1,...p12}的凸包。

凸包的求法

现在已经证明了凸包算法的时间复杂度下界是O(n*logn),但是当凸包的顶点数h也被考虑进去的话,Krikpatrick和Seidel的剪枝搜索算法可以达到O(n*logh),在渐进意义下达到最优。最常用的凸包算法是Graham扫描法和Jarvis步进法。本文只简单介绍一下Graham扫描法,其正确性的证明和Jarvis步进法的过程大家可以参考《算法导论》。

对于一个有三个或以上点的点集Q,Graham扫描法的过程如下:

令p0为Q中Y-X坐标排序下最小的点
设<p1,p2,...pm>为对其余点按以p0为中心的极角逆时针排序所得的点集(如果有多个点有相同的极角,除了距p0最远的点外全部移除
压p0进栈S
压p1进栈S
压p2进栈S
for i ← 3 to m
do while 由S的栈顶元素的下一个元素、S的栈顶元素以及pi构成的折线段不拐向左侧
对S弹栈
压pi进栈S
return S;

此过程执行后,栈S由底至顶的元素就是Q的凸包顶点按逆时针排列的点序列。需要注意的是,我们对点按极角逆时针排序时,并不需要真正求出极角,只需要求出任意两点的次序就可以了。而这个步骤可以用前述的矢量叉积性质实现。

四、结语

尽管人类对几何学的研究从古代起便没有中断过,但是具体到借助计算机来解决几何问题的研究,还只是停留在一个初级阶段,无论从应用领域还是发展前景来看,计算几何学都值得我们认真学习、加以运用,希望这篇文章能带你走进这个丰富多彩的世界。

判断两线段是否相交_yu000hong_新浪博客

 

判断两线段是否相交_yu000hong_新浪博客

2011年12月11日

build netcdf 4.1.1 on windows for 32 bit and 64 bit

1. download and install the HDF 32bit and 64bit system on windows (location: http://www.hdfgroup.org/HDF5/release/obtain5.html)

    • 32 bit HDF will install at : C:\Program Files (x86)\HDF Group\HDF5
    • 64 bit HDF will install at: C:\Program Files\HDF Group\HDF5

2. download the netcdf 4.1.1 for windows package at: ftp://ftp.unidata.ucar.edu/pub/netcdf/contrib/win32/netcdf-4.1.1-win32-src.zip

    • The visual studio solution are in “\win32\NET”

3. We only interested the C and Fortran library.

    • built C library, set the project properties of “netcdf”
      • 32 bit:
        • include : c:\Program Files (x86)\HDF Group\HDF5\1.8.8\include\
        • lib:c:\Program Files (x86)\HDF Group\HDF5\1.8.8\lib\
        • linked library: hdf5.lib hdf5_hl.lib libzlib.lib libszip.lib
        • set runtime library as:Multi-threaded DLL (/MD)
        • built
      • 64 bit:
        • include : c:\Program Files\HDF Group\HDF5\1.8.8\include\
        • lib:c:\Program Files\HDF Group\HDF5\1.8.8\lib\
        • linked library: hdf5.lib hdf5_hl.lib libzlib.lib libszip.lib
        • set runtime library as:Multi-threaded DLL (/MD)
        • built
    • For fortran library :
      • Create library fortran project name: netcdf_f90
      • Copy all the f90 source code in “netcdf-4.1.1\f90” to the project folder.
      • add “netcdf4.f90” and “typeSizes.f90”
        • 32bit: build
        • 64bit: build
      • the library “netcdf_f90.lib will be generate” and include two mod file “netcdf.mod” and “typesizes.mod”

4. Finished.

Project saved location: skydriver

1. netcdf 4.1.1 source code and the c libary and fortran library;

2. the build include file and library.

2011年12月2日

Word Blog - Equation Numbering

 

Equation Numbering

byWord Team

on October 20

In this post, I'm going to talk about equation numbering, one of our most highly-requested features. Setting up your equation numbering for easy one-click entry takes a few steps, so bear with me. You have to go through this process only once, and after that, you'll be able to insert equation numbers with just one click. Feel free to read the steps below, watch the video demos instead, or do both!

Step 1: Insert a 3x1 table. Your equation numbers can go in the leftmost or rightmost column, and your equation should be placed in the middle column.

Step 2: Next, you'll want to make sure your table is laid out properly, to ensure that your equation is centered horizontally on the page, and your equation numbers are centered vertically with respect to the equation. This step has a few sub-steps:

  1. With your IP in the table, click on the Layout contextual tab, and then click on the dialog launcher for Cell Size.

  2. On the "Table" tab, set the Preferred Width to 100%. This ensures your table takes up the whole width of the page.

  3. On the "Column" tab, set your columns to have the following widths:
      Column1 = 15%
      Column2 = 70%
      Column3 = 15%

  4. Determine if you want your equation numbers to the left or right of the equation. For the cell (left or right) you've designated for your equation numbers, on the "Cell" tab, select Center under Vertical Alignment.

  5. Don't forget to hide the table borders. If you want to see the table boundaries, choose "Show Gridlines" on the Borders dropdown.

Step 3: Place your IP in the cell where you'd like to type your equation numbers, and start a Multi-level list. You may want to change list level, so that your equations are of the level 1.1. instead of 1. You may also choose to define a new Multi-Level list, so that you can add parentheses and remove punctuation.

Step 4: Adjust the spacing after the table, to match the spacing after setting in the previous paragraph. If the previous paragraph has 10 pts as its "After" setting, you'll want to make sure your new paragraph also has 10 pts after. Otherwise, your equation will not be vertically centered between the preceding and following paragraphs.

Step 5: Insert a Placeholder equation. You can do this by clicking in the middle cell and choosing Insert | Equation, or by using the Alt+= shortcut key.

Step 6: Now you are ready to save your equation for easy reuse! Select the entire table, and on the Equation dropdown menu, choose "Save Selection to Equation Gallery." Give your equation a name, such as Numbered Equation. From this point forward, you will be able to insert numbered equations from the equation gallery.

In this video, I'll demonstrate how to customize equation numbers to match your chapter headings.

Word Blog - Equation Numbering

Compile, Link, Run and Debug FORTRAN MPI Programs Using Microsoft Visual Studio

From:

http://wiki.rcs.manchester.ac.uk/community/MPI/VisualStudio_mpich2_howto

RCS How-To: Compile, Link, Run and Debug FORTRAN MPI Programs Using Microsoft Visual Studio

Test-system(s) used: VMware virtual machine of WinXP x64 Pro, MS Visual Studio 2008 with Intel Visual Fortran 11.0.047 running mpich2

Installation

For the 64 bit test system, care has to be taken regarding compatibility of components one wishes to use together. Given only a 32 bit Visual Studio (VS) 2008 is available for free to Univ of Manchester researchers, a 32 bit version of mpich2 is used. We downloaded the 32 bit Windows binary from the mpich2 web site. (Using 64 bit mpich2 gives link time errors.)

Following the mpich2 for MS Windows instructions (see README.winbin.rtf) we add the relevant mpich2 include and library components to a VS project's build. For VS 2008 this is as follows; for other versions the actual locations vary. We presume you're aware of how to set parameters for your chosen build/project/configuration.

  • add the full path of mpich2 include directory (eg C:\Program Files (x86)\MPICH2\include) to the VS include path (Configuration Properties - Fortran - General - Additional Include Directories)
  • add the full path of mpich2 library directory (eg C:\Program Files (x86)\MPICH2\lib) to the VS library path (Configuration Properties - Linker - General - Additional Library Directories)
  • add the name of the relevant mpich2 library file to the VS link command using the Additional Dependencies (Configuration Properties - Linker - Input - Additional Dependencies). The mpich2 library file to use for the Intel Fortran compiler is fmpich2.lib

You should now be able to compile and link, or to build, a Fortran MPI program.

Launching MPI from Visual Studio

Rather than running the newly created executable, known to VS as $(TargetPath), we wish to launch mpiexec.exe and pass that the required mpich2 parameters and the executable. This can be achieved by

  • setting the launch command (Configuration Properties - Debugging - Command) to the full path for mpiexec.exe (eg C:\Program Files (x86)\MPICH2\bin\mpiexec.exe)
  • setting the arguments (Configuration Properties - Debugging - Command Arguments) to -n 2 $(TargetPath)

Then the MPI executable can be launched from VS by Debug - Start Without Debugging (Ctrl+F5). (Debug - Start Debugging (F5) also works but VS complains there's no debugging information for the mpiexec.exe itself)

NB if you try and use breakpoints etc it appears not to honour these - see below for how to debug.

Troubleshooting

These are just some of the problems you may see. For an exhaustive list please search the Internet.

You can now run your MPI program. If you see only one MPI process then you may not have launched the MPI processes correctly. You can check whether you program behaves as expecting by opening a terminal window (eg Start - Run - cmd) and then manually launching using {fullpath/}mpiexec.exe -n {num} {fullpath/}your.exe

If prompted for a username/password this will be the username/password used to authenticate to login to Windows. You can use mpiexec to register username/passwords. From a terminal window use mpiexec.exe -help2 for the full help on mpiexec.

If you get an error regarding inablity to connect it may due to MS Windows (or other) firewall settings. You may also occasionally need to start the mpich2 process manager (smpd.exe in the mpich2 bin directory) manually. As per Windows, a restart may help.

The VS Output window may occasionally show "First-chance exception at 0x7d4e237e in mpiexec.exe: 0x000006C5: The tag is invalid." but it appears these can be ignored.

Debugging Fortran MPI Using Visual Studio

by attaching to a currently running process (one VS window for all selected MPI processes)

This is a generic method and gives you one VS debugging window but you can move between MPI processes

  • compile, link and start running your MPI program (you may wish to put a read statement early on to hold the program while you do the next steps)
  • attach to one of the currently running MPI processes: Debug - Attach to Process brings up a dialogue box which lists Available Processes. You should see NUM instances (where N is from mpiexec -n NUM) of your executable. Select all of these and click on Attach. You can now debug by adding breakpoints etc. To move between MPI processes use the Process drop-down menu just above the code listing.
launching VS from mpiexec (one VS window per MPI process)

Firstly, having compiled and linked (or built) your executable (project), close all VS application windows. From a terminal window

  • stop any running mpich2 process manager: {mpich2/bin/}smpd.exe -stop
  • start smpd in debug mode: {mpich2/bin/}smpd.exe -d O (or just -d if you're happy to see debugging messages (-d NUM is the level of debugging))

Open another terminal window we can now launch the VS executable on each MPI process with the following command (this is one command and shouldn't be split over lines but your browser may reformat):

"c:\Program Files (x86)\MPICH2\bin\mpiexec.exe" -n 2 "c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" "c:\Program Files (x86)\MPICH2\examples\Debug\fpi.exe"

where you should use the path to your mpiexec.exe and to your VS executable (devenv.exe} and to the required executable (or Fortran file or project) This will give you two (or NUM if you use -n NUM) VS applications, one for each thread. You can then debug as normal - you will have to manually start each debugging thread and you may have to "Break All" to bring up the source code for adding break and watch points.

More Information

The above was compiled by trial, error and help from the mpich2 team.

For further help and discussion

2011年11月27日

Windows中的文件硬连接

 

Windows中的文件硬连接 (2008-03-17 20:01)

分类: Windows

硬连接的确是一个很实用的功能,在不同目录中共享同一个文件时这显得很有用,特别是文件比较大的时候,可以节约不少空间,也可以完成使用创建"快捷方式"不能完成的功能.

使用fsutil命令来实现,创建硬连接只是其中的一个功能.使用示例,如图所示:

1、只能用于NTFS文件系统上面。 2、不能跨卷创建硬连接

goat - ChinaUnix博客 - IT人与你分享快乐生活

2011年11月22日

Compile PPM library and SPH code in CETO

1. The compilation of Metis library can’t pass in CETO, this is maybe the icc is not set properly

2. The compilation of PPM library is not test in CETO. The compiled lib under linux: libppm.a and libmetis.a is used in CETO, didn’t recompiled.

3. The Makefile of SPH code is generated by mfmk, and the template is “mfmk_template_CETO” as following, the Makefile is generated in folder name “build”, the following script “perl mkmf -t mfmk_template_CETO ../src” is used to generate the make file:

# template for the Intel fortran compiler version with mpich2
# typical use with mkmf:
#-------------------------------------------------------
# perl mkmf -t mkmf_template  ../src_prec_source
#------------------------------------------------------
# compiler to compile the source code.
FC = /opt/mpich2/mpich2-1.0.8-intel/bin/mpif90 -fpp
# compiler to link the source doe.
LD = /opt/mpich2/mpich2-1.0.8-intel/bin/mpif90 -fpp
CPPDEFS    =
CPPFLAGS   =
FPPFLAGS   =
#define the include files.
#FFLAGS     =  -g  -heap-arrays -O3  -axCORE-AVX2 -I/home/tmsxh/Desktop/hostshare/PPM_library_Linux/libppm-1.2.1/include/ppm
FFLAGS     = -O3 -heap-arrays -O3 -I/data1/tmsxh/SPH/PPM_library_Linux/libppm-1.2.1/include/ppm
OTHERFLAGS =
LDFLAGS    =
# add your libraries after LIBS= , e.g. -lblas
#LIBS = c:/mingw/lib
MKLLIB = -L /opt/intel/Compiler/11.1/038/mkl/lib/em64t -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5
#MKLLIB = /opt/intel/mkl/lib/intel64/libmkl_intel_lp64.a  /opt/intel/mkl/lib/intel64/libmkl_intel_thread.a /opt/intel/mkl/lib/#intel64/libmkl_core.a -liomp5
#LIBS = -L/home/tmsxh/ppm/ppm-1.0.1/lib -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6 -lppm -lmetis -lvizing  ${MKLLIB}
LIBS = -L/data1/tmsxh/SPH/PPM_library_Linux/libppm-1.2.1/lib -lppm -lmetis ${MKLLIB}
LDFLAGS    = $(LIBS)

2011年11月19日

Create the Makefile for fortran program by mkmf

The fortran program need the Makefile to build under linx. There are several Makefile generate on the web. The mkmf is the one used to build the SPH code.

1. Download the mkmf from the website: http://www.gfdl.noaa.gov/~vb/mkmf.html

2. Create a template for mkmf, which define the compiler, pre-processor (CPP,FPP), include path and library path and so on. The sample template is sown below, file name “mkmf_template” :

# template for the Intel fortran compiler version with mpich2
# typical use with mkmf:
#-------------------------------------------------------
# perl mkmf -t mkmf_template ../src_prec_source
#------------------------------------------------------
# compiler to compile the source code.
FC = mpif90 -fpp
# compiler to link the source doe.
LD = mpif90 -fpp
CPPDEFS    =
CPPFLAGS   =
FPPFLAGS   =
#define the include files.
#FFLAGS     =  -g  -heap-arrays -O3  -axSSE4.2 -I/home/tmsxh/Desktop/hostshare/PPM_library_Linux/libppm-1.2.1/include/ppm
FFLAGS     =   -g  -heap-arrays -I/home/tmsxh/Desktop/hostshare/PPM_library_Linux/libppm-1.2.1/include/ppm
OTHERFLAGS =
LDFLAGS    =
# add your libraries after LIBS= , e.g. -lblas
#LIBS = c:/mingw/lib
MKLLIB = -L/opt/intel/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5
#MKLLIB = /opt/intel/mkl/lib/intel64/libmkl_intel_lp64.a  /opt/intel/mkl/lib/intel64/libmkl_intel_thread.a /opt/intel/mkl/lib/#intel64/libmkl_core.a -liomp5
#LIBS = -L/home/tmsxh/ppm/ppm-1.0.1/lib -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6 -lppm -lmetis -lvizing  ${MKLLIB}
LIBS = -L/home/tmsxh/Desktop/hostshare/PPM_library_Linux/libppm-1.2.1/lib -lppm -lmetis ${MKLLIB}
LDFLAGS    = $(LIBS)

3. generate the make file by : perl mkmf -t mkmf_template ../src_prec_source

3.1 “-t mfmk_template” : specify the template file;
3.2 “../src_prec_source ” : specify the folder the fortran code located.

4. make ; to generate the code.

Compile the PPM library version 1.0.1 and 1.2.1 on Linux

COMPILE PPM 1.0
    1. compile vizing:
        1.1 vizing is written by older c++ standard, hence the latest version of g++ can't work,
                2.1 the g++ version 34 "g++34" is employed to compile the code.
    2. compile the metis library.
        2.1 the metis include the the ppm-1.0.1 has problem to compile, the error is related to __log2. The error message is "/usr/include/bits/mathcalls.h:145: note: previous declaration of ‘__log2’ was here". Hence, use the metis library download from the PPM, address: http://www.ppm-library.org/index.php/download
        2.2 replace the metis by metis4 and copy the library to "libmetis.a"
    3. install fftw3
        3.1 download fftw3 from : http://www.fftw.org/download.html
        3.2 unpack the fftw3 by: tar xvzf fftw-3*.tar.gz
        3.3 configure the fftw3 : ./configure
                3.4 make the fftw3  : make
                3.4 install the fftw3: sudo make install
                3.5 the detail procedure can see INSTALL
    3. compile the PPM library.
        3.1 set the file in Make.userprefs: change FC as the setting mpif90
                     e.g : FC:=/usr/bin/mpif90
        3.2 set the FFTWDIR ( check where the FFTW installed by the following command :
                         rpm -ql fftw )
             e.g : FC:=/home/tmsxh/fftw-3.3
        3.3 change the compiler flag in ppm_define.h
                3.4 in order to get the preporcessed source file of PPM libaray comment the following line                 in file "Makefile.static", the program will not remove the preporcessed fortran file.
                   #    @rm $(OBJ_DIR)/__$*.f
                the preprocessed fortran code are stored in folder
COMPLIE PPM 1.2
    1. install the metis libaray.
    2. configure the library before compile by: ./configure --enable-mpi=mpich2 FC=/usr/bin/mpif90 --enable-linux LDFLAGS=-L./metis4/lib
        2.1 –enable-mpi= mpich2 : specify the mpich2 is employed as mpi library;
        2.2 FC = /usr/bin/mpif90  : specify the fortran MPI compiler; the mpif90 need to configured, before compile the PPM library;
        2.3 LDFLAGS=                : specify the location of metis library and other library.
    3. compile the PPM library by : make
    4. install the PPm library by  : sudo make install   
        the install will copy the “include” library to: /usr/local/include/ppm 
                                           and “library” to : /usr/local/lib

2011年8月11日

MPICH2 安装

1。launch command windows use administrator account. type: msiexec /i MPICH2 *** to install the MPICH2.
2。register the user account by mpiexec -register
3.reference :
http://lists.mcs.anl.gov/pipermail/mpich-discuss/2005-September/000768.html
install guide

2011年3月19日

SMPD 在windows 下的设置与安装

安装好MPICH2时,有时不能运行MPI job。 因为smpd没有正确的设置,可以这样设置:
1。以管理员身份登陆,停止 smpd: smpd -stop
2。重新安装smpd: smpd -phrase behappy -install
就可以了