mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add Chapel parallel programming language.
Includes several example programs from source distribution.
This commit is contained in:
@@ -347,6 +347,14 @@ Ceylon:
|
||||
extensions:
|
||||
- .ceylon
|
||||
|
||||
Chapel:
|
||||
type: programming
|
||||
color: "#8dc63f"
|
||||
aliases:
|
||||
- chpl
|
||||
extensions:
|
||||
- .chpl
|
||||
|
||||
ChucK:
|
||||
lexer: Java
|
||||
extensions:
|
||||
|
||||
@@ -83,6 +83,9 @@
|
||||
"Ceylon": [
|
||||
".ceylon"
|
||||
],
|
||||
"Chapel": [
|
||||
".chpl"
|
||||
],
|
||||
"Cirru": [
|
||||
".cirru"
|
||||
],
|
||||
@@ -792,8 +795,8 @@
|
||||
"exception.zep.php"
|
||||
]
|
||||
},
|
||||
"tokens_total": 650233,
|
||||
"languages_total": 870,
|
||||
"tokens_total": 659840,
|
||||
"languages_total": 875,
|
||||
"tokens": {
|
||||
"ABAP": {
|
||||
"*/**": 1,
|
||||
@@ -16278,6 +16281,798 @@
|
||||
"<=>": 1,
|
||||
"other.name": 1
|
||||
},
|
||||
"Chapel": {
|
||||
"//": 150,
|
||||
"use": 5,
|
||||
"BlockDist": 2,
|
||||
"CyclicDist": 1,
|
||||
"BlockCycDist": 1,
|
||||
"ReplicatedDist": 2,
|
||||
";": 516,
|
||||
"DimensionalDist2D": 2,
|
||||
"ReplicatedDim": 2,
|
||||
"BlockCycDim": 1,
|
||||
"config": 10,
|
||||
"const": 59,
|
||||
"n": 16,
|
||||
"Space": 12,
|
||||
"{": 122,
|
||||
"}": 120,
|
||||
"BlockSpace": 2,
|
||||
"dmapped": 8,
|
||||
"Block": 4,
|
||||
"(": 626,
|
||||
"boundingBox": 2,
|
||||
")": 626,
|
||||
"var": 72,
|
||||
"BA": 3,
|
||||
"[": 920,
|
||||
"]": 920,
|
||||
"int": 21,
|
||||
"forall": 43,
|
||||
"ba": 4,
|
||||
"in": 76,
|
||||
"do": 62,
|
||||
"here.id": 7,
|
||||
"writeln": 53,
|
||||
"MyLocaleView": 5,
|
||||
"#numLocales": 1,
|
||||
"MyLocales": 5,
|
||||
"locale": 1,
|
||||
"reshape": 2,
|
||||
"Locales": 6,
|
||||
"BlockSpace2": 2,
|
||||
"targetLocales": 1,
|
||||
"BA2": 3,
|
||||
"CyclicSpace": 2,
|
||||
"Cyclic": 1,
|
||||
"startIdx": 2,
|
||||
"Space.low": 5,
|
||||
"CA": 3,
|
||||
"ca": 2,
|
||||
"BlkCycSpace": 2,
|
||||
"BlockCyclic": 1,
|
||||
"blocksize": 1,
|
||||
"BCA": 3,
|
||||
"bca": 2,
|
||||
"ReplicatedSpace": 2,
|
||||
"RA": 11,
|
||||
"ra": 4,
|
||||
"RA.numElements": 1,
|
||||
"A": 13,
|
||||
"i": 250,
|
||||
"j": 25,
|
||||
"i*100": 1,
|
||||
"+": 334,
|
||||
"on": 7,
|
||||
"here": 3,
|
||||
"LocaleSpace.high": 3,
|
||||
"nl1": 2,
|
||||
"nl2": 2,
|
||||
"if": 98,
|
||||
"numLocales": 5,
|
||||
"then": 80,
|
||||
"else": 16,
|
||||
"numLocales/2": 1,
|
||||
"#nl1": 2,
|
||||
"#nl2": 1,
|
||||
"#nl1*nl2": 1,
|
||||
"DimReplicatedBlockcyclicSpace": 2,
|
||||
"new": 7,
|
||||
"BlockCyclicDim": 1,
|
||||
"lowIdx": 1,
|
||||
"blockSize": 1,
|
||||
"DRBA": 3,
|
||||
"for": 36,
|
||||
"locId1": 2,
|
||||
"drba": 2,
|
||||
"Helper": 2,
|
||||
"print": 5,
|
||||
"to": 9,
|
||||
"the": 10,
|
||||
"console": 1,
|
||||
"Time": 2,
|
||||
"get": 3,
|
||||
"timing": 6,
|
||||
"routines": 1,
|
||||
"benchmarking": 1,
|
||||
"block": 1,
|
||||
"-": 345,
|
||||
"distributed": 1,
|
||||
"arrays": 6,
|
||||
"luleshInit": 1,
|
||||
"initialization": 1,
|
||||
"code": 1,
|
||||
"data": 1,
|
||||
"set": 4,
|
||||
"param": 25,
|
||||
"useBlockDist": 5,
|
||||
"CHPL_COMM": 1,
|
||||
"use3DRepresentation": 4,
|
||||
"false": 4,
|
||||
"useSparseMaterials": 3,
|
||||
"true": 5,
|
||||
"printWarnings": 3,
|
||||
"&&": 9,
|
||||
"luleshInit.filename": 1,
|
||||
"halt": 5,
|
||||
"initialEnergy": 2,
|
||||
"e": 84,
|
||||
"initial": 1,
|
||||
"energy": 5,
|
||||
"value": 1,
|
||||
"showProgress": 3,
|
||||
"time": 9,
|
||||
"and": 4,
|
||||
"dt": 14,
|
||||
"values": 1,
|
||||
"each": 1,
|
||||
"step": 1,
|
||||
"debug": 8,
|
||||
"various": 1,
|
||||
"info": 1,
|
||||
"doTiming": 4,
|
||||
"main": 3,
|
||||
"timestep": 1,
|
||||
"loop": 2,
|
||||
"printCoords": 2,
|
||||
"final": 1,
|
||||
"computed": 1,
|
||||
"coordinates": 2,
|
||||
"XI_M": 2,
|
||||
"XI_M_SYMM": 4,
|
||||
"XI_M_FREE": 3,
|
||||
"XI_P": 2,
|
||||
"c": 7,
|
||||
"XI_P_SYMM": 3,
|
||||
"XI_P_FREE": 3,
|
||||
"ETA_M": 2,
|
||||
"ETA_M_SYMM": 4,
|
||||
"ETA_M_FREE": 3,
|
||||
"ETA_P": 2,
|
||||
"c0": 1,
|
||||
"ETA_P_SYMM": 3,
|
||||
"ETA_P_FREE": 3,
|
||||
"ZETA_M": 2,
|
||||
"ZETA_M_SYMM": 4,
|
||||
"ZETA_M_FREE": 3,
|
||||
"ZETA_P": 2,
|
||||
"xc00": 1,
|
||||
"ZETA_P_SYMM": 3,
|
||||
"ZETA_P_FREE": 3,
|
||||
"numElems": 2,
|
||||
"numNodes": 1,
|
||||
"initProblemSize": 1,
|
||||
"ElemSpace": 4,
|
||||
"#elemsPerEdge": 3,
|
||||
"#numElems": 1,
|
||||
"NodeSpace": 4,
|
||||
"#nodesPerEdge": 3,
|
||||
"#numNodes": 1,
|
||||
"Elems": 45,
|
||||
"Nodes": 16,
|
||||
"x": 111,
|
||||
"y": 107,
|
||||
"z": 107,
|
||||
"real": 60,
|
||||
"nodesPerElem": 6,
|
||||
"elemToNode": 7,
|
||||
"nodesPerElem*index": 1,
|
||||
"lxim": 3,
|
||||
"lxip": 3,
|
||||
"letam": 3,
|
||||
"letap": 3,
|
||||
"lzetam": 3,
|
||||
"lzetap": 3,
|
||||
"index": 4,
|
||||
"XSym": 4,
|
||||
"YSym": 4,
|
||||
"ZSym": 4,
|
||||
"sparse": 3,
|
||||
"subdomain": 3,
|
||||
"u_cut": 5,
|
||||
"hgcoef": 1,
|
||||
"qstop": 2,
|
||||
"monoq_max_slope": 7,
|
||||
"monoq_limiter_mult": 7,
|
||||
"e_cut": 3,
|
||||
"p_cut": 6,
|
||||
"ss4o3": 1,
|
||||
"/3.0": 2,
|
||||
"q_cut": 2,
|
||||
"v_cut": 2,
|
||||
"qlc_monoq": 2,
|
||||
"qqc_monoq": 2,
|
||||
"qqc": 1,
|
||||
"qqc2": 1,
|
||||
"*": 260,
|
||||
"qqc**2": 1,
|
||||
"eosvmax": 14,
|
||||
"eosvmin": 9,
|
||||
"pmin": 7,
|
||||
"emin": 7,
|
||||
"dvovmax": 1,
|
||||
"refdens": 3,
|
||||
"deltatimemultlb": 1,
|
||||
"deltatimemultub": 1,
|
||||
"dtmax": 1,
|
||||
"stoptime": 3,
|
||||
"maxcycles": 3,
|
||||
"max": 2,
|
||||
"dtfixed": 2,
|
||||
"MatElems": 9,
|
||||
"MatElemsType": 2,
|
||||
"enumerateMatElems": 2,
|
||||
"proc": 44,
|
||||
"type": 1,
|
||||
"return": 15,
|
||||
"Elems.type": 1,
|
||||
"iter": 3,
|
||||
"yield": 3,
|
||||
"elemBC": 16,
|
||||
"p": 10,
|
||||
"pressure": 1,
|
||||
"q": 13,
|
||||
"ql": 3,
|
||||
"linear": 1,
|
||||
"term": 2,
|
||||
"qq": 3,
|
||||
"quadratic": 1,
|
||||
"v": 9,
|
||||
"//relative": 1,
|
||||
"volume": 21,
|
||||
"vnew": 9,
|
||||
"volo": 5,
|
||||
"reference": 1,
|
||||
"delv": 3,
|
||||
"m_vnew": 1,
|
||||
"m_v": 1,
|
||||
"vdov": 4,
|
||||
"derivative": 1,
|
||||
"over": 2,
|
||||
"arealg": 2,
|
||||
"elem": 3,
|
||||
"characteristic": 2,
|
||||
"length": 2,
|
||||
"ss": 2,
|
||||
"elemMass": 4,
|
||||
"mass": 12,
|
||||
"xd": 8,
|
||||
"yd": 8,
|
||||
"zd": 8,
|
||||
"velocities": 2,
|
||||
"xdd": 3,
|
||||
"ydd": 3,
|
||||
"zdd": 3,
|
||||
"acceleration": 1,
|
||||
"fx": 8,
|
||||
"fy": 8,
|
||||
"fz": 8,
|
||||
"atomic": 2,
|
||||
"forces": 1,
|
||||
"nodalMass": 3,
|
||||
"current": 1,
|
||||
"deltatime": 3,
|
||||
"variable": 1,
|
||||
"increment": 1,
|
||||
"dtcourant": 1,
|
||||
"e20": 2,
|
||||
"courant": 1,
|
||||
"constraint": 2,
|
||||
"dthydro": 1,
|
||||
"change": 2,
|
||||
"cycle": 5,
|
||||
"iteration": 1,
|
||||
"count": 1,
|
||||
"simulation": 1,
|
||||
"initLulesh": 2,
|
||||
"st": 4,
|
||||
"getCurrentTime": 4,
|
||||
"while": 4,
|
||||
"<": 42,
|
||||
"iterTime": 2,
|
||||
"TimeIncrement": 2,
|
||||
"LagrangeLeapFrog": 1,
|
||||
"deprint": 3,
|
||||
"format": 9,
|
||||
"et": 3,
|
||||
"/cycle": 1,
|
||||
"outfile": 1,
|
||||
"open": 1,
|
||||
"iomode.cw": 1,
|
||||
"writer": 1,
|
||||
"outfile.writer": 1,
|
||||
"fmtstr": 4,
|
||||
"writer.writeln": 1,
|
||||
"writer.close": 1,
|
||||
"outfile.close": 1,
|
||||
"initCoordinates": 1,
|
||||
"initElemToNodeMapping": 1,
|
||||
"initGreekVars": 1,
|
||||
"initXSyms": 1,
|
||||
"initYSyms": 1,
|
||||
"initZSyms": 1,
|
||||
"//calculated": 1,
|
||||
"fly": 1,
|
||||
"using": 1,
|
||||
"elemToNodes": 3,
|
||||
"initMasses": 2,
|
||||
"octantCorner": 2,
|
||||
"initBoundaryConditions": 2,
|
||||
"massAccum": 3,
|
||||
"eli": 18,
|
||||
"x_local": 11,
|
||||
"y_local": 11,
|
||||
"z_local": 11,
|
||||
"*real": 40,
|
||||
"localizeNeighborNodes": 6,
|
||||
"CalcElemVolume": 3,
|
||||
"neighbor": 2,
|
||||
".add": 1,
|
||||
".read": 1,
|
||||
"/": 26,
|
||||
"surfaceNode": 8,
|
||||
"mask": 16,
|
||||
"<<": 2,
|
||||
"&": 18,
|
||||
"f": 4,
|
||||
"|": 14,
|
||||
"xf0": 4,
|
||||
"xcc": 4,
|
||||
"check": 3,
|
||||
"loc": 4,
|
||||
"maxloc": 1,
|
||||
"reduce": 2,
|
||||
"zip": 1,
|
||||
"freeSurface": 3,
|
||||
"initFreeSurface": 1,
|
||||
"b": 4,
|
||||
"inline": 5,
|
||||
"ref": 19,
|
||||
"noi": 4,
|
||||
"TripleProduct": 4,
|
||||
"x1": 1,
|
||||
"y1": 1,
|
||||
"z1": 1,
|
||||
"x2": 1,
|
||||
"y2": 1,
|
||||
"z2": 1,
|
||||
"x3": 1,
|
||||
"y3": 1,
|
||||
"z3": 1,
|
||||
"x1*": 1,
|
||||
"y2*z3": 1,
|
||||
"z2*y3": 1,
|
||||
"x2*": 1,
|
||||
"z1*y3": 1,
|
||||
"y1*z3": 1,
|
||||
"x3*": 1,
|
||||
"y1*z2": 1,
|
||||
"z1*y2": 1,
|
||||
"dx61": 2,
|
||||
"dy61": 2,
|
||||
"dz61": 2,
|
||||
"dx70": 2,
|
||||
"dy70": 2,
|
||||
"dz70": 2,
|
||||
"dx63": 2,
|
||||
"dy63": 2,
|
||||
"dz63": 2,
|
||||
"dx20": 2,
|
||||
"dy20": 2,
|
||||
"dz20": 2,
|
||||
"dx50": 2,
|
||||
"dy50": 2,
|
||||
"dz50": 2,
|
||||
"dx64": 2,
|
||||
"dy64": 2,
|
||||
"dz64": 2,
|
||||
"dx31": 2,
|
||||
"dy31": 2,
|
||||
"dz31": 2,
|
||||
"dx72": 2,
|
||||
"dy72": 2,
|
||||
"dz72": 2,
|
||||
"dx43": 2,
|
||||
"dy43": 2,
|
||||
"dz43": 2,
|
||||
"dx57": 2,
|
||||
"dy57": 2,
|
||||
"dz57": 2,
|
||||
"dx14": 2,
|
||||
"dy14": 2,
|
||||
"dz14": 2,
|
||||
"dx25": 2,
|
||||
"dy25": 2,
|
||||
"dz25": 2,
|
||||
"InitStressTermsForElems": 1,
|
||||
"sigxx": 2,
|
||||
"sigyy": 2,
|
||||
"sigzz": 2,
|
||||
"D": 9,
|
||||
"CalcElemShapeFunctionDerivatives": 2,
|
||||
"b_x": 18,
|
||||
"b_y": 18,
|
||||
"b_z": 18,
|
||||
"fjxxi": 5,
|
||||
".125": 9,
|
||||
"fjxet": 6,
|
||||
"fjxze": 5,
|
||||
"fjyxi": 5,
|
||||
"fjyet": 6,
|
||||
"fjyze": 5,
|
||||
"fjzxi": 5,
|
||||
"fjzet": 6,
|
||||
"fjzze": 5,
|
||||
"cjxxi": 5,
|
||||
"cjxet": 6,
|
||||
"cjxze": 5,
|
||||
"cjyxi": 5,
|
||||
"cjyet": 6,
|
||||
"cjyze": 5,
|
||||
"cjzxi": 5,
|
||||
"cjzet": 6,
|
||||
"cjzze": 5,
|
||||
"CalcElemNodeNormals": 1,
|
||||
"pfx": 15,
|
||||
"pfy": 15,
|
||||
"pfz": 15,
|
||||
"ElemFaceNormal": 7,
|
||||
"n1": 23,
|
||||
"n2": 23,
|
||||
"n3": 23,
|
||||
"n4": 23,
|
||||
"bisectX0": 3,
|
||||
"bisectY0": 3,
|
||||
"bisectZ0": 3,
|
||||
"bisectX1": 3,
|
||||
"bisectY1": 3,
|
||||
"bisectZ1": 3,
|
||||
"areaX": 5,
|
||||
"areaY": 5,
|
||||
"areaZ": 5,
|
||||
"rx": 6,
|
||||
"ry": 6,
|
||||
"rz": 6,
|
||||
"//results": 1,
|
||||
"SumElemStressesToNodeForces": 1,
|
||||
"stress_xx": 2,
|
||||
"stress_yy": 2,
|
||||
"stress_zz": 2,
|
||||
"CalcElemVolumeDerivative": 1,
|
||||
"VoluDer": 9,
|
||||
"n0": 13,
|
||||
"n5": 13,
|
||||
"ox": 1,
|
||||
"oy": 1,
|
||||
"oz": 1,
|
||||
"ox/12.0": 1,
|
||||
"oy/12.0": 1,
|
||||
"oz/12.0": 1,
|
||||
"dvdx": 10,
|
||||
"dvdy": 10,
|
||||
"dvdz": 10,
|
||||
"CalcElemFBHourglassForce": 1,
|
||||
"hourgam": 7,
|
||||
"coefficient": 4,
|
||||
"hgfx": 2,
|
||||
"hgfy": 2,
|
||||
"hgfz": 2,
|
||||
"hx": 3,
|
||||
"hy": 3,
|
||||
"hz": 3,
|
||||
"shx": 3,
|
||||
"shy": 3,
|
||||
"shz": 3,
|
||||
"CalcElemCharacteristicLength": 2,
|
||||
"AreaFace": 7,
|
||||
"p0": 7,
|
||||
"p1": 7,
|
||||
"p2": 7,
|
||||
"p3": 7,
|
||||
"gx": 5,
|
||||
"gy": 5,
|
||||
"gz": 5,
|
||||
"area": 2,
|
||||
"charLength": 2,
|
||||
"sqrt": 10,
|
||||
"CalcElemVelocityGradient": 2,
|
||||
"xvel": 25,
|
||||
"yvel": 25,
|
||||
"zvel": 25,
|
||||
"detJ": 5,
|
||||
"d": 12,
|
||||
"inv_detJ": 10,
|
||||
"dyddx": 2,
|
||||
"dxddy": 2,
|
||||
"dzddx": 2,
|
||||
"dxddz": 2,
|
||||
"dzddy": 2,
|
||||
"dyddz": 2,
|
||||
"CalcPressureForElems": 4,
|
||||
"p_new": 17,
|
||||
"bvc": 15,
|
||||
"pbvc": 14,
|
||||
"e_old": 7,
|
||||
"compression": 10,
|
||||
"vnewc": 22,
|
||||
"c1s": 3,
|
||||
"abs": 8,
|
||||
"//impossible": 1,
|
||||
"targetdt": 1,
|
||||
"//don": 1,
|
||||
"t": 3,
|
||||
"have": 2,
|
||||
"negative": 2,
|
||||
"determ": 1,
|
||||
"can": 2,
|
||||
"we": 1,
|
||||
"be": 2,
|
||||
"able": 1,
|
||||
"write": 1,
|
||||
"these": 1,
|
||||
"as": 1,
|
||||
"follows": 1,
|
||||
"CalcVelocityForNodes": 1,
|
||||
"local": 8,
|
||||
"xdtmp": 4,
|
||||
"ydtmp": 4,
|
||||
"zdtmp": 4,
|
||||
"CalcPositionForNodes": 1,
|
||||
"ijk": 7,
|
||||
"CalcLagrangeElements": 1,
|
||||
"dxx": 6,
|
||||
"dyy": 6,
|
||||
"dzz": 6,
|
||||
"CalcKinematicsForElems": 2,
|
||||
"k": 20,
|
||||
"vdovthird": 4,
|
||||
"<=>": 7,
|
||||
"0": 5,
|
||||
"all": 1,
|
||||
"elements": 3,
|
||||
"8": 4,
|
||||
"6": 1,
|
||||
"nodal": 2,
|
||||
"from": 2,
|
||||
"global": 3,
|
||||
"copy": 2,
|
||||
"into": 3,
|
||||
"xd_local": 4,
|
||||
"yd_local": 4,
|
||||
"zd_local": 4,
|
||||
"dt2": 4,
|
||||
"5": 1,
|
||||
"wish": 1,
|
||||
"this": 2,
|
||||
"was": 1,
|
||||
"too": 1,
|
||||
"calculations": 1,
|
||||
"relativeVolume": 3,
|
||||
"1": 2,
|
||||
"put": 1,
|
||||
"velocity": 3,
|
||||
"gradient": 3,
|
||||
"quantities": 1,
|
||||
"their": 1,
|
||||
"2": 1,
|
||||
"3": 1,
|
||||
"sungeun": 1,
|
||||
"Temporary": 1,
|
||||
"array": 4,
|
||||
"reused": 1,
|
||||
"throughout": 1,
|
||||
"delv_xi": 12,
|
||||
"delv_eta": 12,
|
||||
"delv_zeta": 12,
|
||||
"position": 1,
|
||||
"delx_xi": 7,
|
||||
"delx_eta": 7,
|
||||
"delx_zeta": 7,
|
||||
"CalcQForElems": 1,
|
||||
"MONOTONIC": 1,
|
||||
"Q": 1,
|
||||
"option": 1,
|
||||
"Calculate": 1,
|
||||
"gradients": 2,
|
||||
"CalcMonotonicQGradientsForElems": 2,
|
||||
"Transfer": 2,
|
||||
"veloctiy": 1,
|
||||
"first": 1,
|
||||
"order": 1,
|
||||
"problem": 1,
|
||||
"commElements": 1,
|
||||
"CommElements": 1,
|
||||
"monoQ": 1,
|
||||
"*/": 1,
|
||||
"CalcMonotonicQForElems": 2,
|
||||
"ApplyMaterialPropertiesForElems": 1,
|
||||
"matelm": 2,
|
||||
"vc": 6,
|
||||
"exit": 1,
|
||||
"EvalEOSForElems": 2,
|
||||
"UpdateVolumesForElems": 1,
|
||||
"tmpV": 4,
|
||||
"ptiny": 9,
|
||||
"xl": 26,
|
||||
"yl": 26,
|
||||
"zl": 26,
|
||||
"xvl": 26,
|
||||
"yvl": 26,
|
||||
"zvl": 26,
|
||||
"vol": 5,
|
||||
"norm": 20,
|
||||
"ax": 7,
|
||||
"ay": 7,
|
||||
"az": 7,
|
||||
"dxv": 4,
|
||||
"dyv": 4,
|
||||
"dzv": 4,
|
||||
"dxj": 1,
|
||||
"dyj": 1,
|
||||
"dzj": 1,
|
||||
"dxi": 1,
|
||||
"dyi": 1,
|
||||
"dzi": 1,
|
||||
"dxk": 1,
|
||||
"dyk": 1,
|
||||
"dzk": 1,
|
||||
"dyi*dzj": 1,
|
||||
"dzi*dyj": 1,
|
||||
"dzi*dxj": 1,
|
||||
"dxi*dzj": 1,
|
||||
"dxi*dyj": 1,
|
||||
"dyi*dxj": 1,
|
||||
"ax*ax": 3,
|
||||
"ay*ay": 3,
|
||||
"az*az": 3,
|
||||
"ax*dxv": 3,
|
||||
"ay*dyv": 3,
|
||||
"az*dzv": 3,
|
||||
"dyj*dzk": 1,
|
||||
"dzj*dyk": 1,
|
||||
"dzj*dxk": 1,
|
||||
"dxj*dzk": 1,
|
||||
"dxj*dyk": 1,
|
||||
"dyj*dxk": 1,
|
||||
"dyk*dzi": 1,
|
||||
"dzk*dyi": 1,
|
||||
"dzk*dxi": 1,
|
||||
"dxk*dzi": 1,
|
||||
"dxk*dyi": 1,
|
||||
"dyk*dxi": 1,
|
||||
"//got": 1,
|
||||
"rid": 1,
|
||||
"of": 3,
|
||||
"call": 1,
|
||||
"through": 1,
|
||||
"bcMask": 7,
|
||||
"delvm": 27,
|
||||
"delvp": 27,
|
||||
"select": 6,
|
||||
"when": 18,
|
||||
"phixi": 10,
|
||||
"phieta": 10,
|
||||
"phizeta": 10,
|
||||
"qlin": 4,
|
||||
"qquad": 4,
|
||||
"delvxxi": 4,
|
||||
"delvxeta": 4,
|
||||
"delvxzeta": 4,
|
||||
"rho": 3,
|
||||
"delvxxi**2": 1,
|
||||
"phixi**2": 1,
|
||||
"delvxeta**2": 1,
|
||||
"phieta**2": 1,
|
||||
"delvxzeta**2": 1,
|
||||
"phizeta**2": 1,
|
||||
"rho0": 8,
|
||||
"delvc": 11,
|
||||
"p_old": 8,
|
||||
"q_old": 7,
|
||||
"compHalfStep": 8,
|
||||
"qq_old": 7,
|
||||
"ql_old": 7,
|
||||
"work": 5,
|
||||
"e_new": 25,
|
||||
"q_new": 11,
|
||||
"vchalf": 2,
|
||||
"CalcEnergyForElems": 2,
|
||||
"CalcSoundSpeedForElems": 2,
|
||||
"sixth": 2,
|
||||
"pHalfStep": 5,
|
||||
"vhalf": 1,
|
||||
"ssc": 18,
|
||||
"vhalf**2": 1,
|
||||
"q_tilde": 4,
|
||||
"**2": 6,
|
||||
"enewc": 2,
|
||||
"pnewc": 2,
|
||||
"ssTmp": 4,
|
||||
"elemToNodesTuple": 1,
|
||||
"title": 2,
|
||||
"string": 1,
|
||||
"pi": 1,
|
||||
"solarMass": 7,
|
||||
"pi**2": 1,
|
||||
"daysPerYear": 13,
|
||||
"record": 1,
|
||||
"body": 6,
|
||||
"pos": 5,
|
||||
"does": 1,
|
||||
"not": 1,
|
||||
"after": 1,
|
||||
"it": 1,
|
||||
"is": 1,
|
||||
"up": 1,
|
||||
"bodies": 8,
|
||||
"numbodies": 5,
|
||||
"bodies.numElements": 1,
|
||||
"initSun": 2,
|
||||
"writef": 2,
|
||||
"advance": 2,
|
||||
"b.v": 2,
|
||||
"b.mass": 1,
|
||||
".v": 1,
|
||||
"updateVelocities": 2,
|
||||
"b1": 2,
|
||||
"b2": 2,
|
||||
"dpos": 4,
|
||||
"b1.pos": 2,
|
||||
"b2.pos": 2,
|
||||
"mag": 3,
|
||||
"sumOfSquares": 4,
|
||||
"**3": 1,
|
||||
"b1.v": 2,
|
||||
"b2.mass": 2,
|
||||
"b2.v": 1,
|
||||
"b1.mass": 3,
|
||||
"b.pos": 1,
|
||||
"Random": 1,
|
||||
"random": 1,
|
||||
"number": 1,
|
||||
"generation": 1,
|
||||
"Timer": 2,
|
||||
"class": 1,
|
||||
"timer": 2,
|
||||
"sort": 1,
|
||||
"**15": 1,
|
||||
"size": 1,
|
||||
"sorted": 1,
|
||||
"thresh": 6,
|
||||
"recursive": 1,
|
||||
"depth": 1,
|
||||
"serialize": 1,
|
||||
"verbose": 7,
|
||||
"out": 1,
|
||||
"many": 1,
|
||||
"bool": 1,
|
||||
"disable": 1,
|
||||
"numbers": 1,
|
||||
"fillRandom": 1,
|
||||
"timer.start": 1,
|
||||
"pqsort": 4,
|
||||
"timer.stop": 1,
|
||||
"timer.elapsed": 1,
|
||||
"arr": 32,
|
||||
"low": 12,
|
||||
"arr.domain.low": 1,
|
||||
"high": 14,
|
||||
"arr.domain.high": 1,
|
||||
"where": 2,
|
||||
"arr.rank": 2,
|
||||
"bubbleSort": 2,
|
||||
"pivotVal": 9,
|
||||
"findPivot": 2,
|
||||
"pivotLoc": 3,
|
||||
"partition": 2,
|
||||
"serial": 1,
|
||||
"cobegin": 1,
|
||||
"mid": 7,
|
||||
"ilo": 9,
|
||||
"ihi": 6,
|
||||
"low..high": 2
|
||||
},
|
||||
"Cirru": {
|
||||
"print": 38,
|
||||
"array": 14,
|
||||
@@ -70803,6 +71598,7 @@
|
||||
"COBOL": 90,
|
||||
"CSS": 43867,
|
||||
"Ceylon": 50,
|
||||
"Chapel": 9607,
|
||||
"Cirru": 244,
|
||||
"Clojure": 510,
|
||||
"CoffeeScript": 2951,
|
||||
@@ -71003,6 +71799,7 @@
|
||||
"COBOL": 4,
|
||||
"CSS": 2,
|
||||
"Ceylon": 1,
|
||||
"Chapel": 5,
|
||||
"Cirru": 9,
|
||||
"Clojure": 7,
|
||||
"CoffeeScript": 9,
|
||||
@@ -71179,5 +71976,5 @@
|
||||
"fish": 3,
|
||||
"wisp": 1
|
||||
},
|
||||
"md5": "b82e97a2c9c123d8e370eeffe64a1a1d"
|
||||
"md5": "4c7029e118ceca989e36b7f3c025a771"
|
||||
}
|
||||
304
samples/Chapel/distributions.chpl
Normal file
304
samples/Chapel/distributions.chpl
Normal file
@@ -0,0 +1,304 @@
|
||||
//
|
||||
// Distributions Primer
|
||||
//
|
||||
// This primer demonstrates uses of some of Chapel's standard
|
||||
// distributions. To use these distributions in a Chapel program,
|
||||
// the respective module must be used:
|
||||
//
|
||||
use BlockDist, CyclicDist, BlockCycDist, ReplicatedDist;
|
||||
use DimensionalDist2D, ReplicatedDim, BlockCycDim;
|
||||
|
||||
//
|
||||
// For each distribution, we'll create a distributed domain and array
|
||||
// and then initialize it just to give a brief flavor of how the
|
||||
// distribution maps across locales. Running this example on 6
|
||||
// locales does a nice job of illustrating the distribution
|
||||
// characteristics.
|
||||
//
|
||||
// All of these distributions support options to map to a different
|
||||
// virtual locale grid than the one used by default (a
|
||||
// multidimensional factoring of the built-in Locales array), as well
|
||||
// as to control the amount of parallelism used in data parallel
|
||||
// loops. See the Standard Distributions chapter of the language spec
|
||||
// for more details.
|
||||
//
|
||||
|
||||
//
|
||||
// Make the program size configurable from the command line.
|
||||
//
|
||||
config const n = 8;
|
||||
|
||||
//
|
||||
// Declare a 2-dimensional domain Space that we will later use to
|
||||
// initialize the distributed domains.
|
||||
//
|
||||
const Space = {1..n, 1..n};
|
||||
|
||||
//
|
||||
// The Block distribution distributes a bounding box from
|
||||
// n-dimensional space across the target locale array viewed as an
|
||||
// n-dimensional virtual locale grid. The bounding box is blocked
|
||||
// into roughly equal portions across the locales. Note that domains
|
||||
// declared over a Block distribution can also store indices outside
|
||||
// of the bounding box; the bounding box is merely used to compute
|
||||
// the blocking of space.
|
||||
//
|
||||
// In this example, we declare a 2-dimensional Block-distributed
|
||||
// domain BlockSpace and a Block-distributed array BA declared over
|
||||
// the domain.
|
||||
//
|
||||
const BlockSpace = Space dmapped Block(boundingBox=Space);
|
||||
var BA: [BlockSpace] int;
|
||||
|
||||
//
|
||||
// To illustrate how the index set is distributed across locales,
|
||||
// we'll use a forall loop to initialize each array element to the
|
||||
// locale ID that stores that index/element/iteration.
|
||||
//
|
||||
forall ba in BA do
|
||||
ba = here.id;
|
||||
|
||||
//
|
||||
// Output the Block-distributed array to visually see how the elements
|
||||
// are partitioned across the locales.
|
||||
//
|
||||
writeln("Block Array Index Map");
|
||||
writeln(BA);
|
||||
writeln();
|
||||
|
||||
//
|
||||
// Most of Chapel's standard distributions support an optional
|
||||
// targetLocales argument that permits you to pass in your own
|
||||
// array of locales to be targeted. In general, the targetLocales
|
||||
// argument should match the rank of the distribution. So for
|
||||
// example, to map a Block to a [numLocales x 1] view of the
|
||||
// locale set, one could do something like this:
|
||||
|
||||
//
|
||||
// We start by creating our own array of the locale values. Here
|
||||
// we use the standard array reshape function for convenience,
|
||||
// but more generally, this array could be accessed/assigned like any
|
||||
// other.
|
||||
//
|
||||
|
||||
var MyLocaleView = {0..#numLocales, 1..1};
|
||||
var MyLocales: [MyLocaleView] locale = reshape(Locales, MyLocaleView);
|
||||
|
||||
//
|
||||
// Then we'll declare a distributed domain/array that targets
|
||||
// this view of the locales:
|
||||
//
|
||||
|
||||
const BlockSpace2 = Space dmapped Block(boundingBox=Space,
|
||||
targetLocales=MyLocales);
|
||||
var BA2: [BlockSpace2] int;
|
||||
|
||||
//
|
||||
// Then we'll do a similar computation as before to verify where
|
||||
// everything ended up:
|
||||
//
|
||||
forall ba in BA2 do
|
||||
ba = here.id;
|
||||
|
||||
writeln("Block Array Index Map");
|
||||
writeln(BA2);
|
||||
writeln();
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Next, we'll perform a similar computation for the Cyclic distribution.
|
||||
// Cyclic distributions start at a designated n-dimensional index and
|
||||
// distribute the n-dimensional space across an n-dimensional array
|
||||
// of locales in a round-robin fashion (in each dimension). As with
|
||||
// the Block distribution, domains may be declared using the
|
||||
// distribution who have lower indices that the starting index; that
|
||||
// value should just be considered a parameterization of how the
|
||||
// distribution is defined.
|
||||
//
|
||||
const CyclicSpace = Space dmapped Cyclic(startIdx=Space.low);
|
||||
var CA: [CyclicSpace] int;
|
||||
|
||||
forall ca in CA do
|
||||
ca = here.id;
|
||||
|
||||
writeln("Cyclic Array Index Map");
|
||||
writeln(CA);
|
||||
writeln();
|
||||
|
||||
|
||||
//
|
||||
// Next, we'll declare a Block-Cyclic distribution. These
|
||||
// distributions also deal out indices in a round-robin fashion,
|
||||
// but rather than dealing out singleton indices, they deal out blocks
|
||||
// of indices. Thus, the BlockCyclic distribution is parameterized
|
||||
// by a starting index (as with Cyclic) and a block size (per
|
||||
// dimension) specifying how large the chunks to be dealt out are.
|
||||
//
|
||||
const BlkCycSpace = Space dmapped BlockCyclic(startIdx=Space.low,
|
||||
blocksize=(2, 3));
|
||||
var BCA: [BlkCycSpace] int;
|
||||
|
||||
forall bca in BCA do
|
||||
bca = here.id;
|
||||
|
||||
writeln("Block-Cyclic Array Index Map");
|
||||
writeln(BCA);
|
||||
writeln();
|
||||
|
||||
|
||||
//
|
||||
// The ReplicatedDist distribution is different: each of the
|
||||
// original domain's indices - and the corresponding array elements -
|
||||
// is replicated onto each locale. (Note: consistency among these
|
||||
// array replicands is NOT maintained automatically.)
|
||||
//
|
||||
// This replication is observable in some cases but not others,
|
||||
// as shown below. Note: this behavior may change in the future.
|
||||
//
|
||||
const ReplicatedSpace = Space dmapped ReplicatedDist();
|
||||
var RA: [ReplicatedSpace] int;
|
||||
|
||||
// The replication is observable - this visits each replicand.
|
||||
forall ra in RA do
|
||||
ra = here.id;
|
||||
|
||||
writeln("Replicated Array Index Map, ", RA.numElements, " elements total");
|
||||
writeln(RA);
|
||||
writeln();
|
||||
|
||||
//
|
||||
// The replication is observable when the replicated array is
|
||||
// on the left-hand side. If the right-hand side is not replicated,
|
||||
// it is copied into each replicand.
|
||||
// We illustrate this using a non-distributed array.
|
||||
//
|
||||
var A: [Space] int = [(i,j) in Space] i*100 + j;
|
||||
RA = A;
|
||||
writeln("Replicated Array after being array-assigned into");
|
||||
writeln(RA);
|
||||
writeln();
|
||||
|
||||
//
|
||||
// Analogously, each replicand will be visited and
|
||||
// other participated expressions will be computed on each locale
|
||||
// (a) when the replicated array is assigned a scalar:
|
||||
// RA = 5;
|
||||
// (b) when it appears first in a zippered forall loop:
|
||||
// forall (ra, a) in zip(RA, A) do ...;
|
||||
// (c) when it appears in a for loop:
|
||||
// for ra in RA do ...;
|
||||
//
|
||||
// Zippering (RA,A) or (A,RA) in a 'for' loop will generate
|
||||
// an error due to their different number of elements.
|
||||
|
||||
// Let RA store the Index Map again, for the examples below.
|
||||
forall ra in RA do
|
||||
ra = here.id;
|
||||
|
||||
//
|
||||
// Only the local replicand is accessed - replication is NOT observable
|
||||
// and consistency is NOT maintained - when:
|
||||
// (a) the replicated array is indexed - an individual element is read...
|
||||
//
|
||||
on Locales(0) do
|
||||
writeln("on ", here, ": ", RA(Space.low));
|
||||
on Locales(LocaleSpace.high) do
|
||||
writeln("on ", here, ": ", RA(Space.low));
|
||||
writeln();
|
||||
|
||||
// ...or an individual element is written;
|
||||
on Locales(LocaleSpace.high) do
|
||||
RA(Space.low) = 7777;
|
||||
|
||||
writeln("Replicated Array after being indexed into");
|
||||
writeln(RA);
|
||||
writeln();
|
||||
|
||||
//
|
||||
// (b) the replicated array is on the right-hand side of an assignment...
|
||||
//
|
||||
on Locales(LocaleSpace.high) do
|
||||
A = RA + 4;
|
||||
writeln("Non-Replicated Array after assignment from Replicated Array + 4");
|
||||
writeln(A);
|
||||
writeln();
|
||||
|
||||
//
|
||||
// (c) ...or, generally, the replicated array or domain participates
|
||||
// in a zippered forall loop, but not in the first position.
|
||||
// The loop could look like:
|
||||
//
|
||||
// forall (a, (i,j), ra) in (A, ReplicatedSpace, RA) do ...;
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// The DimensionalDist2D distribution lets us build a 2D distribution
|
||||
// as a composition of specifiers for individual dimensions.
|
||||
// Under such a "dimensional" distribution each dimension is handled
|
||||
// independently of the other.
|
||||
//
|
||||
// The dimension specifiers are similar to the corresponding multi-dimensional
|
||||
// distributions in constructor arguments and index-to-locale mapping rules.
|
||||
// However, instead of an array of locales, a specifier constructor
|
||||
// accepts just the number of locales that the indices in the corresponding
|
||||
// dimension will be distributed across.
|
||||
//
|
||||
// The DimensionalDist2D constructor requires:
|
||||
// * an [0..nl1-1, 0..nl2-1] array of locales, where
|
||||
// nl1 and nl2 are the number of locales in each dimension, and
|
||||
// * two dimension specifiers, created for nl1 and nl2 locale counts, resp.
|
||||
//
|
||||
// Presently, the following dimension specifiers are available
|
||||
// (shown here with their constructor arguments):
|
||||
//
|
||||
// * ReplicatedDim(numLocales)
|
||||
// * BlockDim(numLocales, boundingBoxLow, boundingBoxHigh)
|
||||
// * BlockCyclicDim(lowIdx, blockSize, numLocales)
|
||||
//
|
||||
|
||||
//
|
||||
// The following example creates a dimensional distribution that
|
||||
// replicates over 2 locales (when available) in the first dimemsion
|
||||
// and distributes using block-cyclic distribution in the second dimension.
|
||||
// The example computes nl1 and nl2 and reshapes MyLocales correspondingly.
|
||||
//
|
||||
|
||||
var (nl1, nl2) = if numLocales == 1 then (1, 1) else (2, numLocales/2);
|
||||
MyLocaleView = {0..#nl1, 0..#nl2};
|
||||
MyLocales = reshape(Locales[0..#nl1*nl2], MyLocaleView);
|
||||
|
||||
const DimReplicatedBlockcyclicSpace = Space
|
||||
dmapped DimensionalDist2D(MyLocales,
|
||||
new ReplicatedDim(numLocales = nl1),
|
||||
new BlockCyclicDim(numLocales = nl2,
|
||||
lowIdx = 1, blockSize = 2));
|
||||
|
||||
var DRBA: [DimReplicatedBlockcyclicSpace] int;
|
||||
|
||||
// The ReplicatedDim specifier always accesses the local replicand.
|
||||
// (This differs from how the ReplicatedDist distribution works.)
|
||||
//
|
||||
// This example visits each replicand. The behavior is the same
|
||||
// regardless of the second index into MyLocales below.
|
||||
|
||||
for locId1 in 0..#nl1 do on MyLocales[locId1, 0] {
|
||||
|
||||
forall drba in DRBA do
|
||||
drba = here.id;
|
||||
|
||||
writeln("Dimensional2D(Replicated,BlockCyclic) Array Index Map",
|
||||
" from ", here);
|
||||
|
||||
// Technicality: 'writeln(DRBA)' would read DRBA always on Locale 0.
|
||||
// Since we want to see what DRBA contains on the current locale,
|
||||
// we use 'Helper' that is mapped using the default distribution.
|
||||
// 'Helper = DRBA' captures the view of DRBA on the current locale,
|
||||
// which we then print out.
|
||||
|
||||
const Helper: [Space] int = DRBA;
|
||||
writeln(Helper);
|
||||
writeln();
|
||||
|
||||
}
|
||||
1
samples/Chapel/hello.chpl
Normal file
1
samples/Chapel/hello.chpl
Normal file
@@ -0,0 +1 @@
|
||||
writeln("Hello, world!"); // print 'Hello, world!' to the console
|
||||
1692
samples/Chapel/lulesh.chpl
Normal file
1692
samples/Chapel/lulesh.chpl
Normal file
File diff suppressed because it is too large
Load Diff
147
samples/Chapel/nbody.chpl
Normal file
147
samples/Chapel/nbody.chpl
Normal file
@@ -0,0 +1,147 @@
|
||||
/* The Computer Language Benchmarks Game
|
||||
http://benchmarksgame.alioth.debian.org/
|
||||
|
||||
contributed by Albert Sidelnik
|
||||
modified by Brad Chamberlain
|
||||
*/
|
||||
|
||||
|
||||
//
|
||||
// The number of timesteps to simulate; may be set via the command-line
|
||||
//
|
||||
config const n = 10000;
|
||||
|
||||
//
|
||||
// Constants representing pi, the solar mass, and the number of days per year
|
||||
//
|
||||
const pi = 3.141592653589793,
|
||||
solarMass = 4 * pi**2,
|
||||
daysPerYear = 365.24;
|
||||
|
||||
//
|
||||
// a record representing one of the bodies in the solar system
|
||||
//
|
||||
record body {
|
||||
var pos: 3*real;
|
||||
var v: 3*real;
|
||||
var mass: real; // does not change after it is set up
|
||||
}
|
||||
|
||||
//
|
||||
// the array of bodies that we'll be simulating
|
||||
//
|
||||
var bodies = [/* sun */
|
||||
new body(mass = solarMass),
|
||||
|
||||
/* jupiter */
|
||||
new body(pos = ( 4.84143144246472090e+00,
|
||||
-1.16032004402742839e+00,
|
||||
-1.03622044471123109e-01),
|
||||
v = ( 1.66007664274403694e-03 * daysPerYear,
|
||||
7.69901118419740425e-03 * daysPerYear,
|
||||
-6.90460016972063023e-05 * daysPerYear),
|
||||
mass = 9.54791938424326609e-04 * solarMass),
|
||||
|
||||
/* saturn */
|
||||
new body(pos = ( 8.34336671824457987e+00,
|
||||
4.12479856412430479e+00,
|
||||
-4.03523417114321381e-01),
|
||||
v = (-2.76742510726862411e-03 * daysPerYear,
|
||||
4.99852801234917238e-03 * daysPerYear,
|
||||
2.30417297573763929e-05 * daysPerYear),
|
||||
mass = 2.85885980666130812e-04 * solarMass),
|
||||
|
||||
/* uranus */
|
||||
new body(pos = ( 1.28943695621391310e+01,
|
||||
-1.51111514016986312e+01,
|
||||
-2.23307578892655734e-01),
|
||||
v = ( 2.96460137564761618e-03 * daysPerYear,
|
||||
2.37847173959480950e-03 * daysPerYear,
|
||||
-2.96589568540237556e-05 * daysPerYear),
|
||||
mass = 4.36624404335156298e-05 * solarMass),
|
||||
|
||||
/* neptune */
|
||||
new body(pos = ( 1.53796971148509165e+01,
|
||||
-2.59193146099879641e+01,
|
||||
1.79258772950371181e-01),
|
||||
v = ( 2.68067772490389322e-03 * daysPerYear,
|
||||
1.62824170038242295e-03 * daysPerYear,
|
||||
-9.51592254519715870e-05 * daysPerYear),
|
||||
mass = 5.15138902046611451e-05 * solarMass)
|
||||
];
|
||||
|
||||
//
|
||||
// the number of bodies to be simulated
|
||||
//
|
||||
const numbodies = bodies.numElements;
|
||||
|
||||
//
|
||||
// The computation involves initializing the sun's velocity,
|
||||
// writing the initial energy, advancing the system through 'n'
|
||||
// timesteps, and writing the final energy.
|
||||
//
|
||||
proc main() {
|
||||
initSun();
|
||||
|
||||
writef("%.9r\n", energy());
|
||||
for 1..n do
|
||||
advance(0.01);
|
||||
writef("%.9r\n", energy());
|
||||
}
|
||||
|
||||
//
|
||||
// compute the sun's initial velocity
|
||||
//
|
||||
proc initSun() {
|
||||
const p = + reduce (for b in bodies do (b.v * b.mass));
|
||||
bodies[1].v = -p / solarMass;
|
||||
}
|
||||
|
||||
//
|
||||
// advance the positions and velocities of all the bodies
|
||||
//
|
||||
proc advance(dt) {
|
||||
for i in 1..numbodies {
|
||||
for j in i+1..numbodies {
|
||||
updateVelocities(bodies[i], bodies[j]);
|
||||
|
||||
inline proc updateVelocities(ref b1, ref b2) {
|
||||
const dpos = b1.pos - b2.pos,
|
||||
mag = dt / sqrt(sumOfSquares(dpos))**3;
|
||||
|
||||
b1.v -= dpos * b2.mass * mag;
|
||||
b2.v += dpos * b1.mass * mag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for b in bodies do
|
||||
b.pos += dt * b.v;
|
||||
}
|
||||
|
||||
//
|
||||
// compute the energy of the bodies
|
||||
//
|
||||
proc energy() {
|
||||
var e = 0.0;
|
||||
|
||||
for i in 1..numbodies {
|
||||
const b1 = bodies[i];
|
||||
|
||||
e += 0.5 * b1.mass * sumOfSquares(b1.v);
|
||||
|
||||
for j in i+1..numbodies {
|
||||
const b2 = bodies[j];
|
||||
|
||||
e -= (b1.mass * b2.mass) / sqrt(sumOfSquares(b1.pos - b2.pos));
|
||||
}
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
//
|
||||
// a helper routine to compute the sum of squares of a 3-tuple's components
|
||||
//
|
||||
inline proc sumOfSquares(x)
|
||||
return x(1)**2 + x(2)**2 + x(3)**2;
|
||||
145
samples/Chapel/quicksort.chpl
Normal file
145
samples/Chapel/quicksort.chpl
Normal file
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// An example of a parallel quick sort implementation that uses
|
||||
// "cobegin" to make each recursive call in parallel and "serial" to
|
||||
// limit the number of threads.
|
||||
//
|
||||
|
||||
use Random, Time; // for random number generation and the Timer class
|
||||
|
||||
var timer: Timer; // to time the sort
|
||||
|
||||
config var n: int = 2**15; // the size of the array to be sorted
|
||||
config var thresh: int = 1; // the recursive depth to serialize
|
||||
config var verbose: int = 0; // print out this many elements in array
|
||||
config var timing: bool = true; // set timing to false to disable timer
|
||||
|
||||
var A: [1..n] real; // array of real numbers
|
||||
|
||||
//
|
||||
// initialize array with random numbers
|
||||
//
|
||||
fillRandom(A);
|
||||
|
||||
//
|
||||
// print out front of array if verbose flag is set
|
||||
//
|
||||
if verbose > 0 then
|
||||
writeln("A[1..", verbose, "] = ", A[1..verbose]);
|
||||
|
||||
//
|
||||
// start timer, call parallel quick sort routine, stop timer
|
||||
//
|
||||
if timing then timer.start();
|
||||
pqsort(A, thresh);
|
||||
if timing then timer.stop();
|
||||
|
||||
//
|
||||
// report sort time
|
||||
//
|
||||
if timing then writeln("sorted in ", timer.elapsed(), " seconds");
|
||||
|
||||
//
|
||||
// print out front of array if verbose flag is set
|
||||
// values should now be in sorted order
|
||||
//
|
||||
if verbose > 0 then
|
||||
writeln("A[1..", verbose, "] = ", A[1..verbose]);
|
||||
|
||||
//
|
||||
// verify that array is sorted or halt
|
||||
//
|
||||
for i in 2..n do
|
||||
if A(i) < A(i-1) then
|
||||
halt("A(", i-1, ") == ", A(i-1), " > A(", i, ") == ", A(i));
|
||||
|
||||
writeln("verification success");
|
||||
|
||||
//
|
||||
// pqsort -- parallel quick sort
|
||||
//
|
||||
// arr: generic 1D array of values (real, int, ...)
|
||||
// thresh: number of recursive calls to make before serializing
|
||||
// low: lower bound of array to start sort at, defaults to whole array
|
||||
// high: upper bound of array to stop sort at, defaults to whole array
|
||||
//
|
||||
proc pqsort(arr: [],
|
||||
thresh: int,
|
||||
low: int = arr.domain.low,
|
||||
high: int = arr.domain.high) where arr.rank == 1 {
|
||||
|
||||
//
|
||||
// base case: arr[low..high] is small enough to bubble sort
|
||||
//
|
||||
if high - low < 8 {
|
||||
bubbleSort(arr, low, high);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// determine pivot and partition arr[low..high]
|
||||
//
|
||||
const pivotVal = findPivot();
|
||||
const pivotLoc = partition(pivotVal);
|
||||
|
||||
//
|
||||
// make recursive calls to parallel quick sort each unsorted half of
|
||||
// the array; if thresh is 0 or less, start executing conquer tasks
|
||||
// serially
|
||||
//
|
||||
serial thresh <= 0 do cobegin {
|
||||
pqsort(arr, thresh-1, low, pivotLoc-1);
|
||||
pqsort(arr, thresh-1, pivotLoc+1, high);
|
||||
}
|
||||
|
||||
//
|
||||
// findPivot -- helper routine to find pivot value using simple
|
||||
// median-of-3 method, returns pivot value
|
||||
//
|
||||
proc findPivot() {
|
||||
const mid = low + (high-low+1) / 2;
|
||||
|
||||
if arr(mid) < arr(low) then arr(mid) <=> arr(low);
|
||||
if arr(high) < arr(low) then arr(high) <=> arr(low);
|
||||
if arr(high) < arr(mid) then arr(high) <=> arr(mid);
|
||||
|
||||
const pivotVal = arr(mid);
|
||||
arr(mid) = arr(high-1);
|
||||
arr(high-1) = pivotVal;
|
||||
|
||||
return pivotVal;
|
||||
}
|
||||
|
||||
//
|
||||
// partition -- helper routine to partition array such that all
|
||||
// values less than pivot are to its left and all
|
||||
// values greater than pivot are to its right, returns
|
||||
// pivot location
|
||||
//
|
||||
proc partition(pivotVal) {
|
||||
var ilo = low, ihi = high-1;
|
||||
while (ilo < ihi) {
|
||||
do { ilo += 1; } while arr(ilo) < pivotVal;
|
||||
do { ihi -= 1; } while pivotVal < arr(ihi);
|
||||
if (ilo < ihi) {
|
||||
arr(ilo) <=> arr(ihi);
|
||||
}
|
||||
}
|
||||
arr(high-1) = arr(ilo);
|
||||
arr(ilo) = pivotVal;
|
||||
return ilo;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// bubbleSort -- bubble sort for base case of quick sort
|
||||
//
|
||||
// arr: generic 1D array of values (real, int, ...)
|
||||
// low: lower bound of array to start sort at
|
||||
// high: upper bound of array to stop sort at
|
||||
//
|
||||
proc bubbleSort(arr: [], low: int, high: int) where arr.rank == 1 {
|
||||
for i in low..high do
|
||||
for j in low..high-1 do
|
||||
if arr(j) > arr(j+1) then
|
||||
arr(j) <=> arr(j+1);
|
||||
}
|
||||
Reference in New Issue
Block a user