|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Full Text | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PAGE 1 SOLVINGTHEINVERSESPECTRALPROBLEMFORINVERSESPECTRAL PROBLEMS BY MICHAELEDWARDCONLEN AThesis SubmittedtotheDivisionofNaturalSciences NewCollegeofFlorida inpartialfulllmentoftherequirementsforthedegreeof BachelorofArts UndertheSponsorshipofProfessorPatrickMcDonald,PhD. Sarasota,Florida May,2013 PAGE 3 iii Usually,evenanon-Christianknowssomethingabouttheearth,theheavens,andtheotherelementsofthisworld,aboutthemotionandorbitofthestarsandeventheirsizeandrelativepositions,aboutthepredictableeclipsesofthesunandmoon,thecyclesoftheyearsandtheseasons,aboutthekindsofanimals,shrubs,stones,andsoforth,andthisknowledgeheholdtoasbeingcertainfromreasonandexperience.Now,itisadisgracefulanddangerousthingforanindeltohearaChristian,presumablygivingthemeaningofHolyScripture,talkingnonsenseonthesetopics;andweshouldtakeallmeanstopreventsuchanembarrassingsituation,inwhichpeopleshowupvastignoranceinaChristianandlaughittoscorn.Theshameisnotsomuchthatanignorantindividualisderided,butthatpeopleoutsidethehouseholdoffaiththinkoursacredwritersheldsuchopinions,and,tothegreatlossofthoseforwhosesalvationwetoil,thewritersofourScripturearecriticizedandrejectedasunlearnedmen.IftheyndaChristianmistakeninaeldwhichtheythemselvesknowwellandhearhimmaintaininghisfoolishopinionsaboutourbooks,howaretheygoingtobelievethosebooksinmattersconcerningtheresurrectionofthedead,thehopeofeternallife,andthekingdomofheaven,whentheythinktheirpagesarefulloffalsehoodsandonfactswhichtheythemselveshavelearntfromexperienceandthelightofreason?RecklessandincompetentexpoundersofHolyScripturebringuntoldtroubleandsorrowontheirwiserbrethrenwhentheyarecaughtinoneoftheirmischievousfalseopinionsandaretakentotaskbythosewhoarenotboundbytheauthorityofoursacredbooks.Forthen,todefendtheirutterlyfoolishandobviouslyuntruestatements,theywilltrytocalluponHolyScriptureforproofandevenrecitefrommemorymanypassageswhichtheythinksupporttheirposition,althoughtheyunderstandneitherwhattheysaynorthethingsaboutwhichtheymakeassertion. [1Timothy1.7]" {SaintAugustine,TheLiteralMeaningofGenesis",Trans.Taylor,J.H.inAncient ChristianWriters",NewmanPress,1982,volume41. PAGE 4 PrefaceEversincethedevelopmentoftherstpracticalcomputerscientistshavebeeninventingwaystomodelsolutionstodicultproblems.Thesemodels,whileinitiallypopularoftenundergoperiodsofdisuse.Articialintelligencehasundergonetwooftheseperiods,termedAIwinters,whereafterperiodswithfewpositiveresultsfundingforresearchintheareahasnearlyvanished.Initialenthusiasmleadstobubblesofsupportwhichinvariablyleadtodisappointmentwhenexpectationsofresultsoutpaceourunderstandingoftheunderlyingmodels.Worse,duetotherapidincreaseofprocessingpowernaveimplementationsofmodelsmayappearusefulwheninfacttheimplementationisnobetterthanrandomluck.Theseresultsmayleadothersdownfruitlesspaths.Geneticalgorithmsoeranenticinglysimplemodelwithwhichwemightsolvedicultcombinatorialproblems.Spectraltting,ontheotherhand,oersanenticingproblemwhichwewouldliketosolve.Attemptingtonavelysolvethisproblemusinggeneticalgorithmswithoutdeepunderstandingofeithertheproblemortheproposedsolutionprovestobedicult.Inthisworkweexploreonesuchattemptinhopesofbetterunderstandingboththeproblemandthemodel.Whiletheproblemisnotsolvedourunderstandingoftheproblemisimproved. iv PAGE 5 v OrganizationThisworkbeginswithanintroductiontothechemistryandphysicsbehindrotationalspectroscopy,thenotionofttingspectraandwhythisisadicultcomputationalproblemandhowgeneticalgorithmsmaybeappliedtoestimatesolutionstotheproblemofttingspectra.Chapter2exploresanewwayofmodelingsolutionstothespectralttingproblemandexaminescomputationalissueswhichariseformthismodel.Chapter3exploresattemptstosolvethesecomputationalissues.InappendixAwecarryoutamodelcomputationmanuallyasanexample.TheworkissummarizedinChapter5.Theresearchdiscussedabove,however,doesnotstandonit'sown.Itisintimatelylinkedtothesoftwareusedtoexploreandunderstandtheseissues.TheprinciplepieceofsoftwarearethecomponentsofthegeneticalgorithmdiscussedinChapter3.ThissoftwareisdescribedinChapter4.UnittestsforthissoftwareisdocumentedinappendixB,appendixCandappendixD.Moreover,thereareseveralpiecesofsoftwarewhichweredevelopedinunderstandingboththeunderlyingchemistryandhowthatchemistryismodeledandsimulated.ThissoftwareisdescribedinAppendixEandAppendixF. PAGE 6 vi TypographicalConventions Thefollowingconventionsareusedinthiswork: Filenamesandcomputecodeintheexpositionarepresentedinteletypefont. Codeexcerptslistedinthedocumentarepresentedin 1 boxedfixedwithfont ReferencesarenumberedintheIEEEstyleandthebibliographyfollowsthesame[1]. Footnotesaresuperscriptedwithsymbolsonaper-pagebasis ColophonThisworkwastypesetwiththeLATEXtypesettingpackageandrenderedwithpdftex.ThetextisComputerModernRoman.SimulatedspectraimageswererenderedusingtheGD2library.FunctionplotswereproducedwithMathematica8.Codelistingswereproducedwiththe listings L A T E Xpackage. See[2]foranexplicationandexampleofwhytheIEEEstyleisnotused. PAGE 7 vii AcknowledgementsThisworkwouldnotbepossiblewithoutthestrengthanddedicationofProfessorPatMcDonald.IamindebtedtohimforhispatienceanddiplomacyinseeingmethroughthisthesisandmytimeatNewCollegeofFlorida.IthankJonCooper,whoalwayssawmoreinmethanIsawinmyself,KatieHelms,whoneverwaveredinherfaiththatIwasdoingtherightthing,IleneKaur,HarlanLiberman-BergandRalfRaudwhosefriendshiphassupportedmewhenthingswereattheirmostdicult.MostimportantlyIthankmyancee,SherryHaber.Itisthroughherthatallthingsinmylifearepossible. PAGE 8 Contents 1Introduction1 1.1Overview..................................1 1.2MicrowaveEmissionSpectroscopy....................4 1.3FittingSpectra..............................6 1.4HowDistortionDistortsthePicture...................9 1.5BiologicalAlgorithms...........................13 1.6GeneticAlgorithms............................13 1.7InverseSpectralProblemforInverseSpectralProblems........16 2FittingAnglesandEigenvalues17 2.1Overview..................................17 2.2HamiltonianfortheSemi-RigidRotor..................17 2.3ProblemsBegetProblems........................20 2.3.1ASimplerProblem........................20 2.3.2GeneticAlgorithmforthe H 1 Problem.............23 2.3.3AlgorithmPerformance......................26 2.4DivisionofLabor.............................29 2.4.1ProofofConcept.........................30 viii PAGE 9 CONTENTSix 3ANewHope32 3.1GeneticOperators............................33 3.1.1Selection..............................33 3.1.2Crossover.............................33 3.1.3Mutation.............................34 3.1.4Verication............................34 3.1.5FixedGenome...........................34 3.2GPU....................................34 3.3Results...................................35 3.3.1Phase1..............................36 3.3.2Phase2..............................38 3.3.3Phase3..............................39 3.3.4Phase4..............................40 3.4Conclusion.................................40 4Software44 4.1 dHamiltonianParameters ........................45 4.1.1 dHamiltonianParamtersCreate ...............48 4.1.2 dHamiltonianParametersRandom ...............50 4.1.3 dHamiltonianParametersMate ................52 4.1.4 dHamiltonianParametersMateSPC ..............54 4.1.5 dHamiltonianParametersComputeArray ...........56 4.1.6 dHamiltonianParametersDestroy ..............77 4.1.7Regression.............................78 4.2 jgaPopulation ..............................88 4.2.1 structjgaPopulation .....................88 PAGE 10 CONTENTSx 4.2.2 structdHamiltoniansGaElement ...............89 4.2.3 jgaPopulationCreate ......................90 4.2.4 jgaPopulationScore .......................98 4.2.5 jgaPopulationHusbandry ....................104 4.2.6 jgaPopulationVariance ...................115 4.2.7 jgaPopulationDestroy ....................118 4.3GeneticAlgorithm............................119 5Conclusion152 AComputingaHamiltonianfromAnglesandEigenvalues154 B hf.c TestPlans158 C hfGPU.c TestPlans184 D jga.c TestPlans188 EDataStructures196 E.1Queue...................................196 E.1.1Introduction............................196 E.1.2Variables..............................197 E.1.3Code................................197 E.1.4TestPlans.............................213 F spcat Interface225 F.1 .int ....................................226 F.1.1Introduction............................226 F.1.2Variables..............................226 PAGE 11 CONTENTSxi F.1.3Code................................226 F.1.4TestPlans.............................245 F.2 .var ....................................255 F.2.1Introduction............................255 F.2.2Variables..............................255 F.2.3Code................................255 F.2.4TestPlans.............................278 F.3 .cat ....................................289 F.3.1Introduction............................289 F.3.2Variables..............................289 F.3.3Code................................289 F.3.4TestPlans.............................311 F.4Simulator.................................321 F.4.1Introduction............................321 F.4.2Variables..............................321 F.4.3Code................................321 F.4.4TestPlans.............................347 PAGE 12 ListofFigures 1.1SimulatedSpectraofIsopropanolat1 K ................8 1.2SimulatedSpectraofIsopropanolat300 K x .............11 2.1Surfacefor 2 and 3 ...........................26 2.2Surfacefor 3 and 3 ...........................27 2.3Surfacefor x ................................28 2.4Surfacefor 2 and 3 ...........................30 3.1Phase1Results..............................36 3.2Phase2Results..............................38 3.3Phase3Results..............................39 3.4Phase3Initialvs.Final.........................40 3.5Phase4Results..............................41 3.6Phase4Initialvs.Final.........................41 4.1Planeidenticationbyaxispairs....................59 xii PAGE 13 Listings 4.1 hf.h:structdHamiltonianParameters ................44 4.2 hf.h Functions..............................47 4.3 hf.c:dHamiltonianParametersCreate ...............49 4.4 hf.c:dHamiltonianParametersRandom ...............51 4.5 hf.c:dHamiltonianParametersMate .................53 4.6 hf.c:dHamiltonianParametersMateSPC ...............55 4.7 hf.c:dHamiltonianParametersComputeArray ...........56 4.8 hf.c:findPlane ............................61 4.9 hf.c:dHamiltonianParametersCPUComputeArray .........63 4.10 hfGPU.cu:structmakeMatricesParameters .............66 4.11 hfGPU.cu:makeMatrices .......................67 4.12 hfGPU.cu:dHamiltonianParametersGPUComputeArray .......70 4.13 hf.h:dHamiltonianParametersDestroy ................77 4.14 hf.h:generateRegressionCoefficients ..............79 4.15 hf.h:sLen ...............................81 4.16 hf.c:generateStitchedCoefficients ...............83 4.17 hf.c:dHamiltonianFit ........................86 4.18 jga.h:structjgaPopulation .....................88 xiii PAGE 14 LISTINGSxiv 4.19 gae.h:structdHamiltoniansGaElement ...............89 4.20 gae.h:structdHamiltoniansGaElement ...............89 4.21 jga.c:jgaPopulationCreate .....................91 4.22 jga.c:structpopJob ..........................94 4.23 jga.c:jgaPopulationJob .......................95 4.24 jga.c:jgaPopulationScore .....................99 4.25 jga.c:structscoreJob .........................100 4.26 jga.c:jgaPopulationJob .......................101 4.27 jga.c:jgaPopulationHusbandry ...................105 4.28 jga.c:structhusbandryJob ......................109 4.29 jga.c:jgaHusbandryJob .......................110 4.30 jga.c:jgaPopulationVariance ...................115 4.31 jga.c:jgaPopulationDestroy ....................118 4.32 j.c .....................................119 B.1 hf.c:unit dHamiltoinaParametersCreate .............159 B.2 hf.c:unit dHamiltonianParametersRandom ............160 B.3 hf.c:unit dHamiltonianParametersMate ..............161 B.4 hf.c:unit dHamiltonianParametersMateSPC ............163 B.5 hf.c:unit dHamiltonianParametersCPUComputeArray ......165 B.6 hf.c:unit dHamiltonianParametersDestroy ............169 B.7 hf.c:unit findDiagonal .......................170 B.8 hf.c:unit findPlane .........................172 B.9 hf.c:unit h3Fit ............................175 B.10 unit generateRegressionCoefficients ..............177 B.11 hf.c:unit generateStitchedCoefficients ............179 PAGE 15 LISTINGSxv B.12 hf.c:unit dHamiltonianFit .....................181 C.1 hfGPU.cu:unit dHamiltonianParametersGPUComputeArray ....184 D.1 jga.c:unit jgaPopulationCreate ..................188 D.2 jga.c:unit jgaPopulationScore ..................192 D.3 jga.c:unit jgaPopulationVariance ................193 D.4 jga.c:unit jgaPopulationDestroy .................195 E.1 queue.h ..................................197 E.2 queue.c Includes.............................200 E.3 queue.c:queueElementCreate ....................201 E.4 queue.c:queueElementDestroy ...................202 E.5 queue.c:queueCreate .........................203 E.6 queue.c:queueCopy ..........................204 E.7 queue.c:queueEnqueue ........................206 E.8 queue.c:queueDequeue ........................208 E.9 queue.c:queueLength .........................210 E.10 queue.c:queueDestory ........................211 E.11 queue.c:unit queueElementCreate .................213 E.12 queue.c:unit queueElementDestroy ................214 E.13 queue.c:unit queueElementDestroyFree ..............215 E.14 queue.c:unit queueCreate ......................216 E.15 queue.c:unit queueCopy .......................217 E.16 queue.c:unit queueEnqueue .....................219 E.17 queue.c:unit queueDequeue .....................221 E.18 queue.c:unit queueDestroy .....................223 E.19 queue.c:unit queueLength ......................224 PAGE 16 LISTINGSxvi F.1 int.h ...................................227 F.2 int.c Includes..............................229 F.3 int.c:dipoleCpy ...........................230 F.4 int.c:intFileCreate .........................231 F.5 int.h:intFileSetTitle .......................232 F.6 int.h:intFileSetParameters ....................234 F.7 int.h:intFileAddDipole .......................235 F.8 int.h:intFileRead ..........................237 F.9 int.h:intFileWrite .........................241 F.10 int.h:intFileDestroy ........................243 F.11 int.c:unit dipoleCpy ........................245 F.12 int.c:unit intFileCreate ......................246 F.13 int.c:unit intFileSetTitle ....................247 F.14 int.c:unit intFileSetParameters .................248 F.15 int.c:unit intFileAddDipole ....................249 F.16 int.c:unit intFileRead .......................250 F.17 int.c:unit intFileWrite ......................252 F.18 int.c:unit intFileDestroy .....................254 F.19 var.h ...................................255 F.20 var.c:varFileCreate .........................258 F.21 var.c:varFileSetTitle .......................260 F.22 var.c:varFileSetOptions ......................261 F.23 var.c:varFileSetParameter .....................264 F.24 var.c:varFileSetCorrelation ...................266 F.25 var.c:varFileRead ..........................268 PAGE 17 LISTINGSxvii F.26 var.c:varFileWrite .........................274 F.27 var.c:varFileDestroy ........................276 F.28 var.c:unit varFileCreate ......................278 F.29 var.c:unit varFileSetTitle ....................279 F.30 var.c:unit varFileSetOptions ...................280 F.31 var.c:unit varFileSetParameters .................282 F.32 var.c:unit varFileSetCorrelation ................283 F.33 var.c:unit varFileRead .......................284 F.34 var.c:unit varFileWrite ......................286 F.35 var.c:unit varFileDestroy .....................288 F.36 cat.h structures.............................289 F.37 cat.h UnitTestFunctions........................291 F.38 cat.h AuxiliaryFunctions........................291 F.39 cat.hcatFile Functions........................291 F.40 cat.hspecData Functions........................292 F.41 cat.c:catFileCreate .........................293 F.42 cat.c:catFileRead ..........................294 F.43 cat.c:catFileDestroy ........................297 F.44 cat.c:resolve .............................298 F.45 cat.c:specDataCreate ........................300 F.46 cat.c:specDataGenerate .......................301 F.47 cat.c:specDataResolve .......................303 F.48 cat.c:specDataMaximumIntensity .................305 F.49 cat.c:specDataGraph .........................307 F.50 cat.c:specDataDestroy .......................310 PAGE 18 LISTINGSxviii F.51 cat.c:unit specDataCreate .....................311 F.52 cat.c:unit specDataResolve ....................312 F.53 cat.c:unit specDataMaximumIntensity ..............314 F.54 cat.c:unit specDataGenerate ....................315 F.55 cat.c:unit specDataGraph ......................316 F.56 cat.c:unit specDataDestroy ....................317 F.57 cat.c:unit catFileCreate ......................318 F.58 cat.c:unit catFileRead .......................319 F.59 cat.c:unit catFileDestroy .....................320 F.60 sim.h:structrotSpec .........................322 F.61 sim.h UnitTests.............................323 F.62 sim.h Functions..............................324 F.63 sim.c:rotSpecCreate .........................325 F.64 sim.c:rotSpecCopy ..........................327 F.65 sim.c:rotSpecSetTitle .......................329 F.66 sim.c:rotSpecSetVarOptions ....................331 F.67 sim.c:rotSpecSetParameters ....................332 F.68 sim.c:rotSpecSetCorrelation ...................334 F.69 sim.c:rotSpecSetIntOptions ....................336 F.70 sim.c:rotSpecSetTemp ........................338 F.71 sim.c:rotSpecAddDipole .......................340 F.72 sim.c:rotSpecGenerateCat .....................342 F.73 sim.c:unit rotSpecCreate ......................347 F.74 sim.c:unit rotSpecCopy .......................348 F.75 sim.c:unit rotSpecSetTitle ....................351 PAGE 19 LISTINGSxix F.76 sim.c:unit rotSpecSetVarOptions .................352 F.77 sim.c:unit rotSpecSetParameters .................353 F.78 sim.c:unit rotSpecSetCorrelation ................354 F.79 sim.c:unit rotSpecSetIntOptions .................355 F.80 sim.c:unit rotSpecAddDipole ....................356 F.81 sim.c:unit rotSpecGenerateCat ..................357 F.82 sim.c:unit rotSpecDestroy .....................360 PAGE 20 LISTINGSxx PAGE 21 SOLVINGTHEINVERSESPECTRALPROBLEMSFORINVERSESPECTRAL PROBLEMS MichaelEdwardConlen NewCollegeofFlorida,2013 ABSTRACTGeneticalgorithmsprovideausefulschemeforapproximatingsolutionstooptimizationproblems;howevernavelyapplyingthetechniquecanproducepoorresults.Weexploreapotentialtechniquetoimprovethesensitivityofgeneticalgorithmsinthecontextofttinghighresolution,hightemperaturespectraldata;thatofestimatingtheeigenvaluesoftheHamiltonianratherthantherotationalconstantsusedtocomputetheHamiltoniandirectly.Wethenattempttodevelopsolutionstoaproblemintroducedbythistechnique;thatofestimatingaHamiltonianwithknowledgeofonlytheformoftheHamiltonianandtheassociatedeigenvalues.Weexplorethecomputationaldicultyofthissolutionanddevelopideastoresolvetheseissues. PatrickMcDonald DivisionofNaturalSciences PAGE 22 Chapter1 Introduction 1.1OverviewSupposewewewishtoknowifaparticularmoleculeisfoundinaregionofspacewhichwecanobservewitharadiotelescope.Weknowthatlowpressuregasseswillabsorbandemitelectromagneticradiationatdiscretefrequencies[3].Moleculeswillabsorbandemitradiationduetochangesinangularmomentumofthemoleculerotatinginspace.Todeterminethefrequencyrangewherewemightobservethisradiationwebeginbyconsideringasimplemodel,adiatomicmoleculewitharigidbond.Recallthatquantummechanicsshowsthatangularmomentumisquantizedbyintegermultiplesof~;thus2I=J ~,where~isthereducedPlanck'sconstant,IisthemomentofinertiaandisthefrequencyofrotationandJistheintegralquantumnumberinunitsof~whichmeasurestheunitsofangularmomentum.FromthiswecancomputethepossiblefrequenciesofrotationandhencethepossiblelevelsofrotationalenergyassociatedtothemoleculeThisanalysisinformstheestimate Acompleteanalysisofthiscanbefoundin[3,4,5]. 1 PAGE 23 Overview2 thatelectromagneticradiationresultingfromchangesinangularmomentumwilllikelybeobservedinthe3 cm to3 mm range[3].Spectroscopistshavebeenmakingmeasurementsofthespectrumofmoleculesforsometime.Thespectroscopisttypicallyworksatlowtemperaturewherethenumberofpossiblequantumstatesinwhichamoleculewilllikelybeobservedislimited.Byobservingtheemissionsofelectromagneticradiationassociatedwithachangeinangularmomentum,calledatransition,themomentofinertiacanbeestimatedwithhighaccuracy.Usingtheanalysisin[5]thespectroscopistcancomputeanapproximationoftheHamiltonianforanarbitrarymolecule.Whilethespectroscopistmayworkatlowtemperaturetheradioastronomerisunabletocontrolthetemperatureatwhichobservationsaremade.OneexampleisthemeasurementofspectraoftheOrionKleinmann-Lownebulawhereobservationsaremadeatapproximately300K[6].IfmoleculeisarigidrotorthenweexpectthatwecanusetheapproximationoftheHamiltoniantocomputethetransitionfrequenciesatwhichweexpecttoobservehighertemperaturetransitions.Unfortunatelywendthatthisapproximationfailsattemperaturesassociatedtoourobservations.Thebondsbetweenatomsinamoleculearenotrigid,norarethebondanglesxed.Thebondlengthsdependontheangularmomentumofthemolecule.Thisdistortioniscalledcentrifugaldistortion.Aninitialtreatmentofthisdistortionisgivenin[7].Arstorderapproximationofthedistortionisgivenin[8,9].TheresultofthisanalysisarehigherorderapproximationsoftheHamiltonianintermsofthemomentsofinertiaanddistortionparameterscollectivelycalledtherotationalconstants.Ifthespectroscopistcanmeasurethecentrifugaldistortionofamoleculethenwemaypredictthespectraonewouldobserveifthatmoleculeweretobefoundinspace. Inpracticethemomentsofinertiaaretransformedtofrequenciesby I ~ 2 2 I PAGE 24 Overview3 Measuringthespectraofamoleculeinconditionssucienttomeasuretheeectsofcentrifugaldistortioncomplicatethejobofthespectroscopist.Thespectroscopistmustmakemeasurementsathighertemperatureswherethemoleculesmaybeinanyofalargenumberofquantumstates.Thisimpliesthatthespectroscopistwillobservetransitionsatmanyfrequencies.Thespectroscopistmustthendeterminethequantumstatesassociatedwiththetransition,thatis,thestatethemoleculewasinbeforethetransitionandthestateafterthetransition.Ifenoughtransitionscanbeidentiedthentherotationalconstantswillbedetermined.Weproposethatitmaybepossibletousecomputeralgorithmstoaidinthisprocess.Itisrelativelyeasytoestimatethespectrumofamoleculeifweknowtherotationalconstantsofthemolecule.Infact,softwareisreadilyavailabletodothis[10].Thissoftwarecomputestheenergyofeachquantumstateanddeterminesthefrequencyofelectromagneticradiationemittedwhenamoleculestransitionsfromonestatetoanother.Usingthissoftwarewecanguesstherotationalconstants,computetheexpectedspectrathencomparetheexpectedspectratotheobservedspectra.Thisprocessisknownasspectraltting.SpectralttingmaybedoneecientlyusingatypeofcomputerprogramcalledageneticalgorithmGA.InaGAalargenumberofguesses,calledfeasiblesolutionssometimesreferredtosimplyassolutions,aremadeatonce.Thequalityofeachfeasiblesolutionismeasuredusingatnessfunctionandranked,thentheGAcreatesanewpopulationoffeasiblesolutionsusingaalgorithmtomatehighlytsolutionswiththeexpectationthattheaspectsofeachsolutionwhichmadethemhighlytmaycombineinanewsolutioninsuchawayastoproduceanevenmoretsolution.Geneticalgorithmshavebeenappliedtospectralproblemsinthepastwithvariedsuccess[11,12,13,14,15,16].Weproposeanewschemeforageneticalgorithm.Insteadofusingtherotationalconstantstoencodeasolutionweproposetoencodethe PAGE 25 MicrowaveEmissionSpectroscopy4 energyofthequantumstatesasthesolutiontheeigenvaluesoftheHamiltonianthencomputetheHamiltonianandderivetherotationalconstants.Therearesomepotentialadvantagestothistechnique,however,attemptstousethistechniqueresultedinaproblem,weareunabletondasinglealgorithmthatbothestimatedtheeigenvaluesoftheHamiltonianimpliedbyanobservedspectrumandestimatetheHamiltonianitselfatthesametime.Wethenproposetobreaktheproblemintoapairofalgorithms.Therstalgorithm,andthesubjectoftherestofthiswork,attemptstoestimatetheHamiltonianofthesystempresumingweknowtheenergyofthequantumstates.Thesecondalgorithmwouldusethersttoestimatetheenergyofthequantumstatesfromthespectrum.InordertobetterplacetheproblemofestimatingaHamiltoniangiventheformoftheHamiltonianandtheeigenvaluesinbettercontextwediscussthetopicsmentionedaboveingreaterdetail. 1.2MicrowaveEmissionSpectroscopyEmissionspectroscopymeasurestheelectromagneticradiationemittedbymoleculeswhentheyloseangularmomentum.Theenergylevelsofthesystemarequantized,thustheassociatedspectrumconsistsofradiationatdiscretefrequencies.Rotationalspectroscopystudiesthespectraofpolarmoleculesatfrequencieswherethetransitionsinvolvechangesinthemoleculesangularmomentumandhencerotationalenergy.ArstorderapproximationoftheHamiltoniancanbeconstructedfromthemomentsofinertiaofthemoleculeaboutitsprincipalaxesofrotationusingtheparametersdenotedA,BandCgivenbyA=~ 2 2 I awhereI aisthemomentofinertiaabouttheA PAGE 26 MicrowaveEmissionSpectroscopy5 axisand~isthereducedPlanck'sconstant.WecomputelikewiseforBandC.ByconventionA B C y.TheseparametersareusuallygiveninunitsofMHz[5].Thequarticcentrifugaldistortionparametersaredenotedj,jk,k, jand k z.ThesearetheveindependentparametersasdevelopedbyKivelsonandWilsonin[18]andreducedbyWatsonin[9].Theparametersj,jkandkaretypicallygiveninkHz while j and k aretypicallygivenin kHz or Hz .ForourpurposesthemeasurementswewishtobeabletotareobtainedthroughtheuseofchirpedpulseFouriertransformmicrowavespectroscopyCP-FTMW[19].ThistechniquehasbeenappliedtothemeasurementofspectrumofroomtemperaturegassesoflargemoleculessuchasstrawberryaldehydeC 12 H 14 O 3[20]andanisoleC 6 H 5 OCH 3[21].CP-FTMWprovideshighresolutiondataand,inourcase,roomtemperaturemeasurements.Thesecharacteristicsprovidetwoofthemotivationsfor ourwork.Theemissionspectradataconsistsofadiscretesetofintensitiesatvariousfrequencies.Eachpointrepresentsatransitionxofamoleculefromonequantumstatetoanother.Atypicalmeasurementatroomtemperaturemaycontainthousandsoftransitionswithaneectiveresolutionof100kHz {.Thelargenumberoftransitionsistheresultoftherelativelyhightemperature.Tounderstandwhythisisso,recallthatthepercentageofmoleculesfoundinagivenquantumstateisgivenbytheBoltzmann TheaxesA,BandCareassociatedwithx,yandzbasedonthe3!=6waysofrepresentingtheenergymatrixasdescribedin[17]. y [5]containsanexceptiononp.24 zThedistortionparametersaredenedin[5];notethatD j,D jk,D k,d kandd jaresometimesusedwherethegreekalphabetissometimesunavailable. x Theremaybemultipletransitionsinvolvedinthecaseofdegenerateeigenvalues. { Compareto[14]withfwhmresolutionof25 Mhz . PAGE 27 FittingSpectra6 distribution N i N = g i e )]TJ/F59 5.9776 Tf 11.318 4.432 Td [(E i k B T Z T .1whereN i NistheratioofmoleculesinastatewithenergylevelE itothetotalnumberofmolecules,k BistheBoltzmannconstant,g iisthedegeneracyoftheenergylevelandZTisthepartitionfunction.Inthelowtemperaturecasethevastmajorityofthemoleculeswillbeinafewlowenergyquantumstates.Asisclearfrom1.1,however,asthetemperaturerisesthedistributionbecomesat.Theresultforthespectrometeristhatinlowtemperaturestatesthereareafewlargepeakswhereasathighertemperaturetherearemanyrelativelyclosepeaks.Inadditionthehighestintensitypeaksareshiftedtohigherquantumnumbers. 1.3FittingSpectraInadiscretequantizedsystemtheemissionofphotonsresultfromatransitionfromahigherenergystatetoalowerenergystate.Whenthemoleculelosesenergythatenergyisnotdestroyed,butisemittedasaphotonwithenergygivenbyE=hwhereisthefrequency.Becausethephotonresultsfromatransitionwesaythatthespectrallinemeasuredisatransition.Ourgoalistounderstandhowthedistributionofobservedtransitionsisrelatedtothegeometryofthemolecule.Togainanunderstandingoftheunderlyingrelationshipwebeginbynotingthatthetransitionsaredierencesinquantizedenergystates.Theprinciplequantumnumber,denotedJ,representsthetotalangularmomentumofthemolecule.EachprinciplequantumlevelJisassociatedwith2J+1stateswhereeachstaterepresentstheprojectionoftheangularmomentumontotheinertialaxes. PAGE 28 FittingSpectra7 TheprojectionsontotwodimensionsaredenotedbyK aandK c.Theprojectionontothethirdaxisisundeterminedduetoquantumuncertainty.These2J+1statesareidentiedbyunitsofenergyprojectedontotheaxeswherethesumoftheunitsisequalto J or J +1. Intherstprinciplequantumlevel J =1therearethreeassociatedstates 1. K a =0, K c =1 2. K a =1, K c =0 3. K a =1, K c =1andwedenotethesestatesbytheprinciplequantumlevelfollowedbytheprojectionvalues;thustheyare 1.101 2.110 3.111InFigure1.1weshowsimulatedspectraofIsopropanolatatemperatureof1Kfrom9GHzto18GHzwithanarbitraryverticalscale.Thereareatotalof18transitionsorpeaks.Therearetwotallpeaksat13:254GHzand16:530GHz.ThesepeaksareproducedbytransitionsfromtheJ=1statetothegroundstate.Inparticulartherstisthetransitionfromthe111statetothegroundstateandthesecondisthetransitionfromthe110statetothegroundstate.Inthiscasethetransitionfrom101tothegroundstateisnotobservedduetothewaytheelectricdipoleprojectsontotheprincipleaxes.ThetwopeaksontheleftofthespectraaretransitionsfromJ=2states,thetwopeaksontherightofthespectraare PAGE 29 FittingSpectra8 Figure1.1:SimulatedSpectraofIsopropanolat1 K PAGE 30 HowDistortionDistortsthePicture9 transitionsfromtheJ=3state.TherearealsothreetransitionsfromJ=4visible.Anexperiencedspectroscopistwouldbeabletopickoutthegroundstatetransitions,andwithsomeknowledgeofthemoleculeassignquantumvaluestooneormoreoftheothertransitions.Fromthisinformationthemomentsofinertiaofthemoleculecanbeestimatedtowithintheaccuracyandprecisionofthemeasurementdeviceandthemagnitudeofthedistortionattheselevels. 1.4HowDistortionDistortsthePictureImagineyouarelookingatnebulaandyouwonder,Whatisthat?"Onetechniquetostartresolvingthisquestionmightbetolookatthenebulainthemicrowaveregion.Ifweobserveelectromagneticradiationinthemicrowaveregionitisreasonabletoassumethatitmaybetheresultoftransitionsinrotationalenergyofmoleculesoatinginspace.IfweknowthemomentsofinertiaofmoleculeswecanconstructamodeloftheHamiltonianfortherotationalenergyusingtherigidrotorapproximation,solveSchrodinger'sequationtodeterminetransitionfrequenciesandcombinethisinformationwiththeBoltzmanndistributiontodetermineintensityoftransitions.Wecancomparethisestimatetothetransitionsobservedfromthenebulatodetermineifthereisamatch.Wewillndthatthepredictedspectradoesnotmatchtheobservedspectra,inlargepart,duetooursimplifyingassumptionofarigidrotor.WhenthespectroscopistraisesthetemperatureslightlysothatmoleculesareobservedtransitioningfromtheJ=2stateswewill,intheory,haveenoughinformationtocomputethequarticdistortionparameters;howeverinexperimentthisisnotthecase.ThedistortionparametersareontheorderofHertzandaremultipliedbyafactorofJ 4.Inlowenergystatesthedierencebetweentherigidrotorapproximation PAGE 31 HowDistortionDistortsthePicture10 andthesemi-rigidrotorapproximationisafewHertz;belowtheabilityofmodernequipmenttodiscern.InpracticethespectroscopistmustraisethetemperaturesucientlysothattransitionsfromtheprinciplequantumlevelJ=16atbest,andJ =25atworstareobservedinordertoresolvetheeectofdistortion .Whenraisingthetemperatureatwhichmeasurementsaretakentherearetwoeectswhichcloudthepicture.TherstisthatasthetemperatureincreasesthemodeoftheBoltzmanndistributionmovestohigherenergylevels.Recallthatthereare2J+1stateswithineachlevel.Amoleculeinoneofthesestatesmaytransitiontoastatewithinthesameenergylevelortoastateintheneighboringenergylevels.RecallthatinthelowesttemperatureexampleamoleculeinthehighestenergyJ=1statemighttransitiontooneofthreelowerstates.AttheJ=10energylevelamoleculeinthehigheststatemighttransitiontooneoftheother20statesinthatlevelortooneofthe19statesinthenextlowerlevely.Thuswecanseethatthenumberoftransitionsmeasuredincreasesrapidlywithenergylevel.ThesecondeectisthattheBoltzmanndistributionattens.Theresultofthisisthatwemeasuremoleculesinveryhighenergylevels.ComputingtheexpectedspectraofisopropanolusingSPCATwithanoiseoorof)]TJ/F15 11.9552 Tf 1.002 0 0 1 297.443 299.329 Tm [(10:0zandatemperatureof299:00KestimatedthatonemightmeasureatransitionfromanenergylevelashighasJ=100x.ThisatteningoftheBoltzmanndistributionalsoresultsinaatteningoftheintensityofthetransitions,whichisrelatedtothepercentageofmoleculesineachstatewithrespecttothesumtotalofthemolecules.TheeectsofraisingthetemperatureontheobservedspectracanbeseeninFigure1.2. Shipman,personalcommunication. yThisassumesthatanystateintheJ=10levelhashigherenergythananystateintheJ=9level.Thisdoesnotonlyhold,butviolationsofthisdonotsimplifythepicture. z Arbitraryunits,see[10]. xInrealitythereissomeprobabilityofamoleculebeinginanygivenquantumlevelbuttheabilitytomeasureatransitionfromthatstateislimitedbythenoiseooroftheinstrument PAGE 32 HowDistortionDistortsthePicture11 Figure1.2:SimulatedSpectraofIsopropanolat300 K x PAGE 33 HowDistortionDistortsthePicture12 Theresultofthisattempttomeasurethedistortionparametersisthatwecannolongervisuallypickoutafewtransitionswhichgiveusalltheinformationneededforcomputation.Weseekacomputationalsolution.Inordertounderstandthesizeofthecomputationalproblemwemustestimatehowmanytransitionswemaypotentiallymeasure.ForthisestimateweassumethatstateswithatotalangularmomentumJallhaveenergieshigherthanthestateswithtotalangularmomentumJ )]TJ/F15 11.9552 Tf 1.02 0 0 1 131.95 533.062 Tm [(1.Thisisnotstrictlytrue,howevertheeectofthisdoesnotsignicantlyimpacttheestimatewearecomputing.Ifweorderthestatesthathavethesametotalangularmomentumwecanseethatamoleculeinthehighestenergystatecantransitiontoanyofthe2Jstatesbelowit.Amoleculeinthenexthigheststatecantransitiontoanyofthe2J )]TJ/F15 11.9552 Tf 1.02 0 0 1 286.602 439.568 Tm [(1statesbelowit,andsoforth;thusthenumberoftransitionsthatpreservethetotalangularmomentareP 2 J +1 k =1 k=2J 2+J.AmoleculewithagiventotalangularmomentumJmaybeinanyofthe2J+1statesandmaytransitiondowntoanyofthe2J )]TJ/F15 11.9552 Tf 0.993 0 0 1 337.183 369.449 Tm [(1statesbelowit,thusthereare4J 2 )]TJ/F15 11.9552 Tf 0.993 0 0 1 535.359 369.449 Tm [(1transitionsfromagiventotalangularmomenttoastatewithalowertotalangularmomentum.Weconcludethatthereare J 2 + J +J+1J )]TJ/F15 11.9552 Tf 0.994 0 0 1 454.673 322.702 Tm [(1=6J 2+J )]TJ/F15 11.9552 Tf 0.994 0 0 1 535.353 322.702 Tm [(1transitionsfromanyquantumlevel.SummingoverallquantumlevelsuptoJthereareP J k =1 k 2 + k )]TJ/F15 11.9552 Tf 11.955 0 Td [(1=2J 3+7 2 J 2+1 2 Jtransitions.Again,ifwecanmeasuretransitionsashighasJ=100weseethatwemightmeasureover2milliontransitions.Clearlythenavecombinatorialsolutionisimpracticalevenwithperfectinformation;thuswelookelsewhere. x Theintensityscaleofthisgraphisthesameasthe1 K simulationinFigure1.1forreference. PAGE 34 BiologicalAlgorithms13 1.5BiologicalAlgorithmsBiologicalalgorithmsarealgorithmswhichtakecuesfromnatureinordertosolveoptimizationproblems.ThenotionofbiologicalalgorithmsoriginatedoutofthemathematicalmodelingofthehumanbrainusingMcCulloch-Pittsneurons[22],whichledtothedevelopmentofarticialneuralnetworks[23]andattemptstomodelthehumanmindtosolvepatternmatchingproblems.JohnHollandpresentedamethodofmodelingevolutionoflivingcreatureswhichhetermedgeneticalgorithms[24].Geneticalgorithmsusemodelsofgeneticevolutiontocreatepotentialsolutionstoaproblemwhichareoptimizedusingthenotionofsurvivalofthettest.SincetheearlyworkofMcColluch,PittsandHollandaplethoraofalgorithmshavebeendevisedwhichattempttomimicormodelbiologicalsystemsinanattempttosolvehardcombinatorialproblemsSee[25]. 1.6GeneticAlgorithmsAgeneticalgorithmattemptstoavoidproblemsassociatedwithtraditionaloptimiza-tionalgorithms,suchasgradientdescent,usingtechniqueswhichmimictheevolutionofpopulationsofspeciesinnature.Feasiblesolutionsareencodedintoagenomeandapopulationoforganismsarecreated.Thetnessofeachelementofthepopulation'sgenomeismeasuredusingatnessfunctionandthepopulationisrankedaccordingly.Successivegenerationsofthepopulationarecreatedusingselection,crossoverandmutation.Creationofthenextgeneration'ssolutionsareasfollows: 1.Aselectionoperatorisusedtoselectsolutionswithinthepopulationformating.2.Thegenomesofthesolutionschosenarecombinedusingacrossoveroperator PAGE 35 GeneticAlgorithms14 whichmixesaspectsofeachparent'sgenomeintoachildgenome. 3.Thenewsolution'sgenomeis,withsomeprobability,modiedbyamutationoperator.Withthenewpopulationtheprocessbeginsagain.Thisschemeprovidesbenetsagainstgradientdescentinsituationswherethetnesslandscape,thetnessfunctioncomputedacrosstheentiredomain,hasmanylocaloptimaandisofhighdimensionality.Inthiscasegradientdescentsuersfromtwomajorproblems;ifthetnesslandscapehasmanylocaloptimagradientdescent'ssinglefeasiblesolutionmayeasilybecomestucknearalocaloptimaandifthedimensionalityofthesolutionishighthencomputationofthegradientbecomeslaborious.Geneticalgorithmsprovidechoicesinhowtoencodeagenome,populationsize,tnessfunctionandineachofthethreeoperators.DesignchoicesmaybeinformedbyHolland'sschematatheorem.Ifweencodeafeasiblesolutiontoanoptimizationproblemasasequenceofvariablesf x 1 ;x 2 ;:::;x n gwedeneaschemataasamaskwhichxescertainvariables.Bywayofexample,consideraproblemwhereafeasiblesolutionisabinarystringoflength5.Aschemawhichxestherst,thirdandfthbitstoonewouldbe111.Theorderoftheschemaisthenumberofxedpositionsinthemask.Thelengthoftheschemaisthedistancebetweenrstandlastxedpositions.Theschema111wouldhaveaorderof3andalengthof5.Thetnessofaschemaisdenedastheaveragetnessofallpossibleelementswiththegivenschema.Holland'sschematatheoremstatesthatshortloworderschematawithaboveaveragetnesswillrepresentexponentiallyincreasingportionsofthepopulation[26].Ifwemakedesignchoicessuchthatshortloworderschemamaybeparticularlywelltandthatwhentheseschemaarecombinedthepropertieswhichmaketheschemawelltaresynergisticsuccessivegenerationsofapopulationshouldhaveincreasing PAGE 36 GeneticAlgorithms15 tness.Evenwiththesepropertiesthereisstilloftenthechancethatthepopulationwillbecomestuckinoneormorelocaloptima.Mutationprovidesaguaranteethat,withsomeprobability,thepopulationwillspontaneouslydiscovernewlocaloptima.Ifthebestelementofeachgenerationispreserved,atechniquecalledelitism,thenmutationprovidesaguaranteeofeventualconvergencetotheglobaloptimum. ThecanonicalproblemforgeneticalgorithmsistheTravelingSalesmanProblemTSP.Informally,theproblemistondtheshortestpaththroughacollectionofcitiessothatatravelingsalesmanvisitseachoneandreturnshome.Moreformally,consideracompletegraphwhereeachedgehasaweight,ndaHamiltoniancyclesuchthatthesumoftheweightsoftheedgesusedisminimal.Ifweaddtheconstraintthattheedgeweightsformametricthenthefeasiblesolutionsarepermutationsofthevertices.TheconstrainedproblemiscalledthemetricTSP.GeneticalgorithmswhichattempttosolvetheTSPworkbyencodingthegenomeandchoosingoperatorssuchthatecientpathsinafeasiblesolutionarepreservedandthatecientpathsarecombinedinsuccessivegenerations.TheobservationthatdrivesmuchofthedirectionofthisworkisthatifweencodefeasiblesolutionstoametricTSPasanintegerbetween1andn!andoperateonthisencodingatthebitlevelweareunlikelytodevelopoperatorswhichpreserveandcombineecientpaths.If,however,weencodethesolutionsaspermutationswehavesomechanceofoperatingonsolutionsinwaysthatdopreservethesequalities[27]. PAGE 37 InverseSpectralProblemforInverseSpectralProblems16 1.7InverseSpectralProblemforInverseSpectral ProblemsIfwewishtoconstructageneticalgorithmtondtherotationalconstantsofamoleculethenaveapproachistoencodethemomentsofinertiaandparametersintoagenomeusingbitstringsforeach.Asnotedearlierthistechniquehasmetwithonlymixedsuccess.Inparticularifthespectrumwearetryingtotissucientlycomplex,wherethebenetsofageneticalgorithmshouldcauseittoexcelithasbeenfoundlacking[16].Thedrivingideabehindthisworkisthatwemayunraveltherotationalconstantsandinsteadencodetheenergiesofthequantumstates;thatis,theeigenvaluesoftheHamiltonian.Thisschemeprovidesavenuesbywhichwemayinformthealgorithmtowardsawelltsolution.Wemaymakeuseofthedatawearetryingtot,thatis,thespectrum.WhileitdoesnotcontaindirectinformationabouttheeigenvaluesoftheHamiltonianitdoescontaininformationaboutdierencesbetweeneigenvalues.TherearerelationshipsbetweentheparameterswhichareencodedintheHamiltonianwhichmaybeusedtorestrictthesearchspace.Last,thisencodingprovidesamethodbywhichwelltsetsofeigenvaluesmaybepreservedwithhighprobabilityduringcrossover.Wewillseethatthisschemepresentsanewquestion:IfweknowtheformoftheHamiltonianasafunctionoftheparameterswewishtoestimateandweknowtheeigenvaluescanweconstructtheHamiltoniantowithinacceptableaccuracy?Wewillattempttosolvethisproblemusingageneticalgorithm. PAGE 38 Chapter2 FittingAnglesandEigenvalues 2.1OverviewInthischapterweexaminethestructureofanapproximationoftheHamiltonianfortherotationalenergyofamolecule.Weexaminehowwemightencodeageneticalgorithmtosolvethespectralttingproblem,theproblemsencounteredandapotentialsolution. 2.2HamiltonianfortheSemi-RigidRotorWemustrstunderstandthestructureoftheHamiltonianwithwhichweareworking.TheHamiltonianisestimatedbymodelingthemoleculeasasemi-rigidrotorwheretheatomicbondsaremodeledusingHooke'slaw.Accordingto[28]wewritetheHamiltonianasablockdiagonalintheprincipalquantumnumberJ,whereeachblockisasquarematrixofdimension2J+1.Withineachblockthenon-zerotermsareonthe5-bandalongthemaindiagonalasshownintheexamplein2.2wheretheentries17 PAGE 39 HamiltonianfortheSemi-RigidRotor18 correspondtotheJ=7blockofisopropanol.Thediagonalsoneithersideofthemaindiagonalcontain0;thustherearethreediagonalsofnon-zeroelementstoconsider. 0 B B B B B B B B B B B B B B B B B @ 460788015632000 ::: 0433672025066 : 200 ::: 1563204107300326070 ::: 0250660391960038427 ::: 003260703773620 ::: 000384270366935 ::: 1 C C C C C C C C C C C C C C C C C A .1Ifweletk 1 ;k 2rangefrom)]TJ/F57 11.9552 Tf 9.298 0 Td [(JtoJandwrite`=k 1+J+1andm=k 2+J+1wehaveentriesH J= h J m;` whereH JwilldenotetheJsub-blockoftheHamiltonian.Recallingthedenitionsofvariousconstantsonpage4wecanwritedowntheelementsoftheHamiltonianblocks.ForagivenJvalue,onthemaindiagonal,wherem=` wehave h J m;` = B + C J J +1 2 + A )]TJ/F15 11.9552 Tf 13.151 8.088 Td [( B + C 2 k 2 1 )]TJ/F62 11.9552 Tf 11.955 9.684 Td [()]TJ/F15 11.9552 Tf 5.479 -9.684 Td [( j J 2 J +1 2 + jk k 2 1 J J +1+ k k 4 1 PAGE 40 HamiltonianfortheSemi-RigidRotor19 Onthelowerdiagonal,where m = ` )]TJ/F15 11.9552 Tf 11.955 0 Td [(2wehave h J m;` = B )]TJ/F57 11.9552 Tf 11.956 0 Td [(C 4 )]TJ/F57 11.9552 Tf 11.955 0 Td [(J J +1 j )]TJ/F62 11.9552 Tf 11.955 9.683 Td [()]TJ/F57 11.9552 Tf 5.48 -9.683 Td [(k 2 1 + k 2 2 k 2 p J J +1 )]TJ/F15 11.9552 Tf 11.955 0 Td [( k 1 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 k 1 )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 J J +1 )]TJ/F57 11.9552 Tf 11.955 0 Td [(k 1 k 1 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 Ontheupperdiagonal,where m = ` +2wehave h J m;` = B )]TJ/F57 11.9552 Tf 11.955 0 Td [(C 4 )]TJ/F57 11.9552 Tf 11.956 0 Td [(J J +1 j )]TJ/F62 11.9552 Tf 11.955 9.684 Td [()]TJ/F57 11.9552 Tf 5.48 -9.684 Td [(k 2 1 + k 2 2 k 2 p J J +1 )]TJ/F15 11.9552 Tf 11.955 0 Td [( k 1 +1 k 1 +2 J J +1 )]TJ/F57 11.9552 Tf 11.955 0 Td [(k 1 k 1 +1 Inparticularwehave H 1 = 0 B B B B @ 2 A + B + C )]TJ/F56 7.9701 Tf 6.587 0 Td [(8 j )]TJ/F56 7.9701 Tf 6.587 0 Td [(4 jk )]TJ/F56 7.9701 Tf 6.586 0 Td [(2 k 2 0 B )]TJ/F58 7.9701 Tf 6.587 0 Td [(C )]TJ/F56 7.9701 Tf 6.587 0 Td [(8 j )]TJ/F56 7.9701 Tf 6.586 0 Td [(4 k 2 0 B + C )]TJ/F15 11.9552 Tf 11.955 0 Td [(4 j 0 B )]TJ/F58 7.9701 Tf 6.586 0 Td [(C )]TJ/F56 7.9701 Tf 6.586 0 Td [(8 j )]TJ/F56 7.9701 Tf 6.587 0 Td [(4 k 2 0 2 A + B + C )]TJ/F56 7.9701 Tf 6.586 0 Td [(8 j )]TJ/F56 7.9701 Tf 6.587 0 Td [(4 jk )]TJ/F56 7.9701 Tf 6.586 0 Td [(2 k 2 1 C C C C AFromthiswecanseethat,unlessthereissymmetry,H 1haseigenvectors,uptoscalingandsign,of # v 1 = ; 0 ; 1 T .2 # v 2 = ; 1 ; 0 T .3 # v 3 = )]TJ/F15 11.9552 Tf 9.298 0 Td [(1 ; 0 ; 1 T .4 PAGE 41 ProblemsBegetProblems20 withcorrespondingeigenvalues 1 = A + B )]TJ/F15 11.9552 Tf 11.955 0 Td [(4 j )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 jk )]TJ/F15 11.9552 Tf 11.955 0 Td [( k )]TJ/F15 11.9552 Tf 11.955 0 Td [(4 j )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 k .5 2 = B + C )]TJ/F15 11.9552 Tf 11.955 0 Td [(5 j .6 3 = A + C )]TJ/F15 11.9552 Tf 11.955 0 Td [(4 j )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 jk )]TJ/F15 11.9552 Tf 11.956 0 Td [( k +4 j )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 k .7Notethattheeigenvectorsinthiscasedonotdependontherotationalconstants.ComputationwillshowthatthispropertyisuniquetotheJ=1block;moreoverdeningtheeigenvectorsintermsofthemomentsofinertiaanddistortionparametersbecomesincreasinglycomplexathigher J levels. 2.3ProblemsBegetProblems 2.3.1ASimplerProblemWeattempttosolvethefollowingproblemasaproofofconcept;usingtherigidrotorapproximationndtheeigenvectorsassociatedwiththeH 1blockoftheHamiltoniangivenin2.8usingageneticalgorithm.ClearlywecouldcomputetheHamiltoniandirectlyfromtheeigenvectorsviaalgebra;howeverweconstructthissolutionasameansoftestingtheconceptweintendtouseinamoregeneralsetting. 0 B B B B @ 2 A + B + C 2 0 B )]TJ/F58 7.9701 Tf 6.587 0 Td [(C 2 0 B + C 0 B )]TJ/F58 7.9701 Tf 6.586 0 Td [(C 2 0 2 A + B + C 2 1 C C C C A .8 PAGE 42 ProblemsBegetProblems21 Wecanseethattheentriesofthismatrixgive3independentequationsin3variablesbylookingatthecoecientmatrixin2.9.Thismatrixisconstructedfromthecoecientsofthevariablesinthematrix2.8.Notethatthesingularvaluesof2.9aref 2 ; 1 ; 1 g ;thuswehavesomehopeofsolvingthisproblem. 0 B B B B B B B B B B B B B B B B B B B B B B B @ 1 1 2 1 2 000 0 1 2 )]TJ/F56 7.9701 Tf 10.494 4.707 Td [(1 2 000 011 000 0 1 2 )]TJ/F56 7.9701 Tf 10.494 4.707 Td [(1 2 000 1 1 2 1 2 1 C C C C C C C C C C C C C C C C C C C C C C C A .9TheeigenvectormatrixforH 1,uptoscaling,isgivenin2.10;thisisthetargetforourconceptalgorithm. 0 B B B B @ 1 )]TJ/F15 11.9552 Tf 9.299 0 Td [(10 001 110 1 C C C C A .10Wemustunderstandwhatafeasiblesolutiontothisproblemlookslike.SincetheHamiltoniansub-blockisarealsymmetricpositivedenitematrixthesetofnormalizedeigenvectorsareorthogonalandhavedeterminant1.Ifweconstructany33matrixwehavesmallprobabilityofconstructingsuchamatrix.Moreover,givensuchamatrixanysmallperturbationofelementsofthematrixwilllikelydestroythese PAGE 43 ProblemsBegetProblems22 property.Noticing,however,thatingeneralthegroupSO nRisthesetofmatriceswiththispropertywecanchoseourfeasiblesolutionsfromthisgroup.SO nRisgeneratedbyplanerotationsineachofthe )]TJ/F58 7.9701 Tf 5.48 -4.379 Td [(n 2 planes.Wecanconstructafeasiblesolutiontothisproblemfromthesetof)]TJ/F56 7.9701 Tf 5.48 -4.379 Td [(3 2 =3anglesf 1 ; 2 ; 3 gandeigenvaluesf 1 ; 2 ; 3 g.WeconstructQ,theeigenvectormatrixasaproductofthethreerotationmatrices2.11,2.12,2.13.LetQ=R 1 ; 2 R 1 ; 3 R 2 ; 3.Letbethediagonalmatrixwiththeeigenvaluesf k gonthediagonal.TheHamiltonianassociatedwiththeanglesandeigenvaluesis ~ H 1 = Q Q )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 R 1 ; 2 1 = 0 B B B B @ cos 1 )]TJ/F15 11.9552 Tf 11.291 0 Td [(sin 1 0 sin 1 cos 1 0 001 1 C C C C A .11 R 1 ; 3 2 = 0 B B B B @ cos 2 0 )]TJ/F15 11.9552 Tf 11.291 0 Td [(sin 2 010 sin 2 0cos 2 1 C C C C A .12 R 2 ; 3 3 = 0 B B B B @ 100 0cos 3 )]TJ/F15 11.9552 Tf 11.291 0 Td [(sin 3 0sin 3 cos 3 1 C C C C A .13IfweconstructasimulatedspectrumofsixtransitionsgeneratedbytheJ=1blockwemighthopetobuildanalgorithmwhichtstheeigenvaluestothespectrumwhileatthesametimettingtheanglestotheeigenvaluessuchthatthecomputed PAGE 44 ProblemsBegetProblems23 estimateoftheHamiltonian,~ H 1matchestheformgivenin2.8.Wecancomputetnessoftheestimate~ H 1againsttheprescribedformbycomputingaregressionoftheentriesin ~ H 1 againstthecoecientmatrixin2.9. 2.3.2GeneticAlgorithmforthe H 1 ProblemWedescribethecomponentsofthegeneticalgorithmusedtosolvetheproblemdiscussedintheprevioussection. SolutionRepresentationWeconstructthegenomeofthegeneticalgorithmasthesetofanglesf k gandeigenvalues f k g FitnessFunctionThetnessfunctioniscomprisedoftwofunctions;onetomeasurehowclosethematrix~ H 1istotheformoftheHamiltoniangiven,thesecondtomeasurehowfarthecomputedspectrumliesfromthetargetspectrum.Therstfunction,calledtheresidualfunction,worksbycomputing^ H 1,thenlistingtheelementsofthematrixincolumnmajororderandperformingaleastsquaresregressionagainstthecoecientmatrix2.9andsolvingtheleastsquaresprobleminequation2.14.Then,usingthevaluesfoundin2.14computetheassociatedHamiltonian ~ H 1 ;theresidualsisthen ~ H 1 )]TJ/F15 11.9552 Tf 14.99 3.022 Td [(^ H 1 2 . PAGE 45 ProblemsBegetProblems24 0 B B B B B B B B B B B B B B B B B B B B B B B @ 1 1 2 1 2 000 0 1 2 )]TJ/F56 7.9701 Tf 10.494 4.707 Td [(1 2 000 011 000 0 1 2 )]TJ/F56 7.9701 Tf 10.494 4.707 Td [(1 2 000 1 1 2 1 2 1 C C C C C C C C C C C C C C C C C C C C C C C A 0 B B B B @ A B C 1 C C C C A = 0 B B B B B B B B B B B B B B B B B B B B B B B @ ^ H 1 ; 1 ^ H 1 ; 2 ^ H 1 ; 3 ^ H 2 ; 1 ^ H 2 ; 2 ^ H 2 ; 3 ^ H 3 ; 1 ^ H 3 ; 2 ^ H 3 ; 3 1 C C C C C C C C C C C C C C C C C C C C C C C A .14Thesecondfunction,calledthespectraldierencefunction,worksbyconsideringaboundedfrequencyrange,dividingthatrangeintoblocksandconstructingavectort 1 ;t 2 ;:::;t kwhereeacht iisthesumoftheintensitiesinthatblock.Forthetestproblemwewillconstructatestspectrumwhereeachtransitionhasanintensityof1andassignanintensityof1toeachpermissibletransitiongeneratedfromtheeigenvaluesof f H 1 .Theeigenvaluesofthematrixin2.8are 1 = A + B .15 2 = B + C .16 3 = A + C .17 andrecallingthat A B C wehavethat 1 3 2 ;thusthetransitionsare f 1 ; 3 ; 2 ; 1 )]TJ/F57 11.9552 Tf 11.955 0 Td [( 3 ; 1 )]TJ/F57 11.9552 Tf 11.955 0 Td [( 2 ; 3 )]TJ/F57 11.9552 Tf 11.955 0 Td [( 1 g .18 PAGE 46 ProblemsBegetProblems25 Thespectraldierenceisthenthecosineofthevectorrepresentingthecomputedspectrumandthevectorrepresentingthetargetspectrum.Theresidualfunctionandthespectraldierencefunctionarebothfunctionswewishtominimizesotheoveralltnessfunctionforthegeneticalgorithmisthesumofthese. Selection Forselectionwechooseastandardroulettewheelapproach. CrossoverForcrossoverweuseuniformcrossoveronthesetsofvalues;thatis,wetakeeachangleoreigenvectorfromoneofthetwoparentsasopposedtoabitwisecrossover. MutationWemutateonthegenomeatthebitlevel.Sincetheelementsareoatingpointnumbersandtheanglesaretobewithin[0;2wecheckthatthemutatedvalueisvalidandaborttheresultifitisnot. ConstraintsTheconstructionoftheHamiltoniandependsontheconstraintthatA B C.Ourconstructionofasolution,tothispoint,doesnotenforcethisproperty.Forthisproblemwendthatwecanpermutetheorderingoftheeigenvaluesintheconstructionofthediagonaleigenvaluematrixasnecessarytoachievesatisfactionoftheconstraint. PAGE 47 ProblemsBegetProblems26 2.3.3AlgorithmPerformance Figure2.1:Surfacefor 2 and 3Thisalgorithmperformsdismally.Thereisastronggradientinthecomponentt-nessfunctionfortheleastsquaresresid-uals.Ifweexaminethesurfacecreatedbyxingtheangles 1= 2, 2=2 3and 3=3 5thenxingoneeigenvalue 1=15000,thenvarying 2and 3wecanseethedeepgradientinFigure2.1.Ifweexaminethesurfacecreatedbyxingtwoanglesat 1=0and 2=andtheeigenvaluesat 1=12500and 2=17500inFigure2.2wehopetondaminimumat=3 4andanyeigenvalue;howeverwecanseethatthereisasharpminimumat 3 =15000whichcorresponds to min 3 p 1 )]TJ/F57 11.9552 Tf 11.955 0 Td [( 3 2 + 2 )]TJ/F57 11.9552 Tf 11.955 0 Td [( 3 2 .19Thusregressionalonewilldriveanysolutiontowardshavingequaleigenvalues.Sincethesecondcomponentofthetnessfunctionisadiscretefunctionwithonly4valuesthereisinsucientresolutiontocorrecttheundesiredphenomenaoftheregressioncomponentusingthecosinecomponent. PAGE 48 ProblemsBegetProblems27 Sphericity Figure2.2:Surfacefor 3 and 3Weattempttocorrectthedefectinthetnessfunctionbyexaminingthenotionofsphericity.Sincethefunctiondrivesthealgorithmtowardssymmetric,thatis,sphericalsolutionsweconsideridentify-ingameasureofsphericityandfactoringoutbythismeasure.Sincethemethodsofspectroscopyinquestiondependonpolarmoleculeswehavesmallchanceofencounteringsphericalmoleculesinpractice;thusweneednotworryaboutexcludingpossiblecorrectresults.WeattempttofactoroutbythesphericityoftheeigenvaluesinsomewaytoremovethegradientsothatthesurfaceinFigure2.2hasaminimumatanyeigenvalueandonlyattheappropriateangle. Letthe volume ofthemoleculebedenedby V p = 4 3 A B C .20 andapproximatethesurface area by S p 4 A p B p + A p C p + B p C p 3 1 p .21 Peanoestimatedthat4 AB + AC + BC 3 A pandPolyaestimatedthatA p 4 A 2 B 2 + A 2 C 2 + B 2 C 2 3 1 2 asnotedin[29]. PAGE 49 ProblemsBegetProblems28 where p istakentobe1 : 58.Sphericityisdenedin[30]by. = 1 3 V p 2 3 S p .22Thesphericitycanbeseentorangefrom0to1,with1beingperfectlyspherical.Multiplyingtheresidualbyxproducesasphericitypenaltywheretheexponentialgivesusanorderpreservingbijectionfrom[0;1]![0;1]suitablefortuningthepenalty.Attemptstousethemeasureofsphericitytodivideoutthetendencytowardsasphericalsolutionwereunsuccessful.Computationwillshowthattheregressionislinearinthelimitasit'sthesquarerootofaseconddegreepolynomialinthreevariables.Thesphericitycomputationisapproximatelyorder)]TJ/F56 7.9701 Tf 10.494 4.707 Td [(1 3;thusitisunabletofactoroutthesphericityofthesolution. LinearFactor Figure2.3:Surfacefor xWeconsiderasimpleonedi-mensionalobjectivefunctionp )]TJ/F57 11.9552 Tf 11.955 0 Td [(x 2 + )]TJ/F57 11.9552 Tf 11.955 0 Td [(x 2.Wewishtomodifythisbysomelinearfactor,sayj 15000 )]TJ/F57 11.9552 Tf 11.956 0 Td [(x j;butthisresultsinthesharppeakshowninFigure2.3. ConclusionWecannotndanappropriatefactorwhichwillallowustoremovethestrongtendencytowardsasphericalsolution PAGE 50 DivisionofLabor29 withoutdestroyingimportantinformationaboutthemoleculeinthetnessfunction;thereforeweareunabletotboththeeigenvaluesandtheanglesatthesametime. 2.4DivisionofLaborFindinganalgorithmandobjectivefunctionwhichdrivestheeigenvaluesandangleswhichdenetheeigenvectorsatthesametimeappearstobedicult;andtheauthorisunimaginative.Insteadweexamineamultiphasealgorithm.Givenarangeforthemomentsofinertiaanddistortionweperformthefollowing 1.Constructapopulationofestimatesusingguessedmomentsofinertiaanddistortionparameters 2.ConstructHamiltonian J -blocksusingguessedparameters 3.Computetheeigenvaluesoftheestimate 4.Usingageneticalgorithmestimatetheanglesassociatedwiththeeigenvaluematrixfortheeigendecomposition 5.RecomputeparametersbasedonaregressionoftherecomputedHamiltonianJ -blocksusing Q Q T productwhere Q iscomputedfromtheangles 6.Matesetsofeigenvaluestoformaneweigenvaluepopulation 7.Mutate 8.Gotostep4Withthisalgorithmwecanintroduceprophaseinductionwhereourknowledgeofthedierencesineigenvaluescanbeusedtoinject"DNAintothegenomefrom PAGE 51 DivisionofLabor30 theenvironment.RandomlypickapairofeigenvaluesineitherneighboringJ-blocksorwithinasingleJ-block.Randomlypickatransitionfrequencyfromthedatawearetryingtomatch.Changetheeigenvaluessuchthattheymatchthetransitionfrequency y 2.4.1ProofofConcept Figure2.4:Surfacefor 2 and 3Ifwemodifythealgorithmdescribedabovesothateveryelementofthepop-ulationhasthesameeigenvaluesandweonlydrivetheangleswendthatthealgorithmconvergesrapidly.Thisshowsthatwemightconstructanalgorithmtoperformstep4withsomesuccess.More-overjudgingbyFigure2.4wecanseethatthesurfaceiswellsuitedtogradientde-scentoncewearewithinaconvexportionofthesurfacecontainingtheminimumifnecessary.WetestsuchanalgorithmusingtheJ=1blockandtherigidrotorapproximation.Weuseuniformcrossoverandroulettewheelselection.Withapopulationof100elementsandamutationrateof:001wendthealgorithmshowssignsofconvergence IfweassumethatourmethodofconstructingeigenvaluesresultedintheeigenvaluesofaparticularJblocktobesomewhatclosetotheactualvalueswemightlimitourrandomsearchtosomethingontheorderofmagnitudeoftransitionimpliedbyourguess.Possiblyfromanon-uniformsingle-modedistributionwherethemodeisj 1 )]TJ/F11 9.9626 Tf 9.963 0 Td [( 2 jandwhichisappropriatelylongtailed. yYettodetermineifweshouldchangeonlyoneeigenvaluesothatthedierencematchesorbotheigenvaluesbyhalf,orbyaweightedamountsothatthedierencematchesthetransition. PAGE 52 DivisionofLabor31 fromcrossoverforseveralgenerationsbeforesettlingdowntoconvergencefrommutation.Increasingthepopulationsizeappearstoincreasethenumberofgenerationsthatconvergenceresultsfromcrossoverasexpected. PAGE 53 Chapter3 ANewHopeWebrieyrestatetheprobleminageneralsetting.GivenaHamiltonianforasystemdenedintermsofasetofparametersandgivenasetofeigenvaluesforaniteestimationoftheHamiltonianestimatetheeigenvectorswhich,whencombinedwiththeeigenvalues,determinetheparametersusingtheeigendecompositionH=QQ )]TJ/F56 7.9701 Tf 6.587 0 Td [(1.SinceHamiltoniansarerealsymmetricpositivedenitematricesthecolumnsofQcanbenormalizedandwecanassumethatQ 2 SO nR.SincewecannotperturbasingleelementofQandhopetomaintainorthogonalitywefactorQintoaproductofrotationmatricesforeachofthe)]TJ/F58 7.9701 Tf 5.479 -4.379 Td [(n 2 planes.WewriteQ=Q R j;k j;kwherej PAGE 54 GeneticOperators33 coecientmatrixtoestimatetheparameters;thencomputetheestimatematrixf H Jbymultiplyingthecoecientmatrixbytheparametersfound.Wemeasurethetnessofthissolutionby c H J )]TJ/F62 11.9552 Tf 14.225 3.753 Td [(f H J 2 .AnexamplecomputationisgiveninAppendixA. 3.1GeneticOperators 3.1.1SelectionSelectionusesroulettewheelchoice.SinceweareminimizingthetnessfunctiontheelementswiththelowestscoresshouldhavethehighestprobabilityofreproductionsoforeachtnessscorefXwegiveaproportionofthewheelbasedon1 f X .ThetotalP k 1 f X k isusedtonormalizethelistofinversescoresandelementsarechosenbyuniformrandomnumbersin[0 ; 1. 3.1.2CrossoverTherearetwocrossoverschemesimplemented,uniformcrossoverandsinglepointcrossover.Uniformcrossoverwastheinitialchoice;however,whenconsideringthefactthatmatrixmultiplicationisnotcommutativewerealizedthatasetofparticularlytanglesinsequencemaybecompletelyuntifonlyoneoftheanglesintheinteriorarechanged.Toincreasetheprobabilityofpreservingtgroupsofanglesinsequenceweimplementedsinglepointcrossover. Wewillswitchbetweenthinkingofg H Jasann nvectorandann nmatrixbywritingdownthematrixfromthevectorincolumnmajororderandassociatethesetworepresentationswitheachotherascontextdemands. PAGE 55 GPU34 3.1.3MutationMutationisimplementedatthebitlevel.Wethinkofeachbitasanucleotideandtheentireoatingpointnumberasthegene.Themutationratexestheprobabilitythateachbitmaybemutated.Becauseofthestructureofoatingpointnumberstheeectofasinglebitmutationvariesbasedonthelocationofthemutation.Amutationintheexponentportionwilllikelyhavegreateect,likelymakingtheresultinggenomeunviable,whereasamutationintheleastsignicantbitswillhavesmalleect. 3.1.4VericationAftertheoperatorsproduceanewpotentialsolutionthatsolutionmustbecheckedtoseethatitisviable.Anglesthatareoutsideoftherange[0;2resultinannon-viablesolution.Moreover,ifthesolutionproducesaleastsquarestwhichviolatestheconditionA B Cthenthesolutionisnon-viable.Thesesolutionsaredestroyedandanewsolutionisgeneratedinitsplaceuntilaviablesolutionisfound. 3.1.5FixedGenomeSincetheanglesforJ=1areknownandxedwexthoseanglesinthegenomeandshortcircuitthecomputationoftheblockitgenerates. 3.2GPUWemakeuseofnVidiaGTX680graphicscardsforlinearalgebracomputations;however,notallcomputationscanbeecientlyooadedtotheGPU.TheCUDABLASlibrary[31]makesportingcomputationsperformedwithBLASrelatively PAGE 56 Results35 straightforward;howevertherearesomeissuestheprogrammermustbeawareof.ComputationontheGPUrequiresthatmemoryforthematricesbeallocatedontheGPUandthematricesbeuploadedtotheGPUbeforecomputation.ThismeansthatCUBLAScannotbeadirectdropinreplacementforATLASBLAS.Moreover,thereisoverheadassociatedwithcomputingonaGPU.WhereastheInteli7-3770processorhasamemorybandwidthof25:6GB/s[32]andtheBLASlibrariescanmakeextensiveuseofprocessorcachesduringcomputation,computationonthenVidiaGTX690dependsonaapproximately16GB/stransferbus[33]halfwithtwocardsperbusbeforemakinguseofaninternal192.2GB/smemorybandwidth[34].OnceontheGPUtheGTX680hasaprocessorspeedofonly1:006GHzcomparedwith3:4GHzfortheIntelprocessor.Thismeansthatsmallmatriceswhichcannotmakeuseofthe1536coresorwhichtakealargeamountoftimetotransferrelativetotheperformanceboostoftheGPUarenotsuitedtoGPUcomputation.Inouralgorithmwecan,however,mitigatethisbytransferringonlytheanglesratherthantherotationmatrices,buildingthematricesontheGPUandcomputingtheproductofmanymatrixmultiplicationsatthesametime.ThesetechniquearedescribedinSection4.1.5inexaminationofthealgorithmusedforcomputation.TheendresultisthatwewereonlyabletomakeuseoftheGPUforcomputationsofblocksatJ=17andhigher. 3.3ResultsIntheseexperimentsweuseparameterslistedasExpectedValuetogeneratethetargetHamiltonianbasedoncomputationsin[5].Fromthiswecomputeeigenvaluesusedasourtargets.Ineachexperimentthetargetisthesame.Welistthemeach PAGE 57 Results36 Parameter ExpectedValue EstimatedValue %ErrorAbsolute A 8 : 488888 10 3 9 : 642750 10 3 13 : 135926% B 8 : 041802 10 3 8 : 430228 10 3 4 : 830095% C 4 : 765117 10 3 2 : 987855 10 3 37 : 297342% j 0 )]TJ/F15 11.9552 Tf 9.298 0 Td [(3 : 472085 10 2 jk 2 : 242 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(3 3 : 367119 10 2 15018400% k )]TJ/F15 11.9552 Tf 9.299 0 Td [(6 : 048 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 1 : 1748541 10 3 19425500% j )]TJ/F15 11.9552 Tf 9.299 0 Td [(1 : 462 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 1 : 165531 10 2 7972170% k )]TJ/F15 11.9552 Tf 9.299 0 Td [(2 : 351 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 3 : 083103 10 2 13114000% Figure3.1:Phase1Resultstimeforreference.ThealgorithmisrunonanInteli7-3770processorat3.4GHzwithfournVidiaGTX690GPUsforcomputingblocksfor J =17orhigher. 3.3.1Phase1WerunthealgorithmforJ=1throughJ=2withapopulationof1024for10,000generations.Thealgorithmtakesapproximately2minutes45secondstorun.Theseblockstheoreticallycontainenoughinformationtoconvergeonasolution.Unfortunately,thealgorithmdoesnotconvergetoagoodsolution.TheresultsaresummarizedinFigure3.1.Whilethemomentsofinertiawerenotestimatedtoanyrealdegreewenoticethattheestimatesofthedistortionparametersareseveralordersofmagnitudebigger.Therearetwoaspectsoftheseresultstonote.Therstisthatthemomentsofinertiaareobyaconsiderableamount;weexpecttobeabletoestimatethemtoseveraldecimalplacesratherthantowithin40%.Thesecondisthatthedistortionparametersarenotjusto,buttheyareobyordersofmagnitude.Thisraisesthequestionofwhetherit'sevenpossibleforthisalgorithmtoestimatethesevaluestoanymeaningfuldegree. PAGE 58 Results37 ConsidertheJ=1blockwitheigenvaluesf 16530 : 7 ; 13254 :; 12806 : 9 gandangles 1 ; 2=0, 1 ; 3= 4and 2 ; 3= 2.AsnotedinAppendixA,theseanglesminimizethetnessfunction.Theyproducetheblock 0 B B B B @ 14892 : 301638 : 35 012806 : 90 1638 : 35014892 : 3 1 C C C C A .1 Ifweperturbavalue,say 1 ; 2 by theresultis 0 B B B B @ 13849 : 6+1042 : 73cos 1042 : 73sin 1638 : 35cos 1042 : 73sin 13849 : 6 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1042 : 73cos 1638 : 35sin 1638 : 35cos 1638 : 35sin 14892 : 3 1 C C C C A .2 Thisgivesaparameterestimateof 0 B B B B @ 7446 : 71+1042 : 73cos 6924 : 81+1638 : 35cos )]TJ/F15 11.9552 Tf 11.955 0 Td [(521 : 363cos 6924 : 81 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1638 : 35cos )]TJ/F15 11.9552 Tf 11.955 0 Td [(521 : 363cos 1 C C C C A .3 withanestimateof 0 B B B B @ 14371+521 : 363cos 01638 : 35cos 013849 : 6 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1042 : 73cos 0 1638 : 35cos 014371+521 : 363cos 1 C C C C A .4Wecanseefrom3.4howsmallperturbationsareamplied.WhiletheJ=2andhigher PAGE 59 Results38 Parameter ExpectedValue EstimatedValue %Error Absolute A 8 : 488888 10 3 9 : 527545 10 3 2 : 194608 10 2 12 : 2355% B 8 : 041802 10 3 8 : 227920 10 3 3 : 905650 10 2 14 : 7494% C 4 : 765117 10 3 3 : 270091 10 3 4 : 115143 10 2 31 : 3744% j 0 3 : 272955 10 2 3 : 230572 10 1 jk 2 : 242 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(3 3 : 018059 10 2 2 : 866421 10 2 13461500% k )]TJ/F15 11.9552 Tf 9.299 0 Td [(6 : 048 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 1 : 394564 10 3 3 : 587100 10 2 23058300% j )]TJ/F15 11.9552 Tf 9.299 0 Td [(1 : 462 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 1 : 957071 10 2 7 : 870438 10 1 13386300% k )]TJ/F15 11.9552 Tf 9.299 0 Td [(2 : 351 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 3 : 131655 10 2 1 : 299216 10 2 13320500% Figure3.2:Phase2Resultsblocksarediculttoanalyzeonpaper,ifweconsiderhowtheblockiscomposedasproducts)]TJ/F56 7.9701 Tf 5.48 -4.378 Td [(2 J +1 2 rotationmatriceswecanimaginehowtheeectofasinglesmallperturbationisreducedastheproductsofadditionalanglesaretaken;thustoachieveaccuracywiththesmalldistortionparameterswemustcomputewithhigherenergylevels.Thisresultisconsistentwithourintuitionthatthecentrifugaldistortiononlybecomesnoticeableathigherlevelsofangularmomentum. 3.3.2Phase2InPhase2wecheckthattheresultsofPhase1arenotstatisticalaberrations.Werunthesamealgorithmwiththesameparameters1000timesandcomputeaveragesandstandarddeviationsoftherotationalconstants.TheresultsaresummarizedinFigure3.2.Forthedistortionparameterswecomputestatisticsontheabsolutevalueinordertoassessthemagnitudeofthevalues.TheresultssupporttheconclusionsofthePhase1analysis. PAGE 60 Results39 Parameter ExpectedValue EstimatedValue %ErrorAbsolute A 8 : 488888 10 3 1 : 221364 10 4 43 : 878% B 8 : 041802 10 3 5 : 947493 10 3 26 : 0428% C 4 : 765117 10 3 3 : 134660 10 3 34 : 2165% j 0 )]TJ/F15 11.9552 Tf 9.298 0 Td [(2 : 795638 10 0 jk 2 : 242 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(3 8 : 360717 10 0 372913% k )]TJ/F15 11.9552 Tf 9.299 0 Td [(6 : 048 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 4 : 135131 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(2 683 : 719% j )]TJ/F15 11.9552 Tf 9.299 0 Td [(1 : 462 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 7 : 221882 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 49397 : 3% k )]TJ/F15 11.9552 Tf 9.299 0 Td [(2 : 351 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 2 : 879877 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 12249 : 6% Figure3.3:Phase3Results 3.3.3Phase3InPhase1and2wesawthatthealgorithmwasunabletoestimatethedistortionparametersanditsestimatewasobyseveralordersofmagnitude.Wetheorizedthatthisinabilitywasrelatedtothecoarsenessoftheresultwithrespecttosmallperturbationsinthegenome.IfthisisthecasethenwehypothesizethatthealgorithmrunningwithonlyhighJvaluesshouldtargetthedistortionparametersbetter.WerunthealgorithmforJ=29andJ=30forvegenerations.Wenotethatthemutationratemustbesubstantiallyreducedsincethe3541anglesinthegenomeprovideextensiveopportunityformutationtoresultinanon-viablesolutionwhichmustbediscardedandtheprocessisunlikelytoterminateinareasonableamountoftimeforevenasinglegeneration.Wexthemaximummutationrateat:001.Thisrunsforapproximately11minutesand33seconds.TheresultsaresummarizedinFigure3.3.Asweonlyranthealgorithmforvegenerationsit'shardtodrawconclusionsaboutthemomentsofinertia;ontheotherhandwecaneasilyconcludethatweachievedthehypothesizedimprovementinthedistortionparameters.Ofinterestistonotethatoverthevegenerationssevenoftheeightparametersactuallymovedinthewrongdirection.Wecomparetheinitialbestelementofthe PAGE 61 Conclusion40 Parameter Initial Generation5 A 8 : 890951 10 3 1 : 221364 10 4 B 7 : 062120 10 3 5 : 947493 10 3 C 4 : 34258 10 3 3 : 134660 10 3 j )]TJ/F15 11.9552 Tf 9.299 0 Td [(9 : 674310 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 )]TJ/F15 11.9552 Tf 9.299 0 Td [(2 : 795638 10 0 jk 2 : 466565 10 0 8 : 360717 10 0 k 7 : 239022 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 4 : 135131 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(2 j 5 : 357713 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 7 : 221882 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 k )]TJ/F15 11.9552 Tf 9.299 0 Td [(3 : 769969 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 2 : 879877 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 Fitness 1 : 034050 10 7 1 : 033350 10 7 Figure3.4:Phase3Initialvs.FinalpopulationtothenalinFigure3.4.Despitethelargechangeinmomentsofinertiatheoveralltnesswaschangedonlyslightly.Thisgivessomeindicationofthecomplicatednatureofthetnesslandscapeforthisalgorithm. 3.3.4Phase4InPhase3wesawthatusingonlyhighJvaluesresultedintheestimatedmomentsofinertiabeingdrivenawayfromthetargetvalues.Werunthealgorithmwithapopulationsizeof1024for25generationsusingJvaluesfrom1to30toseeifincludingthelowJvaluesstabilizesthemomentsofinertia.Wexthemaximummutationrateat:001.Thealgorithmtakesapproximately240minutestorun.TheresultsaresummarizedinFigure3.5.Inthiscasewedidnotseetheestimatedvaluesmoveawayfromthetargetvalues. 3.4ConclusionWeconcludethatanalgorithmthatattemptstottherotationalconstantsA,BandCrequirescomputingonalowJblock.Analgorithmthatattemptstotthe PAGE 62 Conclusion41 Parameter ExpectedValue EstimatedValue %ErrorAbsolute A 8 : 488888 10 3 7 : 236227 10 3 14 : 7565% B 8 : 041802 10 3 7 : 1383706 10 3 11 : 2342% C 4 : 765117 10 3 6 : 921217 10 3 45 : 246% j 0 )]TJ/F15 11.9552 Tf 9.298 0 Td [(1 : 587559 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 jk 2 : 242 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(3 5 : 050134 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 22525 : 1% k )]TJ/F15 11.9552 Tf 9.299 0 Td [(6 : 048 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 )]TJ/F15 11.9552 Tf 9.298 0 Td [(5 : 022074 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(2 830 : 369% j )]TJ/F15 11.9552 Tf 9.299 0 Td [(1 : 462 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 1 : 091471 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 7465 : 6% k )]TJ/F15 11.9552 Tf 9.299 0 Td [(2 : 351 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(3 1 : 091471 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 4642 : 58% Figure3.5:Phase4Results Parameter Initial Generation25 A 7 : 141470 10 3 7 : 236227 10 3 B 7 : 129361 10 3 7 : 1383706 10 3 C 7 : 025081 10 3 6 : 921217 10 3 j )]TJ/F15 11.9552 Tf 9.299 0 Td [(1 : 152997 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 )]TJ/F15 11.9552 Tf 9.299 0 Td [(1 : 587559 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 jk 6 : 690673 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 5 : 050134 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 k )]TJ/F15 11.9552 Tf 9.299 0 Td [(5 : 409247 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 )]TJ/F15 11.9552 Tf 9.299 0 Td [(5 : 022074 10 )]TJ/F56 7.9701 Tf 6.587 0 Td [(2 j 4 : 451564 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(2 1 : 091471 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 k 6 : 211901 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(2 1 : 091471 10 )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 Fitness 1 : 803774 10 7 1 : 802784 10 7 Figure3.6:Phase4Initialvs.Final PAGE 63 Conclusion42 distortionparametersmustuseasucientlyhighJblocksuchthattheeectofdistortionisprominentenoughtodiscern.ThevalueofthatJvalueislikelytobedeterminedbyacombinationofthegeometryofthemoleculeunderinvestigation,theresolutionofthemeasuringdeviceandtheprecisionofthecomputations.WhereinChapter2wesawthatwecouldttherotationalconstantsA,BandCeasilythisisnotthecaseinthepresenceofdistortionconstants.Thisislikelyduetothefactthattheleastsquareregressionassumesthattheerrorsarenotcorrelatedwithvalue;thusitminimizestheerroruniformlyacrosstheparameters.TheresultinglargeerrorinthedistortionparametersresultsinanestimatewhichalsogrosslymisestimatestheerrorintheconstantsA,BandC.Weconcludethenthatweuseatwochromosomeapproach.IntherstchromosomeofthegenomeweencodetheeigenvaluesfortheJ =1block.Recallingthat 1 = A + B )]TJ/F15 11.9552 Tf 11.955 0 Td [(4 j )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 jk )]TJ/F15 11.9552 Tf 11.955 0 Td [( k )]TJ/F15 11.9552 Tf 11.955 0 Td [(4 j )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 k .5 2 = B + C )]TJ/F15 11.9552 Tf 11.955 0 Td [(5 j .6 3 = A + C )]TJ/F15 11.9552 Tf 11.955 0 Td [(4 j )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 jk )]TJ/F15 11.9552 Tf 11.956 0 Td [( k +4 j )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 k .7 wecanestimatetheparameters A B and C usingtheapproximation 1 = A + B .8 2 = B + C .9 3 = A + C .10whichwillbecorrecttowithinasmallperturbation.Theprecisionoftheapproximationwilllikelybevetosixdecimalplaces.UsingtheestimateofA,BandCwethencan PAGE 64 Conclusion43 estimatethedistortionparametersusingalinearregressiononlyonthosedistortionparameters.Theadvantageofthisschemeisthatitseparatesouttheerrorsofthelargeparameters A B and C fromerrorsincomputingthesmallerdistortionparameters. PAGE 65 Chapter4 SoftwareThesoftwaredevelopedtoimplementthealgorithmsdiscussedareinacombinationofCandCUDA-C.Cisthewellknownprogramminglanguagedescribedin[35].CUDA-CisalanguagedevelopedbythenVidiacorporationusedtoexecutesoftwareontheirGPUcards.CUDA-Cisdescribedin[36].Theprimarycodeissplitintotwoparts:thecodesupportingthedHamiltonianParametersstructure,whichcontainsinformationaboutanindividualJblockoftheHamiltonian,andthecodesupportingthejgaPopulationstructure,whichcontainsinformationaboutapopulationofageneticalgorithm.ThissoftwaredependsheavilyontheBLASlibrary,describedin[37,38,39,40,41,42,43,44],andATLAS,describedin[45,46,47,48,49],forbasiclinearalgebracomputationsontheCPU.GPUlinearalgebracomputationsareperformedwithnVidia'scuBLASlibrarydescribedin[31].LinearleastsquaresregressioniscomputedusingLAPACK,describedin[50].Thesoftwaredevelopedfromthesoftwaredesignedinanattempttoteigenvaluesandeigenvectorsatthesametime;thereforeitcontainsalegacywhichmaybefactoredout. 44 PAGE 66 dHamiltonianParameters 45 Listing4.1: hf.h:structdHamiltonianParameters 1 typedefstruct dHamiltonianParameters f 2 unsignedlonglong J,orientation,eigenPermutation; 3 double theta, lambda; 4 g dHamiltonianParameters; 4.1 dHamiltonianParametersThedHamiltonianParametersstructureinListing4.1containsinformationaboutasingleJblockofafeasiblesolutiontotheproblem.JistheJvaluethattheeigen-values,lambda,andangles,thetareference.lambdacontainseigenvalueswhichshouldbexedacrosstheentiregenome.thetacontainsthefeasiblesolutionandconstitutesaportionofthegenome.ThefunctionsaredeclaredinListing4.2.Therearetwostandardconstructors:dHamiltonianParametersCreateanddHamiltonianParametersRandom.GeneticcrossoverandmutationisperformeddHamiltonianParametersMateanddHamiltonianParametersMate-SPCwhichactasatypeofconstructor,thatis,itreturnsanewhandleratherthanmodifyingex-istinghandles.ThestructureisdestroyedusingdHamiltonianParametersDestroy.ThefunctiondHamiltonianParametersCPUComputeArrayinhf.canddHamiltonianParametersGPUComputeArrayinhfGPU.ccomputethema-trixc H JimpliedbythedHamiltonianParametersstructure.Thefunc-tiondHamiltonianParametersComputeArraywillchoosebetweenCPUandGPUvarietiesbasedonamanuallyconguredcrossoverpointdepend-ingonthevalueofJandautomaticallyshortcircuitsthecomputa- PAGE 67 dHamiltonianParameters 46 tionoftheJ=1blockusingtheknowneigenvectors.Thefunc-tionfindPlaneisusedbydHamiltonianParametersCPUComputeArrayanddHamiltonianParametersGPUComputeArraytoindexeachpairofaxesinthespace.ThefunctiondHamiltonianFittakesthematricescomputedbydHamiltonianParametersComputeArrayandcomputestheleastsquaresre-gression.TheremainingfunctionsgenerateRegressionCoefficientsandgenerateStitchedCoefficientsareusedbydHamiltonianFittocomputetheregression.Theremainingfunctionh3FitisafunctiontocomputetheregressionoftheJ=1estimateagainstonlythemomentsofinertiausedaspartofaproofofconcept. PAGE 68 dHamiltonianParameters 47 Listing4.2: hf.h Functions 1 dHamiltonianParameters dHamiltonianParametersCreate unsigned long J, double eigenvalues; 2 dHamiltonianParameters dHamiltonianParametersRandom unsigned long J, double eigenvalues; 3 dHamiltonianParameters dHamiltonianParametersMate dHamiltonianParameters h1,dHamiltonianParameters h2; 4 dHamiltonianParameters dHamiltonianParametersMateSPC dHamiltonianParameters h1,dHamiltonianParameters h2; 5 int dHamiltonianParametersCPUComputeArray dHamiltonianParameters h, double H, double Vec; 6 int dHamiltonianParametersDestroy dHamiltonianParameters h; 7 8 unsignedlonglong findDiagonal unsignedlonglong a, unsignedlonglong b, unsignedlonglong z; 9 int findPlane unsignedlonglong n, unsigned longlong z, unsignedlonglong x, 10 unsignedlonglong y; 11 int h3Fit double H, double x, double H2, double r; 12 double generateRegressionCoefficients unsigned longlong J; 13 double generateStitchedCoefficients unsigned longlong J1, unsignedlonglong J2; 14 int dHamiltonianFit unsignedlonglong J1, unsignedlonglong J2, double H, double X, PAGE 69 dHamiltonianParameters 48 4.1.1 dHamiltonianParamtersCreateHandlestoadHamiltoianParameterscanbeconstructedwithdefaultvaluesusingdHamiltonianParametersCreate describedinListing4.3. OnInput: { Jistheenergylevelforthesub-blockoftheHamiltonianthisstructurerepresents.Thisdeterminesthenumberofeigenvaluesandanglesusedtocomposetheblockitrepresents. { eigenvalues isalistofeigenvalues,presumedtobeofcorrectlength. OnOutput {Spaceisallocatedforthestructure,thelistofanglesandthelistofeigenvalues. { h->orientation issettozeroandisunused { h->J issetbasedoninput { h->theta isallocatedandsetto0 { h->eigenvalues isallocatedandthevaluesaresetbasedoninput OnReturn { Ahandlepointertothestructureisreturnedonsuccess { NULL isreturnedonerror PAGE 70 dHamiltonianParameters 49 Listing4.3: hf.c:dHamiltonianParametersCreate 1 dHamiltonianParameters dHamiltonianParametersCreate unsignedlong J double eigenvalues 2 f 3 dHamiltonianParameters h; 4 unsignedlong i; 5 6 if h=dHamiltonianParameters malloc sizeof dHamiltonianParameters==NULL goto error0; 7 if h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta= double malloc sizeof double 2 J+1 J== NULL goto error1; 8 if h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda= double malloc sizeof double 2 J+1== NULL goto error2; 9 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation=0; 10 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J=J; 11 for i=0;i < 2 J+1 J;i++ f h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i]=0; g 12 for i=0;i < 2 J+1;i++ f h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[i]=eigenvalues[i]; g 13 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation=0; 14 return h; 15 error2: 16 freeh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta; 17 error1: 18 freeh; 19 error0: 20 return NULL; 21 g PAGE 71 dHamiltonianParameters 50 4.1.2 dHamiltonianParametersRandomThisisaconstructorforstructdHamiltonianParameterswhichcreatesrandomangles,exceptinthecaseoftheJ=1blockwherethebestanglesareknown.NoticethattheanglesarenotthosefoundusingthecomputationsinAppendixAastheorderoftherotationmatricesintheproductwillbedierent.Lines9{17areusedtoseedathreadedrandomnumbergenerator OnInput: { Jistheenergylevelforthesub-blockoftheHamiltonianthisstructurerepresents.Thisdeterminesthenumberofeigenvaluesandanglesusedtocomposetheblockitrepresents. { eigenvalues isalistofeigenvalues,presumedtobeofcorrectlength. OnOutput {Spaceisallocatedforthestructure,thelistofanglesandthelistofeigenvalues. { h->orientation issettozeroandisunused { h->J issetbasedoninput { h->theta isallocatedandsettorandomvaluesin[0 ; 2 { h->eigenvalues isallocatedandthevaluesaresetbasedoninput OnReturn { Ahandlepointertothestructureisreturnedonsuccess { NULL isreturnedonerror PAGE 72 dHamiltonianParameters 51 Listing4.4: hf.c:dHamiltonianParametersRandom 1 dHamiltonianParameters dHamiltonianParametersRandom unsignedlong J double eigenvalues 2 f 3 dHamiltonianParameters h; 4 unsignedlonglong i; 5 staticunsignedshort Xi[3]; 6 staticlonglong seed= )]TJ/F18 9.9626 Tf 8.236 0 Td [(1; 7 struct timespect; 8 9 if seed== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 f 10 clock gettimeCLOCK REALTIME,&t; 11 seed=t.tv sec 1000000+t.tv nsec; 12 if sizeof unsignedlonglong < =6 f 13 memcpyXi,&seed, sizeof unsignedlonglong ; 14 g else f 15 memcpyXi, void &seed+ sizeof unsignedlonglong )]TJETq1 0 0 1 126.259 347.191 cm[]0 d 0 J 0.398 w 0 0 m 0 18.531 l SQq1 0 0 1 543.188 347.191 cm[]0 d 0 J 0.398 w 0 0 m 0 18.531 l SQBT/F18 9.9626 Tf 222.156 352.751 Td [(6,6; 16 g 17 g 18 if h=dHamiltonianParametersCreateJ,eigenvalues==NULL goto error0; 19 if J==1 f 20 h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[0]=5.0 PI/4.0; 21 h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[1]=PI; 22 h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[2]=3 PI/2.0; 23 h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> orientation=0; 24 g else f 25 for i=0;i < 2 J+1 J;i++ f 26 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i]=erand48Xi 2 PI; 27 g PAGE 73 dHamiltonianParameters 52 28 h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> orientation=0; 29 g 30 return h; 31 error0: 32 return NULL; 33 g 4.1.3 dHamiltonianParametersMateThisconstructorgeneratesanewdHamiltonianParametersfromh1andh2usingtheeigenvaluesfromh1andchoosinganglesuniformlyfromh1andh2.Itisassumedthattheeigenvaluesforeachofthemarethesame;otherwisetheprocessdoesnotmakesense. OnInput: { h1 isahandletoa dHamiltonianParameters { h2 isahandletoa dHamiltonianParameters OnOutput {ThehandleiscreatedusingdHamiltonianParametersCreateusingtheJ and lambda from h1 { Each h->theta issetfromoneoftheparentswithuniformprobability. OnReturn { Ahandlepointertothestructureisreturnedonsuccess { NULL isreturnedonerror PAGE 74 dHamiltonianParameters 53 Listing4.5: hf.c:dHamiltonianParametersMate 1 dHamiltonianParameters dHamiltonianParametersMate dHamiltonianParameters h1,dHamiltonianParameters h2 2 f 3 dHamiltonianParameters h; 4 unsignedlonglong i,n,angles,eigenvalues; 5 staticunsignedshort Xi[3]; 6 staticlonglong seed= )]TJ/F18 9.9626 Tf 8.236 0 Td [(1; 7 struct timespect; 8 9 if seed== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 f 10 clock gettimeCLOCK REALTIME,&t; 11 seed=t.tv sec 1000000+t.tv nsec; 12 if sizeof unsignedlonglong < =6 13 memcpyXi,&seed, sizeof unsignedlonglong ; 14 else 15 memcpyXi, void &seed+ sizeof unsignedlonglong )]TJETq1 0 0 1 126.259 332.685 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQq1 0 0 1 543.188 332.685 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQBT/F18 9.9626 Tf 222.156 338.488 Td [(6,6; 16 g 17 18 if h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J!=h2 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J goto error0; 19 if h=dHamiltonianParametersCreateh1 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J,h1 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda==NULL goto error0; 20 n=2 h1 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J+1; 21 angles=n n )]TJ/F18 9.9626 Tf 8.081 0 Td [(1/2; 22 eigenvalues=n; 23 for i=0;i < angles;i++ f h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[i]=erand48Xi > 0.5?h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[i]:h2 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i]; g 24 cblas dcopyeigenvalues,h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda,1,h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda,1; 25 return h; PAGE 75 dHamiltonianParameters 54 26 27 error0: 28 return NULL; 29 g 4.1.4 dHamiltonianParametersMateSPCThisconstructorgeneratesanewdHamiltonianParametersfromh1andh2usingtheeigenvaluesfromh1andchoosinganglesfromh1andh2usingasinglepointofcrossover;thatis,thealgorithmchoosesapointwithinthelistofangleswithuniformprobabilitythensetstheanglesuptothatpointfromh1andtheanglesafterthatpointfrom h2 OnInput: { h1 isahandletoa dHamiltonianParameters { h2 isahandletoa dHamiltonianParameters OnOutput {ThehandleiscreatedusingdHamiltonianParametersCreateusingtheJ and lambda from h1 {Thearrayh->thetaissetfromthetwoparentsusingsinglepointcrossoverwithcrossoverpointchosenwithuniformdistribution. OnReturn { Ahandlepointertothestructureisreturnedonsuccess { NULL isreturnedonerror PAGE 76 dHamiltonianParameters 55 Listing4.6: hf.c:dHamiltonianParametersMateSPC 1 dHamiltonianParameters dHamiltonianParametersMateSPC dHamiltonianParameters h1,dHamiltonianParameters h2 2 f 3 dHamiltonianParameters h; 4 unsignedlonglong angles,eigenvalues,i,n,point; 5 staticunsignedshort Xi[3]; 6 staticlonglong seed=0,seedSet= )]TJ/F18 9.9626 Tf 8.236 0 Td [(1; 7 struct timespect; 8 static pthread mutex tm=PTHREAD MUTEX INITIALIZER; 9 10 if seedSet== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1pthread mutex lock&m; 11 if seedSet== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 f 12 clock gettimeCLOCK REALTIME,&t; 13 seed=t.tv sec 1000000+t.tv nsec; 14 if sizeof unsignedlonglong < =6 15 memcpyXi,&seed, sizeof unsignedlonglong ; 16 else 17 memcpyXi, void &seed+ sizeof unsignedlonglong )]TJETq1 0 0 1 126.259 293.998 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQq1 0 0 1 543.188 293.998 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQBT/F18 9.9626 Tf 222.156 299.801 Td [(6,6; 18 seedSet=1; 19 g 20 pthread mutex unlock&m; 21 if h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J!=h2 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J goto error0; 22 if h=dHamiltonianParametersCreateh1 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J,h1 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda==NULL goto error0; 23 n=2 h1 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J+1; 24 angles=n n )]TJ/F18 9.9626 Tf 8.081 0 Td [(1/2; 25 eigenvalues=n; 26 pthread mutex lock&m; PAGE 77 dHamiltonianParameters 56 27 point=erand48Xi angles; 28 if point > 0 f cblas dcopypoint,h1 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta,1,h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta,1; g 29 if point < anglescblas dcopyangles )]TJ/F18 9.9626 Tf 14.164 0 Td [(point,&h1 )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[point ],1,&h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[point],1; 30 cblas dcopyeigenvalues,h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda,1,h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda,1; 31 return h; 32 error0: 33 return NULL; 34 g 4.1.5 dHamiltonianParametersComputeArrayThisfunctionistheinterfacetobothdHamiltonianParametersCPUComputeArrayanddHamiltonianParametersGPUComputeArray.AdditionallyitautomaticallyreturnstheproperHamiltoniansub-blockforthe J =1case Listing4.7: hf.c:dHamiltonianParametersComputeArray 1 extern "C" int dHamiltonianParametersComputeArray int GPUID, dHamiltonianParameters h, double H, double Vec 2 f 3 double V1[9]= f OORT,0,OORT, )]TJ/F18 9.9626 Tf 6.139 0 Td [(OORT,0,OORT,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(1,0 g ; 4 double EV[9]= f 0,0,0,0,0,0,0,0,0 g ; 5 double C1[9]; 6 double C2[9]; 7 if h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J==1 f 8 EV[0]=h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[0]; 9 EV[4]=h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[1]; ThisfunctionshouldalsogeneratetheHamiltoniansub-blocksforothersmallJvalueswherethematrixcanbecomputedwithouttheneedforrootnding PAGE 78 dHamiltonianParameters 57 10 EV[8]=h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[2]; 11 cblas dgemmCblasColMajor,CblasNoTrans,CblasNoTrans,3,3, 3,1.0,V1,3,EV,3,0,C1,3; 12 cblas dgemmCblasColMajor,CblasNoTrans,CblasTrans,3,3, 3,1.0,C1,3,V1,3,0,C2,3; 13 cblas dcopy9,C2,1,H,1; 14 if Vec!=NULLcblas dcopy9,V1,1,Vec,1; 15 return 0; 16 g 17 if h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J < 17 f 18 return dHamiltonianParametersCPUComputeArrayh,H,Vec; 19 g else f 20 return dHamiltonianParametersGPUComputeArrayGPUID,h,H, Vec; 21 g 22 g OnInput: { GPUID isthe0indexedIDoftheGPUtouseinifaGPUwillbeusedforcomputation.IftherearenthreadsandmGPUsthentheGPUIDshouldbe n mod m { histhestructdHamiltonianParametersstructureforwhichwecomputethearray. { H isspaceallocatedforthecomputedmatrix { Vecisanoptionalspaceallocatedfortheeigenvectormatrixcomputedfromtheangles. PAGE 79 dHamiltonianParameters 58 OnOutput {Ifh->J==1,thenthematrixiscomputeddirectly,otherwisedHamiltonianParametersCPUComputeArrayordHamiltonianParametersGPUComputeArrayiscalledtocomputethematriadenedby h OnReturn { 0 isreturnedonsuccess. {TheerrorfromdHamiltonianParametersCPUComputeArrayordHamiltonianParametersGPUComputeArray isreturned. PAGE 80 dHamiltonianParameters 59 aPointsassociatedwithaxespairs bDiagonalsabovepoints4,5and6 Figure4.1:Planeidenticationbyaxispairs ndPlaneIncaseswheredHamiltonianParametersComputeArraydonotcomputethematrixdirectlythefunctionwilldependonbeingabletoenumeratetheplanesinR nforn 2 N .Ifwehavendimensionswehave)]TJ/F58 7.9701 Tf 5.479 -4.379 Td [(n 2 pairsofplanestochoosefrom.Ifweidentifytheplanebytwodimensions,sayx;ywithy>xwecancomputeabijectionF :[1 ;n ] N [1 ;n ] N N asfollows;Let n begiven F x;y = n )]TJ/F57 11.9552 Tf 11.955 0 Td [(y + x )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 n )]TJ/F57 11.9552 Tf 11.955 0 Td [(y + x 2 + x .1ThatthisisabijectionfollowsfromtheproofthatN Niscountablebydiagonals.ToinvertthiswearegivenFx;y=zandwecomputex;y.WerstndthenumberofdiagonalsabovethepointseeFigure4.1b;thatis,ndthelargestmsuchthatP m j =1 j PAGE 81 dHamiltonianParameters 60 ThefunctionfindPlanedoesthis.Letnbethenumberofdimensions,thefunctionndsthepair x;y associatedwiththeinput z OnInput: { n isthetotalnumberofdimensions { z istheindexofthedimensionweseekaplanefor { x isareferenceofwheretostorethe x value { y isareferenceofwheretostorethe y value OnOutput { Thevalueofthe x dimensionisstoredin x { Thevalueofthe y dimensionisstoredin y OnReturn { 0 isreturnedinallcases Thisshouldbechangedtoaprocedurereturningvoidduetolackofpossibleerrorconditions. PAGE 82 dHamiltonianParameters 61 Listing4.8: hf.c:findPlane 1 int findPlane unsignedlonglong n, unsignedlonglong z, unsigned longlong x, unsignedlonglong y 2 f 3 unsignedlonglong diagonals; 4 5 diagonals=floor )]TJ/F18 9.9626 Tf 7.675 0 Td [(1+sqrt1+8 z )]TJ/F18 9.9626 Tf 8.081 0 Td [(1/2; 6 x=z )]TJ/F18 9.9626 Tf 8.357 0 Td [(diagonals diagonals+1/2; 7 y=n )]TJ/F18 9.9626 Tf 8.197 0 Td [(diagonals+ x )]TJ/F18 9.9626 Tf 8.358 0 Td [(1; 8 return 0; 9 g dHamiltonianParametersCPUComputeArrayThefunctiondHamiltonianParametersCPUComputeArray,alongwithitsGPUvariant,representthecoreofthecomputations.ThefunctioncreatesrotationmatricesR[i]foreachofthe)]TJ/F56 7.9701 Tf 5.48 -4.379 Td [(2 J +1 2 anglesbyassociatingtheintegeriwith1-indexedpairx;y,whichisthedimensionsofthespaceonwhichtherotationtakesplace,usingfindPlane.ThefunctionthencomputesthenormalizedeigenvectormatrixQ,thencomputes c H J = Q Q )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 OnInput: { histhestructdHamiltonianParametersstructureforwhichwecomputethearray. { H isspaceallocatedforthecomputedmatrix PAGE 83 dHamiltonianParameters 62 { Vecisanoptionalspaceallocatedfortheeigenvectormatrixcomputedfromtheangles. OnOutput { Thematrixdenedby h iscomputedandstoredin H { If Vec isnot NULL theeigenvectormatrixisstoredin H OnReturn { 0 isreturnedonsuccess. { -1 isreturnedonerror. PAGE 84 dHamiltonianParameters 63 Listing4.9: hf.c:dHamiltonianParametersCPUComputeArray 1 int dHamiltonianParametersCPUComputeArraydHamiltonianParameters h, double H, double Vec 2 f 3 double R; 4 double RSpace; 5 double C[2]; 6 double V, EV; 7 int rc; 8 unsignedlonglong n,angles; 9 unsignedlonglong i,j,k,x,y; 10 11 n=2 h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J+1; 12 angles=n n )]TJ/F18 9.9626 Tf 8.081 0 Td [(1/2; 13 if R= double malloc sizeof double angles==NULL goto error0; 14 if RSpace= double callocn n angles, sizeof double == NULL goto error1; 15 for i=0;i < angles;i++ f 16 R[i]= double &RSpace[n n i]; 17 for j=0;j < n;j++ f R[i][j+j n]=1; g 18 if rc=findPlanen,i+1,&x,&y!=0 goto error2; 19 x=x )]TJ/F18 9.9626 Tf 8.357 0 Td [(1; 20 y=y )]TJ/F18 9.9626 Tf 8.357 0 Td [(1; 21 R[i][x+n x]=cosh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i]; 22 R[i][y+n x]=sinh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i]; 23 R[i][x+n y]=sinh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i] )]TJ/F18 9.9626 Tf 8.381 0 Td [(1; 24 R[i][y+n y]=cosh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i]; 25 g 26 for i=0;i < 2;i++ f PAGE 85 dHamiltonianParameters 64 27 if C[i]= double callocn n, sizeof double ==NULL goto error3; 28 g 29 cblas dcopyn n,R[0],1,C[0],1; 30 for i=1;i < angles;i++ f 31 cblas dgemmCblasColMajor,CblasNoTrans,CblasNoTrans,n,n, n,1.0,C[i )]TJ/F18 9.9626 Tf 8.081 0 Td [(1%2],n,R[i],n,0,C[i%2],n; 32 g 33 if V= double callocn n, sizeof double ==NULL goto error4; 34 cblas dcopyn n,C[angles )]TJ/F18 9.9626 Tf 8.081 0 Td [(1%2],1,V,1; 35 36 if EV= double callocn n, sizeof double ==NULL goto error5; 37 for i=0;i < n;i++ f 38 EV[i+n i]=h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[i]; 39 g 40 cblas dgemmCblasColMajor,CblasNoTrans,CblasNoTrans,n,n,n, 1.0,V,n,EV,n,0,C[0],n; 41 cblas dgemmCblasColMajor,CblasNoTrans,CblasTrans,n,n,n, 1.0,C[0],n,V,n,0,C[1],n; 42 cblas dcopyn n,C[1],1,H,1; 43 if Vec!=NULLcblas dcopyn n,V,1,Vec,1; 44 freeEV; 45 freeV; 46 freeC[1]; 47 freeC[0]; 48 freeRSpace; 49 freeR; 50 return 0; PAGE 86 dHamiltonianParameters 65 51 52 //error6: 53 freeEV; 54 error5: 55 freeV; 56 error4: 57 i=2; 58 error3: 59 for k=0;k < i;k++ f 60 freeC[k]; 61 g 62 error2: 63 freeRSpace; 64 error1: 65 freeR; 66 error0: 67 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 68 g dHamiltonianParametersGPUComputeArrayThefunctiondHamiltonianParametersGPUComputeArrayistheGPUvariantofthepreviousfunctionandperformsexactlythesamecomputationusingaGPU;howevertherearesomesubtleandsomenotsosubtlemodicationsusedtooptimizeperformanceonaGPU.BLASlibrarycallsarereplacedwithcuBLASlibrarycalls.Inordertoovercometheissuesdiscussedinsection3.2thematricesR[i]aregeneratedinGPUmemoryusingaCUDAkernelcalled makeMatrices . PAGE 87 dHamiltonianParameters 66 WhencallingkernelsCUDAlimitsthesizeofthelistofpassedparameters;thereforetheparameterstopassarestoredinthestructurestructmakeMatricesParameters inListing4.10.Theparametersareasfollows: R :Memoryallocatedforthelistofrotationmatrices theta :ListofanglesinGPUmemory X,Y:ListswhichenumeratethexandyaxisforeachrotationinGPUmemory.Thekernel makeMatrices operatesasfollows: OnInput: { deviceParameterspointstothestructurestoredontheGPUcontainingthememorylocationsofthedatanecessarytocomputetherotationmatrix. OnOutput { Therotationmatrixisinitialized. OnReturn { void return. Listing4.10: hfGPU.cu:structmakeMatricesParameters 1 typedefstruct makeMatricesParameters f 2 int n; 3 double R; 4 double theta; 5 int X, Y; 6 g makeMatricesParameters; PAGE 88 dHamiltonianParameters 67 Thekernelgeneratesasinglematrixwithindexkbyzeroingthespacey,settingthediagonal,thensettingthenon-zeroentries.ThekernelisgiveninListing4.11. Listing4.11: hfGPU.cu:makeMatrices 1 global void makeMatricesmakeMatricesParameters deviceParameters f 2 int k=blockIdx.x blockDim.x+threadIdx.x; 3 int i,x,y; 4 5 6 for i=0;i < deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n;i++ deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> R[k][i]=0; //zerothematrix 7 for i=0;i < deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n;i++deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> R[k][i+i deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n]=1; //setthediagonal 8 9 x=deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> X[k]; 10 y=deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Y[k]; 11 deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> R[k][x+deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n x]=cos deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[k]; //setthenon0/1entries 12 deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> R[k][y+deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n x]=sin deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[k]; 13 deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> R[k][x+deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n y]= )]TJ/F18 9.9626 Tf 8.703 0 Td [(1.0 deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> R[k][y+deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n x]; 14 // )]TJ/F21 9.9626 Tf 8.59 0 Td [(1.0 sintheta[k] 15 deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> R[k][y+deviceParameters )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n y]= deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> R[k][x+deviceParameters )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n x]; 16 //costheta[k] 17 g Wemakeuseofthefactthatthevaluezeroindoubleprecisionoatingpointhasthesamerepresentationastheintegervaluezero y Thisappearstobefasterthanusing cudaMemset ,presumablythroughparallelism. PAGE 89 dHamiltonianParameters 68 ThefunctiondHamiltonianParametersGPUComputeArrayinListing4.12functionsessentiallyasdHamiltonianParametersCPUComputeArray.MemoryisallocatedforstructuresonboththeGPUandCPUasnecessary.Theprimarydierenceisthatinsteadofcomputingtheproductoftherotationmatricesinalinearfashiontheproductiscomputedinparallel.Thelistisreducedtoalisthalfthelengthmoduloaremainder.Thelistreductionisperformediterativelyuntilthelisthaslength1.Whereeachmultiplicationinthelinearcomputationdependsonthepreviousinthisschemeitdoesnot;thereforecomputationsaresplitacrossanumberofstreams,denedbytheconstantSTREAMS.ThevalueofSTREAMSisempiricallydeterminedforbestperformance y OnInput: { GPUID isthe0indexIDoftheGPUtouse. { histhestructdHamiltonianParametersstructureforwhichwecomputethearray. { H isspaceallocatedforthecomputedmatrix { Vecisanoptionalspaceallocatedfortheeigenvectormatrixcomputedfromtheangles. OnOutput { Thematrixdenedby h iscomputedandstoredin H Sincethisfunctionconstitutesthecoreofthealgorithmandiscalledoftenitmaybeusefultoallocateandfreespaceforthisfunctionandforeachthreadwhichmaycallthisfunctiononetime. yInpracticethecrossoverpointforGPUvsCPUcomputationis17,witharesultingnumberofrotationmatricesof)]TJ/F7 6.9738 Tf 4.566 -3.649 Td [(17 2 =136orlarger,andthattheoptimumvalueforSTREAMSis8.GiventhesevaluesitmaybemoreecienttodividethelistofrotationmatricesintoSTREAMSsegments,computetheproductofeachsegment,theninasinglestreamcomputetheproductofthe STREAMS resultingmatrices. PAGE 90 dHamiltonianParameters 69 { If Vec isnot NULL theeigenvectormatrixisstoredin H OnReturn { 0 isreturnedonsuccess. { -1 isreturnedonerror. PAGE 91 dHamiltonianParameters 70 Listing4.12: hfGPU.cu:dHamiltonianParametersGPUComputeArray 1 extern "C" int dHamiltonianParametersGPUComputeArray int GPUID, dHamiltonianParameters h, double H, double Vec 2 f 3 double R[2], deviceR[2]; 4 double RSpace[2]; 5 int X, Y; 6 int deviceX, deviceY; 7 double C[2]; 8 double V, EV; 9 double alpha=1.0,beta=0.0; 10 double deviceTheta; 11 int n,angles,secondaries,depth,curAngles; 12 unsignedlonglong i,j,x,y; 13 makeMatricesParametersparameters, deviceParameters; 14 15 cudaError tcudaStat; 16 cublasStatus tstat; 17 cublasHandle thandle; 18 cudaStream tstream[STREAMS]; 19 20 n=2 h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J+1; 21 angles=n n )]TJ/F18 9.9626 Tf 8.081 0 Td [(1/2; 22 secondaries=angles/2+angles%2; 23 cudaSetDeviceGPUID; 24 25 if cudaStat=cudaMallocHost void &R[0], sizeof double angles!=cudaSuccess goto error0; 26 if cudaStat=cudaMallocHost void &R[1], sizeof double secondaries!=cudaSuccess goto error1; PAGE 92 dHamiltonianParameters 71 27 if cudaStat=cudaMallocHost void &X, sizeof int angles !=cudaSuccess goto error2; 28 if cudaStat=cudaMallocHost void &Y, sizeof int angles !=cudaSuccess goto error3; 29 if cudaStat=cudaMalloc void &deviceX,angles sizeof int !=cudaSuccess goto error4; 30 if cudaStat=cudaMalloc void &deviceY,angles sizeof int !=cudaSuccess goto error5; 31 if cudaStat=cudaMalloc void &deviceParameters, sizeof makeMatricesParameters!=cudaSuccess goto error6; 32 if cudaStat=cudaMalloc void &deviceR[0], sizeof double angles!=cudaSuccess goto error7; 33 if cudaStat=cudaMalloc void &deviceR[1], sizeof double secondaries!=cudaSuccess goto error8; 34 if cudaStat=cudaMalloc void &RSpace[0], sizeof double angles n n!=cudaSuccess goto error9; 35 if cudaStat=cudaMalloc void &RSpace[1], sizeof double secondaries n n!=cudaSuccess goto error10; 36 for i=0;i < angles;i++R[0][i]= double &RSpace[0][n n i]; 37 for i=0;i < secondaries;i++R[1][i]= double &RSpace[1][n n i]; 38 if cudaStat=cudaMalloc void &deviceTheta,angles sizeof double !=cudaSuccess goto error11; 39 if cudaStat=cudaMalloc void &C[0],n n sizeof double !=cudaSuccess goto error12; 40 if cudaStat=cudaMalloc void &C[1],n n sizeof double !=cudaSuccess goto error13; 41 if cudaStat=cudaMalloc void &V,n n sizeof double != cudaSuccess goto error14; 42 if cudaStat=cudaMalloc void &EV,size tn n sizeof PAGE 93 dHamiltonianParameters 72 double !=cudaSuccess goto error15; 43 if stat=cublasCreate&handle!=CUBLAS STATUS SUCCESS goto error16; 44 for i=0;i < STREAMS;i++ f 45 if cudaStat=cudaStreamCreate&stream[i]!=cudaSuccess goto error17; 46 g 47 //cudaStreamCreate&stream; 48 for i=0;i < angles;i++ f 49 findPlanen,i+1,&x,&y; 50 X[i]= int x )]TJ/F18 9.9626 Tf 14.17 0 Td [(1; 51 Y[i]= int y )]TJ/F18 9.9626 Tf 14.17 0 Td [(1; 52 g 53 if cudaStat=cudaMemcpyAsyncdeviceX,X, sizeof int angles, cudaMemcpyHostToDevice,stream[0]!=cudaSuccess goto error99; 54 if cudaStat=cudaMemcpyAsyncdeviceY,Y, sizeof int angles, cudaMemcpyHostToDevice,stream[0]!=cudaSuccess goto error99; 55 if cudaStat=cudaMemcpyAsyncdeviceTheta,h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta,angles sizeof double ,cudaMemcpyHostToDevice,stream[0]!= cudaSuccess 56 goto error99; 57 if cudaStat=cudaMemcpyAsyncdeviceR[0],R[0], sizeof double angles,cudaMemcpyHostToDevice,stream[0]!=cudaSuccess 58 goto error99; 59 if cudaStat=cudaMemcpyAsyncdeviceR[1],R[1], sizeof double secondaries,cudaMemcpyHostToDevice,stream[0]!= cudaSuccess PAGE 94 dHamiltonianParameters 73 60 goto error99; 61 62 parameters.n=n;parameters.R=deviceR[0]; 63 parameters.theta=deviceTheta;parameters.X=deviceX; parameters.Y=deviceY; 64 65 if cudaStat=cudaMemcpyAsyncdeviceParameters,¶meters, sizeof makeMatricesParameters,cudaMemcpyHostToDevice, stream[0] 66 !=cudaSuccess goto error99; 67 68 //angles=2J+1J 69 cudaStreamSynchronizestream[0]; 70 makeMatrices <<< h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J,2 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J+1 >>> deviceParameters; 71 depth= int ceillogangles/log2; 72 curAngles=angles; 73 //cublasSetStreamhandle,stream; 74 for i=0;i < depth;i++ f 75 for j=0;j < curAngles/2;j++ f 76 cublasSetStreamhandle,stream[j%STREAMS]; 77 cublasDgemmhandle,CUBLAS OP N,CUBLAS OP N,n,n,n,& alpha,R[i%2][2 j],n,R[i%2][2 j+1],n, 78 &beta,R[i+1%2][j],n; 79 g 80 for j=0;j < STREAMS;j++ f cudaStreamSynchronizestream[j]; g 81 cublasSetStreamhandle,stream[0]; 82 if curAngles%2==1 f 83 cublasDcopyhandle,n n,R[i%2][curAngles )]TJ/F18 9.9626 Tf 8.69 0 Td [(1],1,R[i+1 %2][curAngles/2],1; PAGE 95 dHamiltonianParameters 74 84 g 85 curAngles=curAngles/2+curAngles%2; 86 cudaStreamSynchronizestream[0]; 87 g 88 cublasDcopyhandle,n n,R[i%2][0],1,V,1; 89 90 if cudaStat=cudaMemsetEV,0, sizeof double n n!= cudaSuccess f 91 fprintfstderr,"cudaMemsetEV, 0, n n sizeofdouble failed : %s n n",cudaGetErrorStringcudaStat; 92 goto error99; 93 g 94 for i=0;i < n;i++ f 95 if cudaStat=cudaMemcpy&EV[i+n i],&h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[i], sizeof double ,cudaMemcpyHostToDevice f 96 fprintfstderr,"cudaMemcpyEV[%llu], h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[%llu], ... failed: %s n n",i+n i,i,cudaGetErrorString cudaStat; 97 goto error99; 98 g 99 g 100 cublasDgemmhandle,CUBLAS OP N,CUBLAS OP N,n,n,n,&alpha,V ,n,EV,n,&beta,C[0],n; 101 cublasDgemmhandle,CUBLAS OP N,CUBLAS OP T,n,n,n,&alpha,C [0],n,V,n,&beta,C[1],n; 102 cudaStat=cudaMemcpyH,C[1], sizeof double n n, cudaMemcpyDeviceToHost; 103 if Vec!=NULLcudaMemcpyVec,V, sizeof double n n, cudaMemcpyDeviceToHost; 104 PAGE 96 dHamiltonianParameters 75 105 for i=0;i < STREAMS;i++ f cudaStreamDestroystream[i]; g 106 cublasDestroyhandle; 107 cudaFreeEV; 108 cudaFreeV; 109 cudaFreeC[1]; 110 cudaFreeC[0]; 111 cudaFreedeviceTheta; 112 cudaFreeRSpace[1]; 113 cudaFreeRSpace[0]; 114 cudaFreedeviceR[1]; 115 cudaFreedeviceR[0]; 116 cudaFreedeviceParameters; 117 cudaFreedeviceY; 118 cudaFreedeviceX; 119 cudaFreeHostY; 120 cudaFreeHostX; 121 cudaFreeHostR[1]; 122 cudaFreeHostR[0]; 123 return 0; 124 error99: 125 i=STREAMS; 126 error17: 127 fprintfstderr,"dHamiltonianParametersGPUComputeArray n n"; 128 for j=0;j < i;j++ f cudaStreamDestroystream[j]; g 129 cublasDestroyhandle; 130 error16: 131 cudaFreeEV; 132 error15: 133 cudaFreeV; 134 error14: PAGE 97 dHamiltonianParameters 76 135 cudaFreeC[1]; 136 error13: 137 cudaFreeC[0]; 138 error12: 139 cudaFreedeviceTheta; 140 error11: 141 cudaFreeRSpace[1]; 142 error10: 143 cudaFreeRSpace[0]; 144 error9: 145 cudaFreedeviceR[1]; 146 error8: 147 cudaFreedeviceR[0]; 148 error7: 149 cudaFreedeviceParameters; 150 error6: 151 cudaFreedeviceY; 152 error5: 153 cudaFreedeviceX; 154 error4: 155 cudaFreeHostY; 156 error3: 157 cudaFreeHostX; 158 error2: 159 cudaFreeHostR[1]; 160 error1: 161 cudaFreeHostR[0]; 162 error0: 163 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 164 g PAGE 98 dHamiltonianParameters 77 4.1.6 dHamiltonianParametersDestroy Listing4.13: hf.h:dHamiltonianParametersDestroy 1 int dHamiltonianParametersDestroydHamiltonianParameters h 2 f 3 if h==NULL goto error0; 4 if h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta!=NULLfreeh )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta; 5 if h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda!=NULLfreeh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda; 6 freeh; 7 return 0; 8 error0: 9 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 10 g dHamiltonianParametersDestroyisthedestructorforthedHamiltonianParametersstructure.Itfreesmemoryspaceassociatedwiththestructure. OnInput: { h isahandletothestructuretobedestroyed. OnOutput {Theallocatedmemoryregionsforh->theta,h->lambdaandharede-stroyed. OnReturn { 0 isreturnedonsuccess. { -1 isreturnedonerror. PAGE 99 dHamiltonianParameters 78 4.1.7RegressionThetnessfunctiondependsoncomputingaleastsquaresregressionoftherotationalconstantsintheHamiltonianfortheJblocksstoredinadHamiltonianParameters.ThefunctiongenerateRegressionCoefficientsgeneratestheregressionmatricesforeachJblock.ThefunctiongenerateStitchedCoefficientsgeneratesamatrixforregressionforarangeofJblocksatonce.ThefunctionsLencomputesthelengthofaseriesofblocksandisusedtondindexesintothematrixcomputedbygenerateStitchedCoefficients.Finally,thefunctiondHamiltonianFitcom-putestheregression,computestheHamiltonianbasedonthevaluesfoundintheregressionandcomputestheresiduals. generateRegressionCoefficientsThefunctiongenerateRegressionCoefficientsgeneratesthematrixcorrespond-ingtoa J value y .Thecomputationsaretakenfrom[28]. OnInput: { J isthe J valuetocomputefor. OnOutput { Theregressionmatrixisgenerated OnReturn { Theregressioncoecientmatrixisreturnedonsuccess. { NULL isreturnedonerror. Eitherthisfunctionshouldbememoizedorit'soutputshouldbeusedtocreateglobalarrayssinceit'soutputisstatic. yThisfunctioncouldeasilybeusedtocomputeaHamiltonianblockforaparticularJvaluebymultiplyingtheoutputofthisfunctionbyavectorcontainingtherotationalconstants. PAGE 100 dHamiltonianParameters 79 Listing4.14: hf.h:generateRegressionCoefficients 1 double generateRegressionCoefficients unsignedlonglong J 2 f 3 double R,s; 4 longlong n,l,m,k1,k2,i,j; 5 6 j=J; 7 n=2 j+1; 8 if R= double callocn n 8, sizeof double ==NULL goto error0; 9 for i=0;i < n n;i++ f 10 m=i%n+1; 11 l=i )]TJ/F18 9.9626 Tf 5.701 0 Td [(m+1/n+1; 12 k1=l )]TJ/F18 9.9626 Tf 7.841 0 Td [(j )]TJ/F18 9.9626 Tf 8.358 0 Td [(1; 13 k2=m )]TJ/F18 9.9626 Tf 7.841 0 Td [(j )]TJ/F18 9.9626 Tf 8.358 0 Td [(1; 14 if l==m f 15 R[n n 0+i]=k1 k1; 16 R[n n 1+i]=powj,2+j )]TJ/F18 9.9626 Tf 6.918 0 Td [(powk1,2/2.0; 17 R[n n 2+i]=powj,2+j )]TJ/F18 9.9626 Tf 6.918 0 Td [(powk1,2/2.0; 18 R[n n 3+i]= )]TJ/F18 9.9626 Tf 7.887 0 Td [(powj,2 )]TJ/F18 9.9626 Tf 14.16 0 Td [(2 powj,3 )]TJ/F18 9.9626 Tf 13.191 0 Td [(powj,4; 19 R[n n 4+i]= )]TJ/F18 9.9626 Tf 8.236 0 Td [(j powk1,2 )]TJ/F18 9.9626 Tf 14.187 0 Td [(powj,2 powk1,2; 20 R[n n 5+i]= )]TJ/F18 9.9626 Tf 7.213 0 Td [(powk1,4; 21 R[n n 6+i]=0; 22 R[n n 7+i]=0; 23 g 24 if m==l )]TJ/F18 9.9626 Tf 8.081 0 Td [(2 f 25 s=sqrtj j+1 )]TJ/F18 9.9626 Tf 7.832 0 Td [(k1 )]TJ/F18 9.9626 Tf 8.081 0 Td [(1 k1 )]TJ/F18 9.9626 Tf 8.081 0 Td [(2 j J+1 )]TJ/F18 9.9626 Tf 7.73 0 Td [(k1 k1 )]TJ/F18 9.9626 Tf 8.081 0 Td [(1; 26 R[n n 0+i]=0; 27 R[n n 1+i]=s/4.0; 28 R[n n 2+i]= )]TJ/F18 9.9626 Tf 7.832 0 Td [(s/4.0; PAGE 101 dHamiltonianParameters 80 29 R[n n 3+i]=0; 30 R[n n 4+i]=0; 31 R[n n 5+i]=0; 32 R[n n 6+i]= )]TJ/F18 9.9626 Tf 8.81 0 Td [(j )]TJ/F18 9.9626 Tf 6.918 0 Td [(powj,2 s; 33 R[n n 7+i]=1/2.0 )]TJ/F18 9.9626 Tf 8.07 0 Td [(powk1,2 )]TJ/F18 9.9626 Tf 7.213 0 Td [(powk2,2 s; 34 g 35 if m==l+2 f 36 s=sqrtj j+1 )]TJ/F18 9.9626 Tf 7.832 0 Td [(k1+1 k1+2 j J+1 )]TJ/F18 9.9626 Tf 7.73 0 Td [(k1 k1+1; 37 R[n n 0+i]=0; 38 R[n n 1+i]=s/4.0; 39 R[n n 2+i]= )]TJ/F18 9.9626 Tf 7.832 0 Td [(s/4.0; 40 R[n n 3+i]=0; 41 R[n n 4+i]=0; 42 R[n n 5+i]=0; 43 R[n n 6+i]= )]TJ/F18 9.9626 Tf 8.81 0 Td [(j )]TJ/F18 9.9626 Tf 6.918 0 Td [(powj,2 s; 44 R[n n 7+i]=1/2.0 )]TJ/F18 9.9626 Tf 8.07 0 Td [(powk1,2 )]TJ/F18 9.9626 Tf 7.213 0 Td [(powk2,2 s; 45 46 g 47 48 g 49 return R; 50 error0: 51 return NULL; 52 g PAGE 102 dHamiltonianParameters 81 sLenInordertocomputeindexesintothestitchedcoecientmatrixweneedtobeabletocomputethenumberofelementsintheblocksoftheHamiltonianforarangeofJ values .Thiscomputationis J 2 X j = J 1 j +1 2 .2 OnInput: { J1 isthe J valuefortherstblock. { J2 isthe J valueforthesecondblock. OnOutput { noinformationissaved OnReturn { Thevalue P J 2 j = J 1 j +1 2 isreturned. Listing4.15: hf.h:sLen 1 unsignedlonglong sLen unsignedlonglong J1, unsignedlonglong J2 2 f 3 return 4 powJ2,3+12 powJ2,2+11 J2 )]TJ/F18 9.9626 Tf 13.8 0 Td [(4 powJ1,3+J1 +3/3; 4 g Thisfunctionshouldbeinlined. PAGE 103 dHamiltonianParameters 82 generateStitchedCoefficientsThefunctiongenerateStitchedCoefficientsgeneratesthecoecientmatrixforarangeofJvalues.EachmatrixcomputedfromgenerateRegressionCoefficientshasJ+12rowsand8columns.TheresultingmatrixshouldhaveP J 2 J = J 1J+12rowsand8columns.Ifthecoecientmatricesaref A k g n k =1thenwepicturetheresultingstitchedmatricesasin4.3 2 6 6 6 6 6 6 6 4 A 1 A 2 A k 3 7 7 7 7 7 7 7 5 .3 OnInput: { J1 isthe J valuefortherstblock. { J2 isthe J valueforthesecondblock. OnOutput { Theregressionmatrixiscomputed OnReturn { Theregressionmatrixisreturnedonsuccess. { NULL isreturnedonerror. PAGE 104 dHamiltonianParameters 83 Listing4.16: hf.c:generateStitchedCoefficients 1 double generateStitchedCoefficients unsignedlonglong J1, unsigned longlong J2 2 f 3 double R, S; 4 unsignedlonglong i,j,len; 5 6 if R= double callocJ2 )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1+1, sizeof double ==NULL goto error0; 7 for i=0;i < J2 )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1+1;i++ f 8 R[i]=generateRegressionCoefficientsJ1+i; 9 if R[i]==NULL goto error2; 10 g 11 //len= n sum f k=J1 g ^ f J2 g 2k+1^2where2k+1isthedimensionofthe Hamiltoniansubblock,so2k+1^2isthe 12 //numberofelements. 13 len=sLenJ1,J2; 14 if S= double malloc sizeof double len 8==NULL goto error2; 15 for i=0;i < J2 )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1+1;i++ f 16 for j=0;j < 8;j++ f 17 cblas dcopy unsignedlonglong pow2 J1+i+1,2,&R[i ][ unsignedlonglong pow2 J1+i+1,2 j],1,&S[ len j+sLenJ1,J1+i )]TJ/F18 9.9626 Tf 8.081 0 Td [(1],1; 18 g 19 g 20 21 for i=0;i < J2 )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1+1;i++ f freeR[i]; g 22 freeR; 23 return S; PAGE 105 dHamiltonianParameters 84 24 25 //error3: 26 freeS; 27 i=J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1; 28 error2: 29 for j=0;j < i;j++ f 30 freeR[j]; 31 g 32 //error1: 33 freeR; 34 error0: 35 return NULL; 36 g PAGE 106 dHamiltonianParameters 85 dHamiltonianFit Thefunction dHamiltonianFit computestheactualtnessfunction,whichistheresidualsoftheHamiltoniandenedbythedHamiltonianParametersarrayversustheHamiltoniancomputedfromtherotationalparametersestimatedbytheleastsquaresregression y OnInput: { J1 and J2 arethevaluesoftherstandlast J block. { Hisalistofarrays,eachamatrixcomputedfromaadHamiltonianParameters structure. { X isapointertoalocationtostoretheregressionresults { H2isapointertoalocationtostorethenewcomputedHamiltonianbasedontheparameterscomputedfor X { r isapointertoalocationtostoretheresidualvalue. OnOutput { Theregressioniscomputedandstoredin X { TheHamiltonianblocksdenedby X iscomputedandstoredin H2 { Theresidualiscomputedinstoredin r OnReturn { Thevalue 0 returnedonsuccessand -1 onerror. OnemighttrytocomputetheeigenvaluesoftheHamiltoniancomputedfromtherotationalparametersestimatedbytheleastsquaresregressionthencomparethesetotheeigenvaluesinthe dHamiltonianParameters structuresasthetnessfunction. yOnemighttrytoweighttheelementscomprisingtheresiduals,whetherusingthecurrentschemeoraneigenvaluescheme. PAGE 107 dHamiltonianParameters 86 Listing4.17: hf.c:dHamiltonianFit 1 int dHamiltonianFit unsignedlonglong J1, unsignedlonglong J2, double H, double X, double H2, double r 2 f 3 double A, ACopy, S, SCopy, S2, D; 4 unsignedlonglong i,len; 5 double wkopt, work; 6 integerlda,ldb,nrhs,m,n,info,lwork; 7 8 len=sLenJ1,J2; 9 A=generateStitchedCoefficientsJ1,J2; 10 ACopy= double malloc sizeof double len 8; 11 S= double malloc sizeof double len; 12 SCopy= double malloc sizeof double len; 13 S2= double malloc sizeof double len; 14 D= double malloc sizeof double len; 15 for i=0;i < J2 )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1+1;i++ f 16 cblas dcopypow2 J1+i+1,2,H[i],1,&S[sLenJ1,J1+i )]TJ/F18 9.9626 Tf 8.081 0 Td [(1 ],1; 17 g 18 lda=len; 19 ldb=len; 20 nrhs=1; 21 m=len; 22 n=8; 23 lwork= )]TJ/F18 9.9626 Tf 8.236 0 Td [(1; 24 cblas dcopylen 8,A,1,ACopy,1; 25 cblas dcopylen,S,1,SCopy,1; 26 dgels "N",&m,&n,&nrhs,ACopy,&lda,SCopy,&ldb,&wkopt,& lwork,&info; PAGE 108 dHamiltonianParameters 87 27 lwork= int wkopt; 28 work= double malloc sizeof double lwork; 29 dgels "N",&m,&n,&nrhs,ACopy,&lda,SCopy,&ldb,work,& lwork,&info; 30 if info!=0 f printf"info = %i n n", int info; return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; g 31 if X!=NULL f 32 cblas dcopy8,SCopy,1,X,1; 33 g 34 cblas dgemmCblasColMajor,CblasNoTrans,CblasNoTrans,len,1, 8,1.0,A,len,SCopy,len,0.0,S2,len; 35 if H2!=NULL f 36 for i=0;i < J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1;i++ f 37 cblas dcopypow2 J1+i+1,2,&S2[sLenJ1,J1+i )]TJ/F18 9.9626 Tf 8.081 0 Td [(1], 1,H2[i],1; 38 g 39 g 40 cblas dcopylen,S,1,D,1; 41 cblas daxpylen, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.0,S2,1,D,1; 42 r=cblas dnrm2len,D,1; 43 freework; 44 freeA; 45 freeACopy; 46 freeS; 47 freeSCopy; 48 freeS2; 49 freeD; 50 return 0; 51 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 52 g PAGE 109 jgaPopulation 88 4.2 jgaPopulation 4.2.1 structjgaPopulationThejgaPopulationstructureinListing4.18containsthestateinformationaboutarunofthegeneticalgorithm. Listing4.18: jga.h:structjgaPopulation 1 typedefstruct jgaPopulation f 2 unsignedlonglong n,J1,J2; 3 double lambda; 4 dHamiltoniansGaElement e; 5 g jgaPopulation; n isthepopulationsize J1 isthevalueoftherst J block J2 isthevalueofthelast J block eisanarrayofdHamiltoniansGaElementoflengthn,eachcontaininganarrayof dHamiltonianParameters ,oneforeach J block,andatnessvalue. PAGE 110 jgaPopulation 89 4.2.2 structdHamiltoniansGaElement Listing4.19: gae.h:structdHamiltoniansGaElement 1 typedefstruct dHamiltoniansGaElement f 2 dHamiltonianParameters h; 3 double fitness; 4 g dHamiltoniansGaElement; ThestructuredHamiltoniansGaElementisgiveninListing4.19.Therearenoconstructorsordestructors.TheonlyoperationonthisisdHamiltoniansGaElementComparewhichexiststofacilitateqsort.dHamiltoniansGaElementCompare isgiveninListing4.20. Listing4.20: gae.h:structdHamiltoniansGaElement 1 int dHamiltoniansGaElementCompare constvoid e1, constvoid e2 2 f 3 if dHamiltoniansGaElement e1 )]TJ/F11 9.9626 Tf 6.332 0 Td [(> fitness== dHamiltoniansGaElement e2 )]TJ/F11 9.9626 Tf 6.332 0 Td [(> fitness return 0; 4 return dHamiltoniansGaElement e1 )]TJ/F11 9.9626 Tf 6.332 0 Td [(> fitness < dHamiltoniansGaElement e2 )]TJ/F11 9.9626 Tf 6.332 0 Td [(> fitness? )]TJ/F18 9.9626 Tf 7.555 0 Td [(1:1; 5 g PAGE 111 jgaPopulation 90 4.2.3 jgaPopulationCreate jgaPopulationCreateThefunctionjgaPopulationCreateisathreadedconstructorforjgaPopulation.TheprimaryfunctionistocreatethejgaPopulationhandle.ItislledwithentriesviajgaPopulationJob.ThestructurestructpopJobisusedtostoreparametersforeachthreadof jgaPopulationJob OnInput: { J1 isthe J valuefortherstblock. { J2 isthe J valueforthelastblock. { lambdaisalistofarraysofeigenvalues,eachwithlengthscorrespondingtothesizeofthe J block. { threads isthenumberofthreadstousetogeneratethepopulation. OnOutput { Thepopulationhandle p iscreated. { Thepopulationisgeneratedwithrandomangles. OnReturn { p returnedonsuccess. { NULL isreturnedonerror. PAGE 112 jgaPopulation 91 Listing4.21: jga.c:jgaPopulationCreate 1 jgaPopulation jgaPopulationCreate unsignedlonglong J1, unsigned longlong J2, unsignedlonglong n, 2 double lambda, unsignedlonglong threads 3 f 4 jgaPopulation p; 5 unsignedlonglong i,k,tCount; 6 pthread t thread; 7 popJob job; 8 int ptrc; 9 10 if threads > nthreads=n; 11 12 if thread=malloc sizeof pthread t threads==NULL goto error0; 13 if job=malloc sizeof popJob threads==NULL goto error1; 14 if p=malloc sizeof jgaPopulation==NULL goto error2; 15 if p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda=malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1==NULL goto error3; 16 if p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e=malloc sizeof dHamiltoniansGaElement n==NULL goto error4; 17 for i=0;i < n;i++ f 18 if p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h=malloc sizeof dHamiltoniansGaElement J2 )]TJETq1 0 0 1 126.259 216.625 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQq1 0 0 1 543.188 216.625 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQBT/F18 9.9626 Tf 197.812 222.428 Td [(J1+1==NULL goto error5; 19 g 20 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1=J1;p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2=J2; 21 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n=n; 22 for i=J1;i < =J2;i++ f 23 if p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]=malloc sizeof double 2 i+1== NULL goto error6; PAGE 113 jgaPopulation 92 24 cblas dcopy2 i+1,lambda[i )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1],1,p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1],1; 25 g 26 tCount=n/threads; 27 for i=0;i < threads;i++ f 28 job[i].start=i tCount; 29 if i < threads )]TJ/F18 9.9626 Tf 8.014 0 Td [(1 f job[i].n=tCount; g else f job[i].n= n )]TJ/F18 9.9626 Tf 14.741 0 Td [(i tCount; g 30 job[i].rc=0; 31 job[i].p=p; 32 job[i].GPUID=i%4; 33 pthread create&thread[i],NULL, void void jgaPopulationJob,&job[i]; 34 g 35 for i=0;i < threads;i++ f 36 while ptrc=pthread jointhread[i],NULL!=0 f 37 perror"pthread join"; 38 g 39 40 g 41 freethread; 42 freejob; 43 44 return p; 45 error6: 46 while )48()]TJ/F18 9.9626 Tf 15.848 0 Td [(i > =J1 f 47 freep )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[i]; 48 g 49 i=n; 50 error5: 51 for k=0;k < i;k++ f freep )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e[k].h; g PAGE 114 jgaPopulation 93 52 freep )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e; 53 error4: 54 freep )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda; 55 error3: 56 freep; 57 error2: 58 freejob; 59 error1: 60 freethread; 61 error0: 62 return NULL; 63 g popJobThisstructuredenesparametersforeachthreadofjgaPopulationJob.Inparticular, p isthehandletothe jgaPopulation structure start isthenumberoftheelementofthearrayof p->e[] tostartwith. n isthenumberofelementsfromthatpositiontogenerate. GPUID isthe0indexedIDoftheGPUtouse rc isspacetoreturnanerrorcodeto jgaPopulationCreate PAGE 115 jgaPopulation 94 Listing4.22: jga.c:structpopJob 1 typedefstruct popJob f 2 jgaPopulation p; 3 unsignedlonglong start,n; 4 int GPUID; 5 int rc; 6 g popJob; jgaPopulationJobThefunctionjgaPopulationJobperformsthebulkofthepopulationcreation.OfimportancetonoteisthattheresultsofdHamiltonianParametersRandomforaseriesofJblocksmaynotreturnafeasiblesolution.ThesolutionischeckedwithdHamiltonianFitandiftheconditionthatA B Cisnotsatisedtheresultisdiscarded.Lines35{37areasafetyvalve;ifthealgorithmfailstoproduceafeasiblepopulationwithinaspeciednumberofattemptsitwillexit.Thisconditionshouldindicatethereisaproblemwithanalgorithm. Thisfunctionshouldsavetheresidualasthetnessfunction,unlessanothertnessfunctionischosen,thoughitdoesnotatpresent.Inj.cthefunctionjgaPopulationScoreisthencalled;thoughthisissueisofminorimportanceuntilthealgorithmperformanceisimproved. PAGE 116 jgaPopulation 95 OnInput: { job isapointertothe popJob structureforthisthread. OnOutput {Thearrayp->e[]islledoutfortheindexesindicatedbythevaluesinjob OnReturn { job->rc issetto0success. { job->rc issettonon-zeroonerror. Listing4.23: jga.c:jgaPopulationJob 1 void jgaPopulationJobpopJob job 2 f 3 double X[8],r; 4 double HA, H2A; 5 unsignedlonglong i,j,k,start,n,J1,J2,fails=0; 6 jgaPopulation p; 7 8 p=job )]TJ/F11 9.9626 Tf 5.977 0 Td [(> p; 9 start=job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> start; 10 n=job )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n; 11 job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> rc=0; 12 J1=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1;J2=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2; 13 if p==NULL goto error0; 14 if n==0 goto error0; 15 PAGE 117 jgaPopulation 96 16 if HA=malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1==NULL goto error0; 17 if H2A=malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1==NULL goto error1; 18 for i=J1;i < =J2;i++ f 19 if HA[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]=malloc sizeof double 2 i+1 2 i+1== NULL goto error2; 20 if H2A[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]=malloc sizeof double 2 i+1 2 i+1== NULL goto error3; 21 g 22 23 for i=start;i < start+n;i++ f 24 for j=J1;j < =J2;j++ f 25 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[j )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]=dHamiltonianParametersRandomj,p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[j )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]; 26 g 27 p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e[i].fitness=0.0; 28 for k=J1;k < =J2;k++ f 29 dHamiltonianParametersComputeArrayjob )]TJ/F11 9.9626 Tf 5.978 0 Td [(> GPUID,p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h [k )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1],HA[k )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1],NULL; 30 g 31 dHamiltonianFitJ1,J2,HA,X,H2A,&r; 32 if X[0] < X[1] jj X[1] < X[2] f 33 for j=0;j < J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1;j++ f dHamiltonianParametersDestroy p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[j]; g 34 i )13()]TJ/F18 9.9626 Tf 15.299 0 Td [(; 35 if fails++ > 1000000 f 36 fprintfstderr,"PopulationJob fit failure n n"; 37 exit )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 38 g PAGE 118 jgaPopulation 97 39 g 40 g 41 for i=J1;i < =J2;i++ f 42 freeHA[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]; 43 freeH2A[i )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1]; 44 g 45 freeHA; 46 freeH2A; 47 return ; 48 error3: 49 freeHA[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]; 50 error2: 51 for j=J1;j < i;j++ f 52 freeHA[j )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]; 53 freeH2A[j )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1]; 54 g 55 freeH2A; 56 error1: 57 freeHA; 58 error0: 59 job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> rc=1; 60 return ; 61 g PAGE 119 jgaPopulation 98 4.2.4 jgaPopulationScoreThefunctionjgaPopulationScoreisathreadedscoringfunctiontoscoreapopu-lationofstructdHamiltoniansGaElement.SimilartotheconstructorthestructurescoreJob containstheinformationforthethreaded jgaPopulationScoreJob jgaPopulationScoreThisfunctiongeneratesthescoreJobstructuresforthethreadsandexecutesthem.OncejgaPopulationScoreJobhasscoredtheelementstheyaresortedviaqsort. OnInput: { p isapointertothe jgaPopulation structuretoscore. { threads isthenumberofthreadstoexecute OnOutput {Thevaluesp->e[i].fitnessarecomputedandthearrayissortedbytness. OnReturn { 0 isreturnedonsuccess. { 1 onerror. PAGE 120 jgaPopulation 99 Listing4.24: jga.c:jgaPopulationScore 1 int jgaPopulationScorejgaPopulation p, unsignedlonglong threads 2 f 3 unsignedlonglong i; 4 unsignedlonglong tCount; 5 pthread t thread; 6 scoreJob job; 7 8 if p==0 goto error0; 9 thread=malloc sizeof pthread t threads; 10 job=malloc sizeof scoreJob threads; 11 tCount=p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n/threads; 12 for i=0;i < threads;i++ f 13 job[i].p=p; 14 job[i].rc=0; 15 job[i].start=i tCount; 16 job[i].n=i < threads )]TJ/F18 9.9626 Tf 13.634 0 Td [(1?tCount:p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n )]TJ/F18 9.9626 Tf 14.741 0 Td [(i tCount; 17 job[i].GPUID=i%4; 18 pthread create&thread[i],NULL, void void jgaPopulationScoreJob,&job[i]; 19 g 20 for i=0;i < threads;i++pthread jointhread[i],NULL; 21 for i=0;i < threads;i++ if job[i].rc!=0 goto error1; 22 qsortp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e,p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n, sizeof dHamiltoniansGaElement, dHamiltoniansGaElementCompare; 23 freethread; 24 freejob; 25 return 0; 26 error1: 27 freethread; PAGE 121 jgaPopulation 100 28 freejob; 29 error0: 30 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 31 g scoreJobThestructurescoreJobinListing4.25storestheinformationpertinenttoeachthreadof jgaPopulationJob p isthe jgaPopulation thethreadisscoringelementsfor. start istheindexoftherstelementin p->e[] toscore. n isthenumberofelementsin p->e[] toscore. GPUIDisthe0indexedIDoftheGPUtousefordHamiltonianParametersComputeArray rc isspacetostoreareturnvalue. Listing4.25: jga.c:structscoreJob 1 typedefstruct scoreJob f 2 jgaPopulation p; 3 unsignedlonglong start,n; 4 int GPUID; 5 int rc; 6 g scoreJob; PAGE 122 jgaPopulation 101 jgaPopulationScoreJobThefunctionjgaPopulationScoreJobperformsthescoringofelementsofthearrayp->e[].ThefunctioniterativelycomputesthearraysforeachdHamiltonianParametersthencomputesthetandresiduals.Theresidualisstoredasthetnessfunction. Listing4.26: jga.c:jgaPopulationJob 1 void jgaPopulationScoreJobscoreJob job 2 f 3 unsignedlonglong i,j,J1,J2,start,n; 4 jgaPopulation p; 5 double X[8],r; 6 double HA, H2A; 7 int rc; 8 9 J1=job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1; 10 J2=job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2; 11 start=job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> start; 12 n=job )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n; 13 p=job )]TJ/F11 9.9626 Tf 5.977 0 Td [(> p; 14 if HA=malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1==NULL goto error0; 15 if H2A=malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1==NULL goto error1; 16 for i=0;i < J2 )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1+1;i++ f 17 if HA[i]=malloc sizeof double 2 J1+i+1 2 J1+i+1 ==NULL goto error3; 18 if H2A[i]=malloc sizeof double 2 J1+i+1 2 J1+i+1 ==NULL goto error4; PAGE 123 jgaPopulation 102 19 g 20 for i=start;i < start+n;i++ f 21 for j=0;j < J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1;j++ f 22 if rc=dHamiltonianParametersComputeArrayjob )]TJ/F11 9.9626 Tf 5.977 0 Td [(> GPUID, p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[j],HA[j],NULL!=0 23 goto error5; 24 g 25 dHamiltonianFitJ1,J2,HA,X,H2A,&r; 26 p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e[i].fitness=r; 27 g 28 for i=0;i < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 7.011 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1;i++ f 29 freeH2A[i]; 30 freeHA[i]; 31 g 32 freeH2A; 33 freeHA; 34 job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> rc=0; 35 return ; 36 error5: 37 i=J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1; 38 goto error3; 39 error4: 40 freeHA[i]; 41 error3: 42 for j=0;j < i;j++ f 43 freeHA[i]; 44 freeH2A[i]; 45 g 46 error2: 47 freeH2A; PAGE 124 jgaPopulation 103 48 error1: 49 freeHA; 50 error0: 51 job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> rc=1; 52 return ; 53 g PAGE 125 jgaPopulation 104 4.2.5 jgaPopulationHusbandryThefunctionjgaPopulationHusbandryisathreadedinterfacetothecrossoverfunctionwhichcreatesanewpopulationofelementsfromanexistingpopulation. jgaPopulationHusbandryThefunctionjgaPopulationHusbandryisaninterfacetoathreadedroulettewheelselectionalgorithmforjgaPopulation.Inlines34{38thefunctioncomputestheroulettewheel.Sincethetnessscoresarebeingminimizedthefunctioncomputestheinverses,normalizesthemandcreatesthewheelnormalSum[].Lines39{42implementoneelementelitismsothattheminimumtnessscoreofthepopulationisnon-increasingovergenerations.Afterthenewpopulationiscreatedtheexistingpopulationisdestroyedandthenewpopulationisputintoplaceandsorted. OnInput: { p isapointertothe jgaPopulation structuretomate. { m isthemutationrate. { threads isthenumberofthreadstoexecute OnOutput { Anewpopulation p->e[i] iscreatedandtheexistingoneisdestroyed. { Thenewpopulationsiscored. OnReturn { 0 isreturnedonsuccess. { 1 onerror. PAGE 126 jgaPopulation 105 Listing4.27: jga.c:jgaPopulationHusbandry 1 int jgaPopulationHusbandryjgaPopulation p, double m, unsignedlong long threads 2 f 3 double score, normalScore, normalSum, normalizer; 4 unsignedlonglong i,j,J1,J2; 5 unsignedlonglong tCount; 6 dHamiltoniansGaElement e; 7 staticunsignedshort Xi[3]; 8 staticlonglong seed= )]TJ/F18 9.9626 Tf 8.236 0 Td [(1; 9 husbandryJob job; 10 pthread t thread; 11 struct timespect; 12 13 if seed== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 f 14 clock gettimeCLOCK REALTIME,&t; 15 seed=t.tv sec 1000000+t.tv nsec; 16 if sizeof unsignedlonglong < =6 17 memcpyXi,&seed, sizeof unsignedlonglong ; 18 else 19 memcpyXi, void &seed+ sizeof unsignedlonglong )]TJETq1 0 0 1 126.259 235.968 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQq1 0 0 1 543.188 235.968 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQBT/F18 9.9626 Tf 222.156 241.771 Td [(6,6; 20 g 21 22 if p==NULL goto error0; 23 J1=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1;J2=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2; 24 thread=malloc sizeof pthread t threads; 25 job=malloc sizeof husbandryJob threads; 26 PAGE 127 jgaPopulation 106 27 if score=mallocp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n sizeof double ==NULL goto error0; 28 if normalScore=mallocp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n sizeof double ==NULL goto error1; 29 if normalSum=mallocp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n sizeof double ==NULL goto error2; 30 if e=mallocp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n sizeof dHamiltoniansGaElement==NULL goto error3; 31 for i=0;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f 32 if e[i].h=mallocJ2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1 sizeof dHamiltonianParameters ==NULL goto error4; 33 g 34 for i=0;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f score[i]=1/p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e[i].fitness; g 35 normalizer=cblas dasump )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n,score,1; 36 for i=0;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f normalScore[i]=score[i]/normalizer; g 37 normalSum[0]=normalScore[0]; 38 for i=1;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f normalSum[i]=normalSum[i )]TJ/F18 9.9626 Tf 8.358 0 Td [(1]+ normalScore[i]; g 39 for i=0;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2 )]TJ/F18 9.9626 Tf 7.01 0 Td [(p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+1;i++ f 40 e[0].h[i]=dHamiltonianParametersMateSPCp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e[0].h[i],p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e [0].h[i]; 41 e[0].fitness=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].fitness; 42 g 43 tCount=p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n/threads; 44 for i=0;i < threads;i++ f 45 job[i].start=i tCount; 46 if i < threads )]TJ/F18 9.9626 Tf 14.169 0 Td [(1 f job[i].n=tCount; g else f job[i].n=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F18 9.9626 Tf 14.741 0 Td [(i tCount; g 47 if i==0 f job[i].start=1;job[i].n=job[i].n )]TJ/F18 9.9626 Tf 14.538 0 Td [(1; g 48 job[i].rc=0; PAGE 128 jgaPopulation 107 49 job[i].p=p; 50 job[i].normalSum=normalSum; 51 job[i].e=e; 52 job[i].m=m; 53 job[i].GPUID=i%4; 54 pthread create&thread[i],NULL, void void jgaHusbandryJob,&job[i]; 55 g 56 for i=0;i < threads;i++pthread jointhread[i],NULL; 57 freethread; 58 freejob; 59 60 for i=0;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f 61 for j=0;j < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 7.011 0 Td [(p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+1;j++ f 62 dHamiltonianParametersDestroyp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[j]; 63 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[j]=e[i].h[j]; 64 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].fitness=e[i].fitness; 65 g 66 g 67 68 qsortp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e,p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n, sizeof dHamiltoniansGaElement, dHamiltoniansGaElementCompare; 69 70 for i=0;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f freee[i].h; g 71 freee; 72 freenormalSum; 73 freenormalScore; 74 freescore; 75 return 0; 76 freee; PAGE 129 jgaPopulation 108 77 error4: 78 for j=0;j < i;j++ f freee[j].h; g 79 error3: 80 freenormalSum; 81 error2: 82 freenormalScore; 83 error1: 84 freescore; 85 error0: 86 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 87 g structhusbandryJobThestructurestructhusbandryJobcontainstheinformationneededforeachhus-bandrythread. p isthe jgaPopulation tomate. normalSum istheroulettewheel. e isthespaceforthenewpopulation. start istheindexoftherstelementof e[] forthethreadtocreate. n isthenumberofelementstocreate. GPUID isthe0indexIDoftheGPUtouseforGPUcomputations. rc isspacetostoreareturnvalue. m isthemutationrate. PAGE 130 jgaPopulation 109 Listing4.28: jga.c:structhusbandryJob 1 typedefstruct husbandryJob f 2 jgaPopulation p; 3 double normalSum; 4 dHamiltoniansGaElement e; 5 unsignedlonglong start,n; 6 int GPUID,rc; 7 double m; 8 g husbandryJob; jgaHusbandryJobThefunctionjgaHusnbadryJobisthefunctionthateachthreadusestoproduceanewpopulationfromanoldone.ThefunctionsRouletteBall takestheroulettewheelnormalSumandndstheelementcorrespondingtothevaluedie[].Thefunctionperformsabinarysearchonthewheeltondtheindexassociatedwiththerandomvaluein[0 ; 1.Themutationalgorithmimplementsabitwisemutationasfollows.Ifxisadoubleprecisionoatingpointnumberwewishtoipabit,butthebitwiseoperatorsareonlydenedonintegertypes.Weconstructapointertoxby&x.Thispointeristypecasttoapointertoanintegertypeybyunsignedlong*&x.Wethendereferencethepointerby*unsignedlong*&x.Thistreatsthevariableasthoughitisaintegertypewhichwecanassignvaluestoandoperateonbitwise.Thetypecastinthemaskisnecessarysince1isinterpretedasa32-bitintegerby Thefunction sRouletteBall ismisnamedandshouldbecalled dRouletteBall y Ifwetypecasttheoatingpointtypetoanintegertypethevalueistruncated. PAGE 131 jgaPopulation 110 default,evenon64-bitsystemswith gcc .MiscarriagechecksthateachofthemutatedvaluesarewithinrangeandthattherotationalconstantscomputedfromthegenomesatisfyA B C.Iftheseconditionsarenotmettheresultisdiscardedandnewvaluescomputed.Sincetheregressioniscomputedtoverifysuitabilityofthegenomethetnessfunctionregressionisautomaticallycomputed.Wesavetheresidualsoscoringthepopulationisnotnecessary. Listing4.29: jga.c:jgaHusbandryJob 1 void jgaHusbandryJobhusbandryJob job 2 f 3 unsignedlonglong i,j,k,l,start,n,mask,J1,J2, angles,fails=0; 4 staticlonglong seed= )]TJ/F18 9.9626 Tf 8.236 0 Td [(1; 5 unsignedlonglong parent[2]; 6 double die[2]; 7 double normalSum; 8 double m; 9 double X[8],r, HA, H2A; 10 staticunsignedshort Xi[3]; 11 jgaPopulation p; 12 dHamiltoniansGaElement e; 13 struct timespect; 14 15 if seed== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 f 16 clock gettimeCLOCK REALTIME,&t; 17 seed=t.tv sec 1000000+t.tv nsec; 18 if sizeof unsignedlonglong < =3 19 memcpyXi,&seed, sizeof unsignedlonglong ; PAGE 132 jgaPopulation 111 20 else 21 memcpyXi, void &seed+ sizeof unsignedlonglong )]TJETq1 0 0 1 126.259 627.226 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQq1 0 0 1 543.188 627.226 cm[]0 d 0 J 0.398 w 0 0 m 0 19.343 l SQBT/F18 9.9626 Tf 222.156 633.029 Td [(6,6; 22 g 23 24 p=job )]TJ/F11 9.9626 Tf 5.977 0 Td [(> p; 25 start=job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> start; 26 n=job )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n; 27 normalSum=job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> normalSum; 28 e=job )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e; 29 m=job )]TJ/F11 9.9626 Tf 5.977 0 Td [(> m; 30 job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> rc=0; 31 J1=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1;J2=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2; 32 33 if HA=malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1==NULL goto error0; 34 if H2A=malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1==NULL goto error1; 35 for i=J1;i < =J2;i++ f 36 if HA[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]=malloc sizeof double 2 i+1 2 i+1== NULL goto error2; 37 if H2A[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]=malloc sizeof double 2 i+1 2 i+1== NULL goto error3; 38 g 39 40 41 for i=start;i < start+n;i++ f 42 die[0]=erand48Xi; 43 die[1]=erand48Xi; 44 parent[0]=sRouletteBallnormalSum,0,p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F18 9.9626 Tf 8.155 0 Td [(1,die[0]; PAGE 133 jgaPopulation 112 45 parent[1]=sRouletteBallnormalSum,0,p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F18 9.9626 Tf 8.155 0 Td [(1,die[1]; 46 for j=0;j < J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1;j++ f 47 angles=2 j+J1+1; 48 e[i].h[j]=dHamiltonianParametersMatep )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[parent[0]].h [j],p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e[parent[1]].h[j]; 49 //mutation 50 //thisdependsondoublebeingthesamesizeaslongintat64bits 51 if J1+j!=1 f 52 for k=0;k < 63;k++ f 53 for l=0;l < angles;l++ f 54 if erand48Xi < m f 55 mask= unsignedlonglong 1 << k; 56 unsignedlong &e[i].h[j] )]TJ/F11 9.9626 Tf 7.639 0 Td [(> theta[l ]= unsignedlong &e[i].h[j ] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[l]^mask; 57 g 58 g 59 g 60 g 61 62 //miscarybadmutation 63 //notethatiffisafloatthenf!=fifandonlyiffisNaN 64 for k=0;k < angles;k++ f 65 if e[i].h[j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[k] < 0 jj e[i].h[j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[k] > 2 PI jj e[i].h[j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[k]!=e[i].h[j] )]TJ/F11 9.9626 Tf 7.639 0 Td [(> theta[k ] 66 break ; 67 g 68 if k < angles jj e[i].h[j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[angles )]TJ/F18 9.9626 Tf 8.358 0 Td [(1] < 0 jj e[i].h[ j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[angles )]TJ/F18 9.9626 Tf 8.358 0 Td [(1] > 2 PI jj PAGE 134 jgaPopulation 113 69 e[i].h[j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[angles )]TJ/F18 9.9626 Tf 8.358 0 Td [(1]!=e[i].h[j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[ angles )]TJ/F18 9.9626 Tf 8.657 0 Td [(1] f 70 dHamiltonianParametersDestroye[i].h[j )-59()]TJ/F18 9.9626 Tf 16.383 0 Td [(]; 71 continue ; 72 g 73 g 74 for k=0;k < J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1;k++ f 75 dHamiltonianParametersComputeArrayjob )]TJ/F11 9.9626 Tf 5.978 0 Td [(> GPUID,e[i].h[k ],HA[k],NULL; 76 g 77 dHamiltonianFitJ1,J2,HA,X,H2A,&r; 78 e[i].fitness=r; 79 if X[0] < X[1] jj X[1] < X[2] f 80 for j=0;j < J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1;j++ f dHamiltonianParametersDestroy e[i].h[j]; g 81 i )13()]TJ/F18 9.9626 Tf 15.299 0 Td [(; 82 if fails++ > 10000 f 83 printf"fit failure n n"; 84 exit )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 85 g 86 g 87 g 88 for i=J1;i < =J2;i++ f 89 freeHA[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]; 90 freeH2A[i )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1]; 91 g 92 freeHA; 93 freeH2A; 94 return ; 95 error3: PAGE 135 jgaPopulation 114 96 freeHA[i )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]; 97 error2: 98 for j=J1;j < i;j++ f 99 freeHA[j )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1]; 100 freeH2A[j )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1]; 101 g 102 freeH2A; 103 error1: 104 freeHA; 105 error0: 106 job )]TJ/F11 9.9626 Tf 5.978 0 Td [(> rc=1; 107 return ; 108 g PAGE 136 jgaPopulation 115 4.2.6 jgaPopulationVarianceThefunctionjgaPopulationVariancecomputestheaveragevarianceofallanglesinthegenome.Thisfunctioncanbeusedtodeterminetheextenttowhichthefoundereecthashadonthepopulation.Thisisusefulforvaryingthemutationrate.Typicalstartingvalues,wherethepopulationisuniformlydistributed,isapproximately1:77.Listing4.30: jga.c:jgaPopulationVariance 1 double jgaPopulationVariancejgaPopulation p 2 f 3 unsignedlonglong i,j,k,n,J,angles,totalAngles; 4 double mu, v; 5 double av=0; 6 7 if mu= double malloc sizeof double p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.284 0 Td [(p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+1 ==NULL goto error0; 8 for i=0;i < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+1;i++ f 9 J=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+i; 10 if mu[i]= double callocJ 2 J+1, sizeof double == NULL goto error1; 11 g 12 if v= double malloc sizeof double p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.284 0 Td [(p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+1 ==NULL goto error2; 13 for i=0;i < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1;i++ f 14 J=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+i; 15 if v[i]= double callocJ 2 J+1, sizeof double == NULL goto error3; 16 g 17 18 19 for i=0;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f PAGE 137 jgaPopulation 116 20 for j=0;j < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.284 0 Td [(p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+1;j++ f 21 J=p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+j; 22 angles=J 2 J+1; 23 for k=0;k < angles;k++ f 24 mu[j][k]+=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[k]; 25 g 26 g 27 g 28 for j=0;j < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1;j++ f 29 J=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+j; 30 angles=J 2 J+1; 31 for k=0;k < angles;k++ f 32 mu[j][k]=mu[j][k]/p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 33 g 34 g 35 for i=0;i < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f 36 for j=0;j < p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.284 0 Td [(p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+1;j++ f 37 J=p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+j; 38 angles=J 2 J+1; 39 for k=0;k < angles;k++ f 40 v[j][k]+=powp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[j] )]TJ/F11 9.9626 Tf 7.638 0 Td [(> theta[k] )]TJ/F18 9.9626 Tf 12.509 0 Td [(mu[j][k],2 ; 41 g 42 g 43 g 44 for j=0;j < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1;j++ f 45 J=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+j; 46 angles=J 2 J+1; 47 for k=0;k < angles;k++ f 48 v[j][k]=sqrtv[j][k]/p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 49 g PAGE 138 jgaPopulation 117 50 g 51 for j=0;j < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1;j++ f 52 J=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1+j; 53 angles=J 2 J+1; 54 for k=0;k < angles;k++ f 55 av+=v[j][k]; 56 g 57 g 58 // n sum f J=J1 g ^J2binomial[2J+1,2] 59 totalAngles=p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+3 powp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1,2 )]TJ/F18 9.9626 Tf 13.8 0 Td [(4 powp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1,3+p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2 1+p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 5+4 p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2/6; 60 av=av/ float totalAngles; 61 for i=0;i < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1;i++ f freev[i]; g 62 freev; 63 for i=0;i < p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1;i++ f freemu[i]; g 64 freemu; 65 return av; 66 error99: 67 i=p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1; 68 error3: 69 for j=0;j < i;j++freev[i]; 70 freev; 71 error2: 72 i=p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J2 )]TJ/F18 9.9626 Tf 13.283 0 Td [(p )]TJ/F11 9.9626 Tf 5.977 0 Td [(> J1+1; 73 error1: 74 for j=0;j < i;j++freemu[i]; 75 freemu; 76 error0: 77 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 78 g PAGE 139 jgaPopulation 118 4.2.7 jgaPopulationDestroyThefunctionjgaPopulationDestroyisthedestructorforthestruct jgaPopulation.ThiscallsthedestructorforeachofthedHamiltonianParameters andfreesallocatedmemory. Listing4.31: jga.c:jgaPopulationDestroy 1 int jgaPopulationDestroyjgaPopulation p 2 f 3 unsignedlonglong i,j,n,J1,J2; 4 5 if p==NULL goto error0; 6 J1=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J1;J2=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J2;n=p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 7 if p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda!=NULL f 8 for i=0;i < J2 )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1+1;i++ if p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[i]!=NULLfreep )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[i]; 9 freep )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda; 10 g 11 if p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e!=NULL f 12 for i=0;i < n;i++ f 13 for j=0;j < J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1;j++ f 14 dHamiltonianParametersDestroyp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[j]; 15 g 16 freep )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h; 17 g 18 freep )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e; 19 g 20 freep; 21 return 0; 22 error0: 23 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 24 g PAGE 140 GeneticAlgorithm119 4.3GeneticAlgorithmTheprogramj.cisanexampleofthegeneticalgorithm.ThisprogramuseseigenvaluescomputedfromtheparametersinMathematicatoensureprecision. Line451createsthepopulation.Lines457{473executeseachgeneration.Lines458{459computetheregressionfortherstbestelementfordisplay. Listing4.32: j.c 1 #include < config.h > 2 #include < math.h > 3 #include < stdio.h > 4 #include < stdlib.h > 5 #include < string.h > 6 #include < time.h > 7 #include < unistd.h > 8 9 #include < f2c.h > 10 #include < cblas.h > 11 #include < clapack.h > 12 13 #include "hf.h" 14 #include "hfGPU.h" 15 #include "jga.h" 16 #include "util.h" 17 #include "../math/constants.h" 18 19 #define N10000 20 #define G500 21 #define THREADS4 PAGE 141 GeneticAlgorithm120 22 23 int main int argc, char argv 24 f 25 double lambda0[3]= f 26 16530.702114000003,13253.996013999998, 12806.919000000004 27 g ; 28 double lambda1[5]= f 29 49634.879098717516,46762.51396000001, 45421.272334,35591.08385799999, 30 35548.39186128248 31 g ; 32 double lambda2[7]= f 33 99395.55013415603,97051.01377881395, 94371.06008565592,85183.21715200004, 34 84972.28350184394,67656.23237718601, 67653.67106634415 35 g ; 36 double lambda3[9]= f 37 165924.52864310401,164146.93010673753, 159693.83805351253, 151339.6814271749, 38 150723.51262511773,133700.76814926247, 133682.93130248744, 109268.97428882521, 39 109268.84698777828 40 g ; 41 double lambda4[11]= f 42 249336.67141728586,248081.59057328445, 241445.690657239,234089.00609800298, PAGE 142 GeneticAlgorithm121 43 232716.83477100002,216233.02645623358, 216162.40643761624, 191827.43375799697, 44 191826.29197771405,160412.133476482, 160412.12776114477 45 g ; 46 double lambda5[13]= f 47 349719.03362028894,348886.76360397576, 339705.5095255797, 333466.13727827213, 48 330903.17647388706,315248.80720467545, 315040.76580685785, 290868.4174970501, 49 290862.7425158188,259488.53227134878, 259488.4695735631, 221084.44971067837, 50 221084.44947000532 51 g ; 52 double lambda6[15]= f 53 467116.23506793263,466591.6619410244, 454577.32698408223, 449511.4581248736, 54 445285.6716505488,430751.9600653461, 430247.17962131585,406378.158769315, 55 406357.5482491122,375051.7303720615, 375051.35580673005, 336678.0274578117, 56 336678.0243364065,291285.51394956815, 291285.5139398726 57 g ; PAGE 143 GeneticAlgorithm122 58 double lambda7[17]= f 59 601538.9398011618,601220.9584157058, 586186.0209263235,582269.2416112975, 60 575913.5019008579,562756.2898039705, 561695.8449577399,538343.4632715994, 61 538282.520658927,507089.8782315882, 507088.2655683238, 468761.91890232585, 62 468761.8971286535,423395.51454073575, 423395.5143956133,371014.8655027775, 63 371014.86550239945 64 g ; 65 double lambda8[19]= f 66 752981.1472332376,752794.0114324919, 734661.5557739456,731785.546446303, 67 722867.8897305959,711286.1237678742, 709302.2145988257,686753.835605849, 68 686598.6993540039,655589.7426820606, 655584.1503171605,617326.840521767, 69 617326.7321924957,571998.3546858914, 571998.3535284007,519640.6596980798, 70 519640.6596916658,460271.9630536805, 460271.9630536659 71 g ; 72 double lambda9[21]= f 73 921432.772094204,921325.1097616354, 900113.8995019107,898105.7495419297, 74 886253.2656175158,876375.634712851, 873008.9403619895,851603.9671220717, 75 851252.7018540626,820537.1591814591, PAGE 144 GeneticAlgorithm123 820520.5954745206,782362.3040852456, 76 782361.8737110323,737086.6028840804, 737086.5963518765,684761.2167466761, 77 684761.2166891088,625412.9679319739, 625412.9679317017,559056.1895060764, 78 559056.1895060762 79 g ; 80 double lambda10[23]= f 81 1.1068851743902948E+06, 1.1068243276438483E+06, 1.082612293346778E+06, 82 1.081272087463889E+06, 1.0661942522344897E+06, 1.0580672156790695E+06, 83 1.0528080421302961E+06, 1.0328961938492577E+06, 1.032174387995122E+06, 84 1.0019178302063323E+06, 1.0018744168057586E+06, 963856.6305956859, 85 963855.180576227,918651.9519368818, 918651.9227020172,866370.4325146124, 86 866370.4321513225,807050.292470003, 807050.2924672844,740711.8237685552, 87 740711.8237685438,667366.8547398658, 667366.8547398653 88 g ; 89 double lambda11[25]= f 90 1.309332479930936E+06,1.309298581114871 E+06,1.2821827254059133E+06, PAGE 145 GeneticAlgorithm124 91 1.2813216548093546E+06, 1.262832133294219E+06, 1.2564092207704764E+06, 92 1.2487456324582454E+06, 1.2306424413620778E+06, 1.2292793890999006E+06, 93 1.1997185648102674E+06, 1.1996155174824845E+06, 1.161797026264244E+06, 94 1.1617927275708166E+06, 1.1166851915505738E+06, 1.1166850812425145E+06, 95 1.064461558988525E+06, 1.0644615571804524E+06, 1.0051788293499569E+06, 96 1.0051788293309875E+06, 938865.1014934098,938865.1014932881, 865536.5158758548, 97 865536.5158758538,785203.1969023892, 785203.196902388 98 g ; 99 double lambda12[27]= f 100 1.5287712724479437E+06, 1.5287526084003996E+06, 1.4988216675156353E+06, 101 1.4982852123694113E+06, 1.4763138285412393E+06, 1.4714533204854473E+06, 102 1.4609111915804981E+06, 1.4448652477090058E+06, PAGE 146 GeneticAlgorithm125 1.442480987933219E+06, 103 1.4139289845658909E+06, 1.4137039634162085E+06, 1.3761697778038532E+06, 104 1.3761582862843492E+06, 1.3311761796566644E+06, 1.3311758152659745E+06, 105 1.2790271846867374E+06, 1.279027177137197E+06, 1.2197929842921426E+06, 106 1.219792984188235E+06, 1.1535116958940981E+06, 1.1535116958931559E+06, 107 1.0802049911622554E+06, 1.0802049911622503E+06, 999886.2487208968, 108 999886.2487208956,912564.3830552017, 912564.3830552002 109 g ; 110 double lambda13[29]= f 111 1.7651999234170078E+06, 1.7651897485634477E+06, 1.7325129820588364E+06, 112 1.7321869225608557E+06, 1.7067712359836642E+06, 1.7032516877194783E+06, 113 1.6894241417204833E+06, 1.6755976695896771E+06, 1.6717123464096573E+06, 114 1.6445435967194596E+06, PAGE 147 GeneticAlgorithm126 1.6440866412283191E+06, 1.6069606454413754E+06, 115 1.6069324644372643E+06, 1.5621138221717272E+06, 1.5621127412920853E+06, 116 1.5100592092856956E+06, 1.5100591818056372E+06, 1.4508866636989913E+06, 117 1.450886663223427E+06,1.384646903482151 E+06,1.3846469034765232E+06, 118 1.3113685856813397E+06, 1.3113685856812955E+06, 1.2310691829162193E+06, 119 1.2310691829162186E+06, 1.143760148413557E+06, 1.1437601484135569E+06, 120 1.049449509522029E+06, 1.0494495095220287E+06 121 g ; 122 double lambda14[31]= f 123 2.018618000058942E+06,2.01861249972054E +06,1.983239125363205E+06, 124 1.9830448721113487E+06, 1.954298720927843E+06, 1.9518542659809245E+06, 125 1.9344253583887462E+06, 1.9228821210116849E+06, 1.9169510160323123E+06, 126 1.8915639838196097E+06, 1.8906947671986497E+06, PAGE 148 GeneticAlgorithm127 1.8541555448561464E+06, 127 1.85409135295139E+06,1.8094860800209267 E+06,1.809483148882202E+06, 128 1.7575488125565376E+06, 1.7575487230732455E+06, 1.6984532584739896E+06, 129 1.6984532565834806E+06, 1.6322656359859388E+06, 1.6322656359579253E+06, 130 1.5590233082860042E+06, 1.559023308285716E+06, 1.4787488299962203E+06, 131 1.4787488299962163E+06, 1.3914567955786576E+06, 1.391456795578656E+06, 132 1.2971572658501246E+06, 1.2971572658501237E+06, 1.195857602087346E+06, 133 1.195857602087346E+06 134 g ; 135 double lambda15[33]= f 136 2.289025842913789E+06, 2.2890228910734854E+06, 2.2509859172247276E+06, 137 2.2508720823539174E+06, 2.2189426608592276E+06, 2.217306424433249E+06, 138 2.1960716592946434E+06, 2.186768360462793E+06, 2.1782318859949005E+06, PAGE 149 GeneticAlgorithm128 139 2.155000740087895E+06, 2.1534449884835887E+06, 2.1177416006039474E+06, 140 2.117604532408104E+06, 2.0732800352936143E+06, 2.073272671644201E+06, 141 2.0214864192452533E+06, 2.0214861537146382E+06, 1.9624856233435937E+06, 142 1.962485616642242E+06, 1.8963624099341815E+06, 1.8963624098134467E+06, 143 1.8231648660578215E+06, 1.8231648660562625E+06, 1.742921784826352E+06, 144 1.742921784826338E+06, 1.6556516017148108E+06, 1.6556516017148087E+06, 145 1.5613668578662593E+06, 1.5613668578662593E+06, 1.46007657850753E+06, 146 1.460076578507529E+06, 1.3517876161153005E+06, 1.3517876161152995E+06 147 g ; 148 double lambda16[35]= f 149 2.5764242918657884E+06, 2.576422717726226E+06, 2.535743479035183E+06, 150 2.5356776881223535E+06, PAGE 150 GeneticAlgorithm129 2.5007089381928323E+06, 2.499647294176532E+06, 151 2.4745267605421E+06,2.467310903704027E +06,2.4556427650180305E+06, 152 2.4348747638219628E+06, 2.432248061155586E+06, 2.3977086090581925E+06, 153 2.397432383414484E+06,2.353482064806608 E+06,2.3534647546641245E+06, 154 2.3018616644269554E+06, 2.301860936485159E+06, 2.242976051096843E+06, 155 2.2429760295124254E+06, 2.1769313334576627E+06, 2.1769313329949807E+06, 156 2.103788657287819E+06,2.103788657280566 E+06,2.0235844026734552E+06, 157 2.0235844026733716E+06, 1.9363416551310872E+06, 1.9363416551310865E+06, 158 1.8420759495026893E+06, 1.8420759495026877E+06, 1.7407983155190572E+06, 159 1.7407983155190554E+06, 1.6325169915186681E+06, 1.6325169915186665E+06, 160 1.5172384366238692E+06, 1.5172384366238674E+06 161 g ; 162 double lambda17[37]= f PAGE 151 GeneticAlgorithm130 163 2.880814517564181E+06,2.880813682785732 E+06,2.8375056241680863E+06, 164 2.837468047422677E+06, 2.7995803135489114E+06, 2.7989089646101315E+06, 165 2.769944008796321E+06,2.764566141081148 E+06,2.749310481782252E+06, 166 2.7312176178373266E+06, 2.7270276194218164E+06, 2.6940508610793557E+06, 167 2.693522945150684E+06,2.650078186413116 E+06,2.6500398144812104E+06, 168 2.5986633687868123E+06, 2.5986615056253755E+06, 2.5399162414668347E+06, 169 2.539916177401569E+06, 2.4739660898088887E+06, 2.4739660882018926E+06, 170 2.4008897627162533E+06, 2.400889762686392E+06, 2.320732794272994E+06, 171 2.3207327942725793E+06, 2.2335238523627957E+06, 2.233523852362793E+06, 172 2.139282052736529E+06, 2.1392820527365287E+06, 2.0380208172481742E+06, 173 2.0380208172481726E+06, 1.9297500355689153E+06, 1.9297500355689146E+06, PAGE 152 GeneticAlgorithm131 174 1.8144773383436364E+06, 1.814477338343633E+06, 1.6922088783326834E+06, 175 1.6922088783326806E+06 176 g ; 177 double lambda18[39]= f 178 3.202197920993432E+06, 3.2021974804885336E+06, 3.1562688996531903E+06, 179 3.156247656254703E+06,3.115532174763219 E+06,3.1151165305564418E+06, 180 3.0824438626590273E+06, 3.0785894385957033E+06, 3.0593881446024487E+06, 181 3.0440708564113583E+06, 3.0377449980189665E+06, 3.0067691545121092E+06, 182 3.005809253346463E+06, 2.9630546551809753E+06, 2.962973961656442E+06, 183 2.911879540913876E+06,2.911875051964264 E+06,2.8532972651066026E+06, 184 2.8532970879675336E+06, 2.7874599170610327E+06, 2.787459911929414E+06, 185 2.714462934729376E+06, 2.7144629346181517E+06, 2.6343628197595836E+06, 186 2.6343628197577605E+06, 2.5471948945824686E+06, PAGE 153 GeneticAlgorithm132 2.5471948945824443E+06, 187 2.452982525377337E+06, 2.4529825253773355E+06, 2.351741965491444E+06, 188 2.351741965491442E+06, 2.2434850556662264E+06, 2.2434850556662255E+06, 189 2.1282208090020414E+06, 2.1282208090020395E+06, 2.0059563812034372E+06, 190 2.0059563812034368E+06, 1.8766976856947616E+06, 1.876697685694761E+06 191 g ; 192 double lambda19[41]= f 193 3.5405760748746344E+06, 3.5405758434490785E+06, 3.492031737742095E+06, 194 3.4920198354029274E+06,3.44854163662683 E+06,3.448288803535428E+06, 195 3.41209756427058E+06,3.4094325152076525 E+06,3.386046525896083E+06, 196 3.373484406777713E+06, 3.3644183483752483E+06, 3.335872710182198E+06, 197 3.3342092894021845E+06, 3.2923988835247513E+06, 3.2922371525542918E+06, 198 3.241497434468052E+06,3.241487187042215 E+06,3.183109524562102E+06, PAGE 154 GeneticAlgorithm133 199 3.1831090643870668E+06, 3.117405583455719E+06, 3.1174055682218387E+06, 200 3.0445025841672034E+06, 3.0445025837870995E+06, 2.964470081279138E+06, 201 2.964470081271904E+06, 2.8773512832388794E+06, 2.8773512832387756E+06, 202 2.783174568379558E+06, 2.7831745683795577E+06, 2.6819595179997194E+06, 203 2.6819595179997175E+06, 2.5737202610321064E+06, 2.5737202610321045E+06, 204 2.4584674295205497E+06, 2.458467429520548E+06, 2.3362093524785643E+06, 205 2.3362093524785633E+06, 2.206952811368578E+06, 2.2069528113685767E+06, 206 2.0707035329180858E+06, 2.0707035329180826E+06 207 g ; 208 double lambda20[43]= f 209 3.8959506899210517E+06, 3.895950568820172E+06, 3.84479382690094E+06, 210 3.844787210912154E+06, 3.7985909230402773E+06, PAGE 155 GeneticAlgorithm134 3.7984394066781783E+06, 211 3.758927227114459E+06, 3.7571413815296204E+06, 3.7294652674629646E+06, 212 3.7195142222752124E+06, 3.707125793689471E+06, 3.6813806438279687E+06, 213 3.678631997499326E+06,3.638100729997149 E+06,3.6377907006149082E+06, 214 3.5875037016550666E+06, 3.5874814205737854E+06, 3.529342716741094E+06, 215 3.529341585843838E+06, 3.4637953579833535E+06, 3.4637953155711116E+06, 216 3.391002764349325E+06,3.39100276314396E +06,3.311049914075208E+06, 217 3.31104991404886E+06,3.2239893148103463 E+06,3.223989314809899E+06, 218 3.1298552226130976E+06, 3.129855222613092E+06, 3.0286711064164205E+06, 219 3.0286711064164205E+06, 2.920453761352144E+06, 2.920453761352144E+06, 220 2.805215702592745E+06,2.805215702592741 E+06,2.682966622279309E+06, 221 2.682966622279307E+06,2.553714309476803 E+06,2.5537143094768026E+06, 222 2.417465249356085E+06,2.417465249356082 PAGE 156 GeneticAlgorithm135 E+06,2.2742250239805644E+06, 223 2.2742250239805644E+06 224 g ; 225 double lambda21[45]= f 226 4.2683235955443345E+06, 4.2683235324014025E+06, 4.214555683689986E+06, 227 4.2145520320738405E+06, 4.165667620255081E+06, 4.1655779798280434E+06, 228 4.1229205220334735E+06, 4.121755055004137E+06, 4.0898181843442908E+06, 229 4.082219482880793E+06, 4.0659943267583926E+06, 4.0433226795723327E+06, 230 4.0389926073092795E+06, 4.0001541373052327E+06, 3.999584297217503E+06, 231 3.949884698950277E+06, 3.9498383603625246E+06, 3.891985805650071E+06, 232 3.891983161820597E+06,3.82662097610281E +06,3.8266208645787793E+06, 233 3.753957151881908E+06, 3.7539571483032308E+06, 3.6740973758115903E+06, 234 3.67409737572272E+06,3.5871050745440368 E+06,3.587105074542312E+06, 235 3.4930213650178146E+06, PAGE 157 GeneticAlgorithm136 3.493021365017788E+06, 3.391874233824616E+06, 236 3.3918742338246154E+06, 3.2836835651614084E+06, 3.283683565161406E+06, 237 3.1684640515925703E+06,3.16846405159257 E+06,3.0462269591725576E+06, 238 3.046226959172555E+06, 2.9169812392083476E+06, 2.916981239208345E+06, 239 2.780734251074638E+06, 2.7807342510746354E+06, 2.637492245066981E+06, 240 2.637492245066979E+06, 2.4872606926406096E+06, 2.4872606926406072E+06 241 g ; 242 double lambda22[47]= f 243 4.657696728840883E+06,4.657696696024805 E+06,4.601318375220347E+06, 244 4.601316372512418E+06,4.549763738144226 E+06,4.5497112962951055E+06, 245 4.504049133850486E+06,4.50330512768396E +06,4.467251909259629E+06, 246 4.461659637227911E+06,4.441184682864353 E+06,4.421738915928439E+06, 247 4.415236208549459E+06, 4.3785590040787365E+06, 4.37755321489096E+06, 248 4.328627012182087E+06,4.32853451984185E PAGE 158 GeneticAlgorithm137 +06,4.27102702067718E+06, 249 4.271021114039597E+06,4.205873601206572 E+06,4.205873322621735E+06, 250 4.1333590237839245E+06, 4.133359013764085E+06, 4.053607233857739E+06, 251 4.053607233577535E+06,3.966694429035837 E+06,3.9666944290296705E+06, 252 3.8726697040594686E+06, 3.872669704059361E+06, 3.7715662718530456E+06, 253 3.771566271853044E+06,3.66340757794076E +06,3.663407577940758E+06, 254 3.5482108192872605E+06, 3.5482108192872573E+06, 3.4259890692796386E+06, 255 3.4259890692796367E+06, 3.296752612276143E+06, 3.296752612276142E+06, 256 3.1605098094808087E+06, 3.160509809480805E+06, 3.017267676495351E+06, 257 3.0172676764953495E+06, 2.8670322778841164E+06, 2.8670322778841113E+06, 258 2.709809002444701E+06, 2.7098090024446994E+06 259 g ; 260 double lambda23[49]= f 261 5.064072128278947E+06,5.064072111274711 PAGE 159 GeneticAlgorithm138 E+06,5.005083344544358E+06, 262 5.005082252452029E+06,4.950874563856404 E+06,4.950844186337165E+06, 263 4.902282353632799E+06,4.901816097713528 E+06,4.861865722149152E+06, 264 4.85789158634141E+06,4.832879267610285E +06,4.816678625930313E+06, 265 4.807360881550488E+06,4.77332306834321E +06,4.771617336726497E+06, 266 4.723718268746647E+06,4.72354061030606E +06,4.666453904815133E+06, 267 4.66644124623282E+06,4.601543783764492E +06,4.601543119498328E+06, 268 4.529201230493088E+06,4.529201203878532 E+06,4.449573950223289E+06, 269 4.449573949391323E+06,4.362753017484699 E+06,4.362753017464135E+06, 270 4.268796774394526E+06,4.268796774394119 E+06,4.167744457285932E+06, 271 4.1677444572859295E+06, 4.0596235998894675E+06, 4.05962359988946E+06, 272 3.9444542663321667E+06, 3.9444542663321667E+06, 3.8222515952343363E+06, 273 3.8222515952343307E+06, 3.6930273921802007E+06, 3.693027392180198E+06, 274 3.5567911605019867E+06, 3.556791160501983E+06, PAGE 160 GeneticAlgorithm139 3.4135507876493516E+06, 275 3.4135507876493502E+06, 3.263313013496511E+06, 3.2633130134965107E+06, 276 3.1060837567429338E+06, 3.106083756742928E+06, 2.9418683467328865E+06, 277 2.9418683467328856E+06 278 g ; 279 double lambda24[51]= f 280 5.487451930042147E+06,5.487451921255068 E+06,5.425852302838963E+06, 281 5.425851710405522E+06,5.368997681223934 E+06,5.368980239312884E+06, 282 5.317593891630462E+06,5.317306248019409 E+06,5.273704183852363E+06, 283 5.270967300878827E+06,5.241272231023886 E+06,5.22819822732823E+06, 284 5.215428485473801E+06,5.184463501919505 E+06,5.181684931741604E+06, 285 5.135148285561008E+06,5.134819236088109 E+06,5.078253448771731E+06, 286 5.078227343616456E+06,5.013621422382976 E+06,5.013619904408644E+06, 287 4.941476164436018E+06,4.941476097037234 E+06,4.861991663786338E+06, 288 4.861991661445902E+06,4.775276241430891 E+06,4.775276241366345E+06, 289 4.681398930639575E+06,4.681398930638146 E+06,4.58040588811556E+06, PAGE 161 GeneticAlgorithm140 290 4.5804058881155355E+06, 4.472329323336173E+06, 4.472329323336173E+06, 291 4.357192569523012E+06,4.357192569523009 E+06,4.235013114973412E+06, 292 4.235013114973408E+06, 4.1058044933524122E+06, 4.105804493352412E+06, 293 3.969577503969469E+06, 3.9695775039694603E+06, 3.8263410227392903E+06, 294 3.826341022739286E+06, 3.6761025546944607E+06, 3.676102554694453E+06, 295 3.518868618652043E+06, 3.5188686186520425E+06, 3.3546450201834445E+06, 296 3.354645020183439E+06,3.183437048642761 E+06,3.183437048642759E+06 297 g ; 298 double lambda25[53]= f 299 5.927838365874129E+06,5.927838361344695 E+06,5.863627163535925E+06, 300 5.863626843678365E+06,5.80413223919597E +06,5.804122303630105E+06, 301 5.749963874738896E+06, 5.7497888070445405E+06, 5.702766573250441E+06, 302 5.700932115455472E+06,5.666556385649527 E+06,5.656358659963898E+06, PAGE 162 GeneticAlgorithm141 303 5.639558961717086E+06,5.612007903812376 E+06,5.607664622490834E+06, 304 5.562910554047974E+06,5.562322069709439 E+06,5.506412359606907E+06, 305 5.506360421719402E+06,5.442095734734054 E+06,5.442092399010288E+06, 306 5.370175724162188E+06,5.370175560754903 E+06,5.290854169423592E+06, 307 5.290854163153787E+06,5.204259252758687 E+06,5.204259252567037E+06, 308 5.1104723401271105E+06, 5.110472340122397E+06, 5.009547518969465E+06, 309 5.00954751896937E+06,4.901522329746676E +06,4.90152232974667E+06, 310 4.786423819778651E+06,4.786423819778649 E+06,4.664272140341964E+06, 311 4.664272140341959E+06,4.535082780170888 E+06,4.535082780170888E+06, 312 4.398868002908102E+06,4.398868002908099 E+06,4.255637800281175E+06, 313 4.255637800281171E+06,4.105400540441308 E+06,4.1054005404413054E+06, 314 3.9481634187845057E+06, 3.9481634187845048E+06, 3.7839327775600073E+06, 315 3.7839327775600036E+06,3.61271433638889 E+06,3.6127143363888883E+06, 316 3.4345133611124223E+06, 3.4345133611124204E+06 PAGE 163 GeneticAlgorithm142 317 g ; 318 double lambda26[55]= f 319 6.385233761775859E+06,6.385233759446483 E+06,6.318410002234724E+06, 320 6.318409830292138E+06,6.256278443348936 E+06,6.256272824116054E+06, 321 6.199378451660816E+06,6.199273155302231 E+06,6.1490256182038365E+06, 322 6.1478238388498565E+06, 6.108903647525528E+06, 6.101222456674886E+06, 323 6.079915241683586E+06,6.055994454057415 E+06,6.049486565696995E+06, 324 6.007003986502321E+06,6.005986978674149 E+06,5.950917523237045E+06, 325 5.950817621894108E+06,5.886955251905462 E+06,5.886948182921028E+06, 326 5.815291274690117E+06,5.81529089405042E +06,5.736154893633479E+06, 327 5.736154877569879E+06,5.649696939710807 E+06,5.649696939169514E+06, 328 5.556012974512853E+06,5.556012974498109 E+06,5.455166155836077E+06, 329 5.455166155835747E+06,5.347200086282389 E+06,5.34720008628238E+06, 330 5.232146019825346E+06,5.232146019825345 E+06,5.110027115494167E+06, 331 5.1100271154941665E+06, 4.980861065830478E+06, 4.980861065830467E+06, PAGE 164 GeneticAlgorithm143 332 4.844661782722773E+06,4.844661782722772 E+06,4.701440512500288E+06, 333 4.701440512500284E+06,4.551206593002804 E+06,4.551206593002794E+06, 334 4.393967979271637E+06,4.393967979271635 E+06,4.229731615835695E+06, 335 4.229731615835691E+06, 4.0585037049977523E+06, 4.05850370499775E+06, 336 3.8802899032147937E+06, 3.880289903214792E+06, 3.695095466882649E+06, 337 3.695095466882647E+06 338 g ; 339 double lambda27[57]= f 340 6.859640537192378E+06,6.859640535996998 E+06,6.790203032243934E+06, 341 6.790202940183759E+06,6.725437216824465 E+06,6.725434059429707E+06, 342 6.665828586178706E+06,6.665765915544462 E+06,6.61244495373664E+06, 343 6.611672674047069E+06, 6.5684429749091845E+06, 6.562850811622767E+06, 344 6.5366881697971625E+06, 6.5164711272124285E+06, 6.507127421286784E+06, 345 6.467434753547818E+06,6.46573635041426E +06,6.411756723372505E+06, 346 6.411570639157669E+06, PAGE 165 GeneticAlgorithm144 6.3481878575459225E+06, 6.348173376112619E+06, 347 6.276813605908325E+06,6.276812751448519 E+06,6.197886866272973E+06, 348 6.197886826767972E+06,6.111583910624874 E+06,6.1115839091642015E+06, 349 6.018016600079977E+06,6.018016600036193 E+06,5.917258450002892E+06, 350 5.9172584500018135E+06, 5.809359941858769E+06, 5.809359941858751E+06, 351 5.6943570815504985E+06, 5.694357081550497E+06, 5.5722764150685575E+06, 352 5.572276415068549E+06,5.443138111055406 E+06,5.443138111055398E+06, 353 5.30695793027178E+06,5.306957930271779E +06,5.163748524652215E+06, 354 5.1637485246522045E+06, 5.013520317441442E+06, 5.013520317441435E+06, 355 4.856282113381546E+06,4.856282113381545 E+06,4.692041530315998E+06, 356 4.692041530315993E+06,4.520805309930525 E+06,4.520805309930525E+06, 357 4.342579545039325E+06,4.342579545039324 E+06,4.157369848211038E+06, 358 4.1573698482110305E+06, 3.9651814784984645E+06, 3.965181478498463E+06 PAGE 166 GeneticAlgorithm145 359 g ; 360 double lambda28[59]= f 361 7.351061204485443E+06,7.351061203873221 E+06,7.279008589521207E+06, 362 7.2790085404128255E+06, 7.211609979954377E+06, 7.21160821638955E+06, 363 7.149308797542868E+06,7.149271845588025 E+06,7.092990021980196E+06, 364 7.092501803049589E+06,7.045246464776097 E+06,7.041300946502521E+06, 365 7.0100844323190665E+06, 6.993494019444049E+06, 6.980627796825796E+06, 366 6.944217957617108E+06,6.941479014615768 E+06,6.888919667616846E+06, 367 6.888583592066908E+06,6.825780903177578 E+06,6.825752166607826E+06, 368 6.754732892905111E+06,6.754731039678863 E+06,6.676042688152259E+06, 369 6.676042594601799E+06,6.589914475065019 E+06,6.589914471284999E+06, 370 6.496478766562333E+06,6.496478766438239 E+06,6.395820891110032E+06, 371 6.395820891106686E+06,6.287999122646778 E+06,6.287999122646699E+06, 372 6.173054822990744E+06, 6.1730548229907425E+06, 6.051018342115069E+06, 373 6.051018342115068E+06,5.921912622638672 PAGE 167 GeneticAlgorithm146 E+06,5.921912622638672E+06, 374 5.785755492816393E+06,5.78575549281639E +06,5.64256117425366E+06, 375 5.642561174253655E+06,5.492341301044085 E+06,5.492341301044084E+06, 376 5.335105625086728E+06,5.335105625086726 E+06,5.170862514307698E+06, 377 5.1708625143076945E+06, 4.999619310987304E+06, 4.999619310987304E+06, 378 4.821382593634635E+06,4.821382593634632 E+06,4.636158371145172E+06, 379 4.636158371145171E+06,4.443952228638714 E+06,4.443952228638712E+06, 380 4.244769438310315E+06,4.244769438310311 E+06 381 g ; 382 double lambda29[61]= f 383 7.859498368577155E+06,7.859498368264181 E+06,7.784829123251648E+06, 384 7.784829097144843E+06,7.71479850920921E +06,7.714797529546343E+06, 385 7.649816120500126E+06,7.649794516616069 E+06,7.590632722763137E+06, 386 7.590328404821E+06,7.539331849630471E +06,7.536624041235278E+06, 387 7.500313976347101E+06,7.487124969823659 E+06,7.470093649028564E+06, 388 7.437378847894824E+06,7.433119083058799 E+06,7.382399336785053E+06, PAGE 168 GeneticAlgorithm147 389 7.381810356260288E+06,7.319721442328335 E+06,7.319666112106942E+06, 390 7.249038665336596E+06,7.249034773177208 E+06,7.170614494526858E+06, 391 7.170614280631077E+06,7.084682621990302 E+06,7.084682612578763E+06, 392 6.991394794281427E+06,6.991394793944455 E+06,6.890849799208443E+06, 393 6.890849799198524E+06,6.78311472695399E +06,6.78311472695375E+06, 394 6.668236964915888E+06,6.668236964915885 E+06,6.5462511257490935E+06, 395 6.546251125749091E+06,6.417183251791649 E+06,6.417183251791649E+06, 396 6.281053476835378E+06,6.281053476835375 E+06,6.137877770215131E+06, 397 6.1378777702151295E+06, 5.987669112676831E+06, 5.987669112676826E+06, 398 5.830438308577052E+06,5.830438308577048 E+06,5.666194558746144E+06, 399 5.666194558746138E+06,5.494945872018196 E+06,5.494945872018185E+06, 400 5.316699365710627E+06,5.316699365710618 E+06,5.131461488239398E+06, 401 5.131461488239396E+06,4.939238186231485 E+06,4.939238186231484E+06, 402 4.740035031483137E+06,4.740035031483133 E+06,4.5338573184748525E+06, 403 4.5338573184748385E+06 PAGE 169 GeneticAlgorithm148 404 g ; 405 jgaPopulation p; 406 unsignedlonglong i,j,k,l; 407 double lambda[30]= f lambda0,lambda1,lambda2, lambda3,lambda4,lambda5,lambda6,lambda7, 408 lambda8,lambda9,lambda10,lambda11, lambda12,lambda13,lambda14, lambda15, 409 lambda16,lambda17,lambda18,lambda19, lambda20,lambda21,lambda22, lambda23, 410 lambda24,lambda25,lambda26,lambda27, lambda28,lambda29 411 g ; 412 double HA, H2A; 413 double X[8],r; 414 double variance,mutation; 415 int rc; 416 int copt; 417 unsignedlonglong n=0,g=9,J1=0,J2=0,threads=1; 418 419 while copt=getoptargc,argv,"n:g:j:k:t:"!= )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 f 420 switch copt f 421 case 'n': 422 n=atolloptarg; 423 break ; 424 case 'g': 425 g=atolloptarg; 426 break ; 427 case 'j': PAGE 170 GeneticAlgorithm149 428 J1=atolloptarg; 429 break ; 430 case 'k': 431 J2=atolloptarg; 432 break ; 433 case 't': 434 threads=atolloptarg; 435 break ; 436 default : 437 goto usage; 438 g 439 g 440 if n==0 jj g==0 goto usage; 441 if J2 > 30 goto usage; 442 if J1 < 1 goto usage; 443 if J1 > J2 goto usage; 444 445 HA= double malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1; 446 H2A= double malloc sizeof double J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1; 447 for i=0;i < J2 )]TJ/F18 9.9626 Tf 7.482 0 Td [(J1+1;i++ f 448 HA[i]= double malloc sizeof double 2 J1+i+1 2 J1+i+1; 449 H2A[i]= double malloc sizeof double 2 J1+i+1 2 J1+i+1; 450 g 451 p=jgaPopulationCreateJ1,J2,n,&lambda[J1 )]TJ/F18 9.9626 Tf 8.69 0 Td [(1],threads; 452 if rc=jgaPopulationScorep,threads!=0 f 453 fprintfstderr,"jgaPopoulationScorep, 4 failed n n"; 454 return )]TJ/F18 9.9626 Tf 8.32 0 Td [(1; 455 g PAGE 171 GeneticAlgorithm150 456 457 for i=0;i < g;i++ f 458 for j=0;j < J2 )]TJ/F18 9.9626 Tf 7.481 0 Td [(J1+1;j++ f dHamiltonianParametersComputeArray0,p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[j],HA[j ],NULL; g 459 dHamiltonianFitJ1,J2,HA,X,H2A,&r; 460 variance=jgaPopulationVariancep; 461 mutation=1 )]TJ/F18 9.9626 Tf 8.07 0 Td [(powvariance/2.0 PI,10.0/1.0/10.0; 462 printf"Gen %lld % .15e: % .15e: % .15e % .15e % .15e % .15e % .15e % .15e % .15e % .15e % .15e n n",i,variance, mutation,X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7], r; 463 / 464 forl=0;l < n;l++ f 465 printf"ID%lld:",l; 466 forj=0;j < J2 )]TJ/F21 9.9626 Tf 13.68 0 Td [(J1+1;j++ f 467 fork=0;k < J1+j 2 J1+j+1;k++ f printf"%.15 f",p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[l].h[j] )]TJ/F11 9.9626 Tf 7.543 0 Td [(> theta[k]; g 468 g 469 printf"fit=%.15e n n",p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[l].fitness; 470 g 471 / 472 jgaPopulationHusbandryp,mutation,threads; 473 g 474 475 printf"Gen %lld: % .15e % .15e % .15e % .15e % .15e % .15e % .15e % .15e % .15e n n",i,X[0],X[1],X[2],X[3],X[4],X[5], X[6],X[7],r; 476 / 477 fori=0;i < J2;i++ f dHamiltonianParametersComputeArrayp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e PAGE 172 GeneticAlgorithm151 [0].h[i],HA[i],NULL; g 478 dHamiltonianFitJ1,J2,HA,X,H2A,&r; 479 fori=0;i < J2;i++ f dPrintMatrix"H",2 i+1+1,2 i+1+1,HA [i],2 i+1+1; g 480 fori=0;i < J2;i++ f dPrintMatrix"H2",2 i+1+1,2 i+1+1, H2A[i],2 i+1+1; g 481 dPrintMatrix"X",1,8,X,1; 482 printf"r=%e n n",r; 483 / 484 jgaPopulationDestroyp; 485 486 return 0; 487 usage: 488 fprintfstderr,"%s )]TJ/F18 9.9626 Tf 7.38 0 Td [(n N )]TJ/F18 9.9626 Tf 7.657 0 Td [(g G )]TJ/F18 9.9626 Tf 8.626 0 Td [(j J1 )]TJ/F18 9.9626 Tf 7.518 0 Td [(k J2 n n",argv[0]; 489 fprintfstderr," n nWhere n n"; 490 fprintfstderr,"N = population size n n"; 491 fprintfstderr,"G = generations n n"; 492 fprintfstderr,"J1 J1 < J2 n n"; 493 fprintfstderr,"J2 < = 30 n n"; 494 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 495 g PAGE 173 Chapter5 ConclusionThewiderangeofmagnitudesofrotationalconstantsofamoleculepresentchallengestothespectroscopistandcomputeralgorithmalike.Wesuggestthatsplittingtheestimationoftheserotationalconstantsprovidesatechniquetobetterestimatethemsothaterrorsarenotuniformlydistributedovervaluesofawiderangeofmagnitudes.ThereareseveralimprovementsrecommendedthroughoutChapter4andthereareseverallargescaleinvestigationstobeperformed.Thechoiceoftnessfunctionisrelativelyuninspired.DirectcomputationofseveralmorelowJvalueblocksiseasilypossible.WeightingtheresidualsmayimproveperformanceaslowJblockshavefewnon-zeroentrieswithsmallervaluethanhighJblocks.Therearealsoothersourcesoftness,suchastheeigenvaluesoftheestimateoftheHamiltonian.TheabilitytoestimateusingaspeciclistofblocksislikelyusefulastheconstantsA,BandCareuniquelyspeciedinblocksJ=1andJ=2,whileafewhighJvalueblocksmaysucetodeterminethedistortionconstants.Thiswouldconsiderablyreducetheruntimeofthealgorithm. 152 PAGE 174 153 TherearelikelystilllargescaleimprovementsinthefunctionsdHamiltonianParametersCPUComputeArrayanddHamiltonianParametersGPUComputeArray.EnergyconsumptionestimatesshowthattheGPUissomewhatunderutilizedduringcomputation.AsinglelargerJ blockmaybemorecomputationallyecientifitsaturatestheGPU.Ecientmutationsratesandfunctionstovarythemutationshouldbeinvestigated.Thereissomeindicationthatlowinitialmutationratesimproveconvergencerate,butleadtothefoundereectinthepopulation.Schemesthatmaintainpopulationvarietywhilekeepingmutationrateslowsuchasproducingdenovopopulationelementseachgenerationcouldproveuseful.Whileuniformcrossoverandsinglepointcrossoverhavebothbeenimplementedexperimentsshouldbeperformedtodeterminethedierencesinconvergencerates.Moreoverthereareothercrossoverschemesthatmaybeimplemented.Measuresofpopulationvarianceovergenerationsmayinformchangestotheselectionoperatorsuchasatteningorrougheningtheroulettewheel.Finally,bynoticingthatmutationisoftenthesourceofimprovementsinlatestagesofthealgorithmitmaybeusefultoemploygradientdescentattimestoreneestimates. PAGE 175 AppendixA ComputingaHamiltonianfrom AnglesandEigenvaluesInthisappendixwecomputeamatrixfromit'seigenvaluesandtheanglesfromwhichtheeigenvectorsarecomposed.Thiscomputationisattheheartofthetnessfunctionofthegeneticalgorithm.WeconsiderarigidapproximationoftheJ=1quantumlevel.Letf k g=f 16530 : 7 ; 13254 :; 12806 : 9 gbetheeigenvaluesoftherigidrotorassociatedwithparam-etersA=8:488888103,B=8:041802103andC=4:765117103.Let 1 ; 2= 4,154 PAGE 176 155 1 ; 3 = 3 and 2 ; 3 = 2 .Letthereectionconstantbe+1;thenwehavethefollowing R 1 ; 2 = 0 B B B B @ cos 1 ; 2 )]TJ/F15 11.9552 Tf 11.291 0 Td [(sin 1 ; 2 0 sin 1 ; 2 cos 1 ; 2 0 001 1 C C C C A = 0 B B B B @ 1 p 2 )]TJ/F56 7.9701 Tf 14.022 4.707 Td [(1 p 2 0 1 p 2 1 p 2 0 001 1 C C C C A R 1 ; 3 = 0 B B B B @ 1 2 0 )]TJ/F60 7.9701 Tf 10.494 11.318 Td [(p 3 2 010 p 3 2 0 1 2 1 C C C C A R 2 ; 3 = 0 B B B B @ 100 00 )]TJ/F15 11.9552 Tf 9.299 0 Td [(1 010 1 C C C C A Wecompute Q = Q R j;k Q = 0 B B B B @ 1 2 p 2 )]TJ 10.494 15.183 Td [(p 3 2 2 1 p 2 1 2 p 2 )]TJ 10.494 15.183 Td [(p 3 2 2 1 p 2 p 3 2 1 2 0 1 C C C C A PAGE 177 156 andcompute ^ H = Q Q )]TJ/F56 7.9701 Tf 6.587 0 Td [(1 ^ H = Q Q )]TJ/F56 7.9701 Tf 6.586 0 Td [(1 = 0 B B B B @ 14892 : 31158 : 491158 : 49 1158 : 4913849 : 61042 : 73 1158 : 491042 : 7313849 : 6 1 C C C C A A.1 Wethenwritethismatrixincolumnorderas B = 0 B B B B B B B B B B B B B B B B B B B B B B B @ 14892 : 3 1158 : 49 1158 : 49 1158 : 49 13849 : 6 1042 : 73 1158 : 49 1042 : 73 13849 : 6 1 C C C C C C C C C C C C C C C C C C C C C C C A PAGE 178 157 andthecoecientmatrixforthe J =1blockas A = 0 B B B B B B B B B B B B B B B B B B B B B B B @ 10 : 50 : 5 000 00 : 5 )]TJ/F15 11.9552 Tf 9.298 0 Td [(0 : 5 000 011 000 00 : 5 )]TJ/F15 11.9552 Tf 9.298 0 Td [(0 : 5 000 10 : 50 : 5 1 C C C C C C C C C C C C C C C C C C C C C C C AThewecomputemin x jj Ax )]TJ/F57 11.9552 Tf 11.955 0 Td [(B jj 2usingLinearLeastSquaresandndsolutionx=:76;7723:3;5716:74correspondingtoA;B;C.Thereadermayverifythatthevalues 1 ; 2 =0, 1 ; 3 = 4 and 2 ; 3 = 2 minimizestheresidual. PAGE 179 AppendixB hf.c TestPlans Thetestplansforthe dHamiltonianParameters areincludedhere. 158 PAGE 180 159 FunctionB.0.1 unit dHamiltonianParametersCreate ListingB.1: hf.c:unit dHamiltoinaParametersCreate 1 void unit dHamiltonianParametersCreate void 2 f 3 double eigenvalues[3]= f 0,1,2 g ; 4 unsignedlonglong i; 5 dHamiltonianParameters h; 6 7 h=dHamiltonianParametersCreate1,eigenvalues; 8 CU ASSERT PTR NOT NULLh; 9 if h==NULL goto error0; 10 CU ASSERT PTR NOT NULLh )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta; 11 if h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta==NULL goto error1; 12 CU ASSERT PTR NOT NULLh )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda; 13 if h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda==NULL goto error1; 14 CU ASSERTh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation==0; 15 CU ASSERTh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation==0; 16 CU ASSERTh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J==1; 17 for i=0;i < 3;i++ f CU ASSERT DOUBLE EQUALh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; g 18 for i=0;i < 3;i++ f CU ASSERT DOUBLE EQUALh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[i], double i,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; g 19 return ; 20 error1: 21 dHamiltonianParametersDestroyh; 22 error0: 23 return ; 24 g PAGE 181 160 FunctionB.0.2 dHamiltonianParametersRandom ListingB.2: hf.c:unit dHamiltonianParametersRandom 1 void unit dHamiltonianParametersRandom void 2 f 3 double eigenvalues[3]= f 0,1,2 g ; 4 unsignedlonglong i; 5 dHamiltonianParameters h; 6 7 h=dHamiltonianParametersRandom1,eigenvalues; 8 CU ASSERT PTR NOT NULLh; 9 if h==NULL goto error0; 10 CU ASSERT PTR NOT NULLh )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta; 11 if h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta==NULL goto error1; 12 CU ASSERT PTR NOT NULLh )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda; 13 if h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda==NULL goto error1; 14 CU ASSERTh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation==0 jj h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation==1; 15 CU ASSERTh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation==0; 16 CU ASSERTh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> J==1; 17 for i=0;i < 3;i++ f 18 CU ASSERTh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i] > =0&&h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[i] < 2 PI; 19 g 20 for i=0;i < 3;i++ f CU ASSERT DOUBLE EQUALh )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[i], double i,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; g 21 return ; 22 error1: 23 dHamiltonianParametersDestroyh; 24 error0: 25 return ; 26 g PAGE 182 161 FunctionB.0.3 unit dHamiltonianParametersMate ListingB.3: hf.c:unit dHamiltonianParametersMate 1 void unit dHamiltonianParametersMate void 2 f 3 dHamiltonianParameters h[3]; 4 double eigenvalues[3]= f 0,1,2 g ; 5 unsignedlonglong i; 6 7 if h[0]=dHamiltonianParametersRandom1,eigenvalues==NULL goto error0; 8 if h[1]=dHamiltonianParametersRandom1,eigenvalues==NULL goto error1; 9 h[2]=dHamiltonianParametersMateh[0],h[1]; 10 CU ASSERT PTR NOT NULLh[2]; 11 if h[2]==NULL goto error2; 12 CU ASSERTh[2] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> J==1; 13 CU ASSERTh[2] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> orientation==h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation jj h[2] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> orientation==h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation; 14 for i=0;i < 3;i++ f CU ASSERTh[2] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[i]==h[0] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> theta[i] jj h[2] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[i]==h[1] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> theta[i]; g 15 for i=0;i < 3;i++ f CU ASSERT DOUBLE EQUALh[2] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[i], double i,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; g 16 for i=0;i < 3;i++ f dHamiltonianParametersDestroyh[i]; g 17 return ; 18 error2: 19 dHamiltonianParametersDestroyh[1]; 20 dHamiltonianParametersDestroyh[0]; 21 CU FAIL"Mate fail"; 22 return ; 23 error1: PAGE 183 162 24 dHamiltonianParametersDestroyh[0]; 25 error0: 26 CU FAIL"Setup failed"; 27 return ; 28 g PAGE 184 163 FunctionB.0.4 unit dHamiltonianParametersMateSPC ListingB.4: hf.c:unit dHamiltonianParametersMateSPC 1 void unit dHamiltonianParametersMateSPC void 2 f 3 dHamiltonianParameters h[3]; 4 double eigenvalues[3]= f 0,1,2 g ; 5 unsignedlonglong i; 6 7 if h[0]=dHamiltonianParametersRandom1,eigenvalues==NULL goto error0; 8 if h[1]=dHamiltonianParametersRandom1,eigenvalues==NULL goto error1; 9 h[2]=dHamiltonianParametersMateSPCh[0],h[1]; 10 CU ASSERT PTR NOT NULLh[2]; 11 if h[2]==NULL goto error2; 12 CU ASSERTh[2] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> J==1; 13 CU ASSERTh[2] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> orientation==h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation jj h[2] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> orientation==h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation; 14 for i=0;i < 3;i++ f CU ASSERTh[2] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[i]==h[0] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> theta[i] jj h[2] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[i]==h[1] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> theta[i]; g 15 for i=0;i < 3;i++ f CU ASSERT DOUBLE EQUALh[2] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[i], double i,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; g 16 for i=0;i < 3;i++ f dHamiltonianParametersDestroyh[i]; g 17 return ; 18 error2: 19 dHamiltonianParametersDestroyh[1]; 20 dHamiltonianParametersDestroyh[0]; 21 CU FAIL"Mate fail"; 22 return ; 23 error1: PAGE 185 164 24 dHamiltonianParametersDestroyh[0]; 25 error0: 26 CU FAIL"Setup failed"; 27 return ; 28 g PAGE 186 165 FunctionB.0.5 unit dHamiltonianParametersCPUComputeArray ListingB.5: hf.c:unit dHamiltonianParametersCPUComputeArray 1 void unit dHamiltonianParametersCPUComputeArray void 2 f 3 dHamiltonianParameters h; 4 double H[9],Vec[9]; 5 double H2[25],Vec2[25]; 6 //doubleeigenvalues[3]= f 13254.0,12806.9, 16530.7 g ; 7 double eigenvalues[3]= f 16530.7,13254.0, 12806.9 g ; 8 double eigenvalues2[5]= f 49634.9,46762.5, 45421.3,35591.1,35548.4 g ; 9 int rc; 10 11 h=dHamiltonianParametersCreate1,eigenvalues; 12 if h==NULL goto error0; 13 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[0]=5.0 PI/4.0; 14 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[1]=PI; 15 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[2]=3 PI/2.0; 16 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation=0; 17 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation=0; 18 CU ASSERTrc=dHamiltonianParametersCPUComputeArrayh,H,Vec ==0; 19 if rc!=0 goto error1; 20 //dPrintMatrix"H",3,3,H,3; 21 //dPrintMatrix"Vec",3,3,Vec,3; 22 CU ASSERT DOUBLE EQUALH[0],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 23 CU ASSERT DOUBLE EQUALH[1],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 24 CU ASSERT DOUBLE EQUALH[2],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; PAGE 187 166 25 CU ASSERT DOUBLE EQUALH[3],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 26 CU ASSERT DOUBLE EQUALH[4],1.280690e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 27 CU ASSERT DOUBLE EQUALH[5],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 28 CU ASSERT DOUBLE EQUALH[6],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 29 CU ASSERT DOUBLE EQUALH[7],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 30 CU ASSERT DOUBLE EQUALH[8],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 31 CU ASSERT DOUBLE EQUALVec[0],7.071068e )]TJ/F18 9.9626 Tf 8.32 0 Td [(01,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(7; 32 CU ASSERT DOUBLE EQUALVec[1],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 33 CU ASSERT DOUBLE EQUALVec[2],7.071068e )]TJ/F18 9.9626 Tf 8.32 0 Td [(01,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(7; 34 CU ASSERT DOUBLE EQUALVec[3], )]TJ/F18 9.9626 Tf 8.513 0 Td [(7.071068e )]TJ/F18 9.9626 Tf 8.321 0 Td [(01,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(7; 35 CU ASSERT DOUBLE EQUALVec[4],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 36 CU ASSERT DOUBLE EQUALVec[5],7.071068e )]TJ/F18 9.9626 Tf 8.32 0 Td [(01,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(7; 37 CU ASSERT DOUBLE EQUALVec[6],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 38 CU ASSERT DOUBLE EQUALVec[7], )]TJ/F18 9.9626 Tf 8.154 0 Td [(1,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 39 CU ASSERT DOUBLE EQUALVec[8],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 40 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation=1; 41 CU ASSERTrc=dHamiltonianParametersCPUComputeArrayh,H,Vec ==0; 42 if rc!=0 goto error1; 43 //dPrintMatrix"H",3,3,H,3; 44 CU ASSERT DOUBLE EQUALH[0],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 45 CU ASSERT DOUBLE EQUALH[1],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 46 CU ASSERT DOUBLE EQUALH[2],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 47 CU ASSERT DOUBLE EQUALH[3],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 48 CU ASSERT DOUBLE EQUALH[4],1.280690e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 49 CU ASSERT DOUBLE EQUALH[5],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 50 CU ASSERT DOUBLE EQUALH[6],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 51 CU ASSERT DOUBLE EQUALH[7],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 52 CU ASSERT DOUBLE EQUALH[8],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 53 PAGE 188 167 54 dHamiltonianParametersDestroyh; 55 h=dHamiltonianParametersCreate2,eigenvalues2; 56 if h==NULL goto error0; 57 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[0]=6.014661; 58 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[1]=1.591151; 59 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[2]=4.643043; 60 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[3]=4.804916; 61 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[4]=0.4085940; 62 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[5]=5.847415; 63 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[6]=2.822937; 64 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[7]=3.442965; 65 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[8]=4.834847; 66 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[9]=4.200063; 67 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation=0; 68 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation=0; 69 CU ASSERTrc=dHamiltonianParametersCPUComputeArrayh,H2, Vec2==0; 70 if rc!=0 goto error1; 71 //dPrintMatrix"H2",5,5,H2,5; 72 //dPrintMatrix"Vec2",5,5,Vec2,5; 73 CU ASSERT DOUBLE EQUALH2[0],4.592370e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 74 CU ASSERT DOUBLE EQUALH2[1], )]TJ/F18 9.9626 Tf 8.513 0 Td [(1.826792e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 75 CU ASSERT DOUBLE EQUALH2[2], )]TJ/F18 9.9626 Tf 8.513 0 Td [(5.311851e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 76 CU ASSERT DOUBLE EQUALH2[3],1.128238e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 77 CU ASSERT DOUBLE EQUALH2[4],4.952531e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 78 CU ASSERT DOUBLE EQUALH2[5], )]TJ/F18 9.9626 Tf 8.513 0 Td [(1.826792e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 79 CU ASSERT DOUBLE EQUALH2[6],3.565272e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 80 CU ASSERT DOUBLE EQUALH2[7], )]TJ/F18 9.9626 Tf 8.513 0 Td [(5.069754e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 81 CU ASSERT DOUBLE EQUALH2[8], )]TJ/F18 9.9626 Tf 8.513 0 Td [(1.847574e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 82 CU ASSERT DOUBLE EQUALH2[9], )]TJ/F18 9.9626 Tf 8.513 0 Td [(6.093458e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; PAGE 189 168 83 dHamiltonianParametersDestroyh; 84 return ; 85 error1: 86 CU FAIL"Second call of dHamiltonianParametersCPUComputeArray failed"; 87 dHamiltonianParametersDestroyh; 88 error0: 89 return ; 90 g PAGE 190 169 FunctionB.0.6 unit dHamiltonianParametersDestroy ListingB.6: hf.c:unit dHamiltonianParametersDestroy 1 void unit dHamiltonianParametersDestroy void 2 f 3 dHamiltonianParameters h; 4 int rc; 5 struct mallinfomi[2]; 6 double eigenvalues[3]= f 0,1,2 g ; 7 8 mi[0]=mallinfo; 9 h=dHamiltonianParametersRandom1,eigenvalues; 10 CU ASSERT PTR NOT NULL FATALh; 11 CU ASSERTrc=dHamiltonianParametersDestroyh==0; 12 mi[1]=mallinfo; 13 CU ASSERTmi[0].uordblks==mi[1].uordblks; 14 return ; 15 g PAGE 191 170 FunctionB.0.7 unit findDiagonal ListingB.7: hf.c:unit findDiagonal 1 void unit findDiagonal void 2 f 3 unsignedlong m; 4 5 m=findDiagonal0,5,8; 6 CU ASSERTm==3; 7 if m!=3fprintfstderr,"findDiagonal0, 5, 8 = %ld n n",m; 8 m=findDiagonal0,5,1; 9 CU ASSERTm==0; 10 if m!=0fprintfstderr,"findDiagonal0, 5, 1 = %ld n n",m; 11 m=findDiagonal0,5,2; 12 CU ASSERTm==1; 13 if m!=1fprintfstderr,"findDiagonal0, 5, 2 = %ld n n",m; 14 m=findDiagonal0,5,3; 15 CU ASSERTm==1; 16 if m!=1fprintfstderr,"findDiagonal0, 5, 3 = %ld n n",m; 17 m=findDiagonal0,5,4; 18 CU ASSERTm==2; 19 if m!=2fprintfstderr,"findDiagonal0, 5, 4 = %ld n n",m; 20 m=findDiagonal0,5,5; 21 CU ASSERTm==2; 22 if m!=2fprintfstderr,"findDiagonal0, 5, 5 = %ld n n",m; 23 m=findDiagonal0,5,6; 24 CU ASSERTm==2; 25 if m!=2fprintfstderr,"findDiagonal0, 5, 6 = %ld n n",m; 26 m=findDiagonal0,5,7; 27 CU ASSERTm==3; 28 if m!=3fprintfstderr,"findDiagonal0, 5, 7 = %ld n n",m; PAGE 192 171 29 return ; 30 g PAGE 193 172 FunctionB.0.8 unit findPlane ListingB.8: hf.c:unit findPlane 1 void unit findPlane void 2 f 3 unsignedlonglong x,y; 4 int rc; 5 6 rc=findPlane3,1,&x,&y; 7 CU ASSERTrc==0; 8 CU ASSERTx==1; 9 CU ASSERTy==3; 10 if x!=1 jj y!=3printf"expected 1, 3, got %lld, %lld n n ",x,y; 11 12 rc=findPlane3,2,&x,&y; 13 CU ASSERTrc==0; 14 CU ASSERTx==1; 15 CU ASSERTy==2; 16 if x!=1 jj y!=2printf"expected 1, 2, got %lld, %lld n n ",x,y; 17 18 rc=findPlane3,3,&x,&y; 19 CU ASSERTrc==0; 20 CU ASSERTx==2; 21 CU ASSERTy==3; 22 if x!=2 jj y!=3printf"expected 2, 3, got %lld, %lld n n ",x,y; 23 24 rc=findPlane5,1,&x,&y; 25 CU ASSERTrc==0; PAGE 194 173 26 CU ASSERTx==1; 27 CU ASSERTy==5; 28 29 rc=findPlane5,2,&x,&y; 30 CU ASSERTrc==0; 31 CU ASSERTx==1; 32 CU ASSERTy==4; 33 34 rc=findPlane5,3,&x,&y; 35 CU ASSERTrc==0; 36 CU ASSERTx==2; 37 CU ASSERTy==5; 38 39 rc=findPlane5,4,&x,&y; 40 CU ASSERTrc==0; 41 CU ASSERTx==1; 42 CU ASSERTy==3; 43 44 rc=findPlane5,5,&x,&y; 45 CU ASSERTrc==0; 46 CU ASSERTx==2; 47 CU ASSERTy==4; 48 49 rc=findPlane5,6,&x,&y; 50 CU ASSERTrc==0; 51 CU ASSERTx==3; 52 CU ASSERTy==5; 53 54 rc=findPlane5,7,&x,&y; 55 CU ASSERTrc==0; PAGE 195 174 56 CU ASSERTx==1; 57 CU ASSERTy==2; 58 59 rc=findPlane5,8,&x,&y; 60 CU ASSERTrc==0; 61 CU ASSERTx==2; 62 CU ASSERTy==3; 63 64 rc=findPlane5,9,&x,&y; 65 CU ASSERTrc==0; 66 CU ASSERTx==3; 67 CU ASSERTy==4; 68 69 rc=findPlane5,10,&x,&y; 70 CU ASSERTrc==0; 71 CU ASSERTx==4; 72 CU ASSERTy==5; 73 74 return ; 75 g PAGE 196 175 FunctionB.0.9 unit h3Fit ListingB.9: hf.c:unit h3Fit 1 void unit h3Fit void 2 f 3 dHamiltonianParameters h; 4 double H[9],H2[9],r; 5 double x[3]; 6 double eigenvalues[3]= f 13254.0,12860.9, 16530.7 g ; 7 8 h=dHamiltonianParametersCreate1,eigenvalues; 9 if h==NULL goto error0; 10 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[0]=3.0 PI/4.0; 11 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[1]=0.0; 12 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[2]=PI; 13 //h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[0]=13254.0; 14 //h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[1]=12806.9; 15 //h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> lambda[2]=16530.7; 16 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation=0; 17 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation=0; 18 dHamiltonianParametersCPUComputeArrayh,H,NULL; 19 dHamiltonianParametersDestroyh; 20 h3FitH,x,H2,&r; 21 //dPrintMatrix"H",3,3,H,3; 22 //dPrintMatrix"X",3,1,x,3; 23 //dPrintMatrix"H2",3,3,H2,3; 24 CU ASSERT DOUBLE EQUALx[0],8.4619e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 25 CU ASSERT DOUBLE EQUALx[1],8.0688e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 26 CU ASSERT DOUBLE EQUALx[2],4.7921e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 27 CU ASSERT DOUBLE EQUALH2[0],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; PAGE 197 176 28 CU ASSERT DOUBLE EQUALH2[1],0,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 29 CU ASSERT DOUBLE EQUALH2[2],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 30 CU ASSERT DOUBLE EQUALH2[3],0,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 31 CU ASSERT DOUBLE EQUALH2[4],1.286090e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 32 CU ASSERT DOUBLE EQUALH2[5],0,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 33 CU ASSERT DOUBLE EQUALH2[6],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 34 CU ASSERT DOUBLE EQUALH2[7],0,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 35 CU ASSERT DOUBLE EQUALH2[8],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 36 CU ASSERT DOUBLE EQUALr,6.365704e )]TJ/F18 9.9626 Tf 8.321 0 Td [(12,1e )]TJ/F18 9.9626 Tf 8.214 0 Td [(17 37 return ; 38 39 error0: 40 CU FAIL"setup failure"; 41 return ; 42 g PAGE 198 177 FunctionB.0.10 unit generateRegressionCoefficients ListingB.10: unit generateRegressionCoefficients 1 void unit generateRegressionCoefficients void 2 f 3 double R; 4 double A[9 8]= f 1,0,0,0,0,0,0,0,1, 5 .5,0,.5,0,1,0,.5,0,.5, 6 .5,0, )]TJ/F18 9.9626 Tf 8.556 0 Td [(.5,0,1,0, )]TJ/F18 9.9626 Tf 8.556 0 Td [(.5,0,.5, 7 )]TJ/F18 9.9626 Tf 8.154 0 Td [(4,0,0,0, )]TJ/F18 9.9626 Tf 8.155 0 Td [(4,0,0,0, )]TJ/F18 9.9626 Tf 8.155 0 Td [(4, 8 )]TJ/F18 9.9626 Tf 8.154 0 Td [(2,0,0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(2, 9 )]TJ/F18 9.9626 Tf 8.154 0 Td [(1,0,0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(1, 10 0,0, )]TJ/F18 9.9626 Tf 8.155 0 Td [(4,0,0,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(4,0,0, 11 0,0, )]TJ/F18 9.9626 Tf 8.155 0 Td [(2,0,0,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(2,0,0 g ; 12 unsignedlonglong i; 13 struct mallinfomi[2]; 14 15 mi[0]=mallinfo; 16 double B[25 8]= f 17 4.0,0,0,0,0,0,1.0,0,0,0,0,0,0,0,0,0,0,0,1.0, 0,0,0,0,0,4.0, 18 1.0,0,1.22474487,0,0,0,2.5,0,1.5,0,1.22474487,0,3.0, 0,1.22474487,0,1.5,0,2.5,0,0,0,1.22474487,0,1.0, 19 1.0,0, )]TJ/F18 9.9626 Tf 8.657 0 Td [(1.22474487,0,0,0,2.5,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.5,0, )]TJ/F18 9.9626 Tf 8.656 0 Td [(1.22474487,0, 3.0,0, )]TJ/F18 9.9626 Tf 8.656 0 Td [(1.22474487,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.5,0,2.5,0,0,0, )]TJ/F18 9.9626 Tf 8.656 0 Td [(1.22474487, 0,1.0, 20 )]TJ/F18 9.9626 Tf 8.598 0 Td [(36.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(36.,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.597 0 Td [(36.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.598 0 Td [(36.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.598 0 Td [(36.0, 21 )]TJ/F18 9.9626 Tf 8.598 0 Td [(24.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(6.0,0,0,0,0,0,0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(6.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.598 0 Td [(24.0, 22 )]TJ/F18 9.9626 Tf 8.598 0 Td [(16.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.0,0,0,0,0,0,0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.598 0 Td [(16.0, PAGE 199 178 23 0,0, )]TJ/F18 9.9626 Tf 8.657 0 Td [(29.3938769,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.598 0 Td [(36.0,0, )]TJ/F18 9.9626 Tf 8.656 0 Td [(29.3938769,0,0, 0, )]TJ/F18 9.9626 Tf 8.656 0 Td [(29.3938769,0, )]TJ/F18 9.9626 Tf 8.597 0 Td [(36.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.657 0 Td [(29.3938769,0,0, 24 0,0, )]TJ/F18 9.9626 Tf 8.643 0 Td [(9.797959,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(6.0,0, )]TJ/F18 9.9626 Tf 8.642 0 Td [(9.797959,0,0,0, )]TJ/F18 9.9626 Tf 8.643 0 Td [(9.797959,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(6.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.643 0 Td [(9.797959,0,0 25 g ; 26 27 R=generateRegressionCoefficients1; 28 CU ASSERT PTR NOT NULLR; 29 if R==NULL goto error0; 30 //dPrintMatrix"R",9,8,R,9; 31 for i=0;i < 27;i++ f 32 CU ASSERT DOUBLE EQUALR[i],A[i],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 33 g 34 freeR; 35 mi[1]=mallinfo; 36 CU ASSERTmi[0].uordblks==mi[1].uordblks; 37 R=generateRegressionCoefficients2; 38 CU ASSERT PTR NOT NULLR; 39 if R==NULL goto error0; 40 for i=0;i < 200;i++ f 41 CU ASSERT DOUBLE EQUALR[i],B[i],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 42 g 43 //dPrintMatrix"R",25,8,R,25; 44 //dPrintMatrix"B",25,8,B,25; 45 freeR; 46 mi[1]=mallinfo; 47 CU ASSERTmi[0].uordblks==mi[1].uordblks; 48 return ; 49 error0: 50 return ; 51 g PAGE 200 179 FunctionB.0.11 unit generateStitchedCoefficients ListingB.11: hf.c:unit generateStitchedCoefficients 1 void unit generateStitchedCoefficients void 2 f 3 unsignedlonglong i; 4 double R; 5 double A[34 8]= f 6 1,0,0,0,0,0,0,0,1,4.0,0,0,0,0,0,1.0,0,0,0,0, 0,0,0,0,0,0,0,1.0,0,0,0,0,0,4.0, 7 .5,0,.5,0,1,0,.5,0,.5,1.0,0,1.22474487,0,0,0,2.5, 0,1.5,0,1.22474487,0,3.0,0,1.22474487,0,1.5,0, 2.5,0,0,0,1.22474487,0,1.0, 8 .5,0, )]TJ/F18 9.9626 Tf 8.556 0 Td [(.5,0,1,0, )]TJ/F18 9.9626 Tf 8.556 0 Td [(.5,0,.5,1.0,0, )]TJ/F18 9.9626 Tf 8.656 0 Td [(1.22474487,0,0,0, 2.5,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.5,0, )]TJ/F18 9.9626 Tf 8.656 0 Td [(1.22474487,0,3.0,0, )]TJ/F18 9.9626 Tf 8.657 0 Td [(1.22474487,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.5,0,2.5,0,0,0, )]TJ/F18 9.9626 Tf 8.657 0 Td [(1.22474487,0,1.0, 9 )]TJ/F18 9.9626 Tf 8.155 0 Td [(4,0,0,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(4,0,0,0, )]TJ/F18 9.9626 Tf 8.155 0 Td [(4, )]TJ/F18 9.9626 Tf 8.598 0 Td [(36.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(36.,0,0, 0,0,0, )]TJ/F18 9.9626 Tf 8.597 0 Td [(36.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.597 0 Td [(36.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.597 0 Td [(36.0, 10 )]TJ/F18 9.9626 Tf 8.154 0 Td [(2,0,0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.468 0 Td [(2, )]TJ/F18 9.9626 Tf 8.469 0 Td [(24.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(6.0,0,0,0, 0,0,0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(6.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.598 0 Td [(24.0, 11 )]TJ/F18 9.9626 Tf 8.154 0 Td [(1,0,0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(1, )]TJ/F18 9.9626 Tf 8.597 0 Td [(16.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.0,0,0, 0,0,0,0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.0,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.598 0 Td [(16.0, 12 0,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(4,0,0,0, )]TJ/F18 9.9626 Tf 8.155 0 Td [(4,0,0,0,0, )]TJ/F18 9.9626 Tf 8.656 0 Td [(29.3938769,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.597 0 Td [(36.0,0, )]TJ/F18 9.9626 Tf 8.657 0 Td [(29.3938769,0,0,0, )]TJ/F18 9.9626 Tf 8.657 0 Td [(29.3938769,0, )]TJ/F18 9.9626 Tf 8.597 0 Td [(36.0,0,0, 0,0,0, )]TJ/F18 9.9626 Tf 8.657 0 Td [(29.3938769,0,0, 13 0,0, )]TJ/F18 9.9626 Tf 8.154 0 Td [(2,0,0,0, )]TJ/F18 9.9626 Tf 8.155 0 Td [(2,0,0,0,0, )]TJ/F18 9.9626 Tf 8.643 0 Td [(9.797959,0,0,0,0,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(6.0,0, )]TJ/F18 9.9626 Tf 8.643 0 Td [(9.797959,0,0,0, )]TJ/F18 9.9626 Tf 8.643 0 Td [(9.797959,0, )]TJ/F18 9.9626 Tf 8.579 0 Td [(6.0,0,0,0,0, 0, )]TJ/F18 9.9626 Tf 8.643 0 Td [(9.797959,0,0 14 g ; 15 struct mallinfomi[2]; 16 PAGE 201 180 17 mi[0]=mallinfo; 18 R=generateStitchedCoefficients1,2; 19 CU ASSERT PTR NOT NULLR; 20 if R==NULL goto error0; 21 for i=0;i < 34 8;i++ f 22 CU ASSERT DOUBLE EQUALR[i],A[i],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 23 g 24 freeR; 25 mi[1]=mallinfo; 26 CU ASSERTmi[0].uordblks==mi[1].uordblks; 27 return ; 28 error0: 29 return ; 30 g PAGE 202 181 FunctionB.0.12 unit dHamiltonianFit ListingB.12: hf.c:unit dHamiltonianFit 1 void unit dHamiltonianFit void 2 f 3 dHamiltonianParameters h1, h2; 4 double EV1[3]= f 16530.7,13254.0,12806.9 g ; 5 //doubleEV1[3]= f 13254.0,12806.9,16530.7 g ; 6 double EV2[5]= f 49634.9,46762.5,45421.3, 35591.1,35548.4 g ; 7 double X[8]= f 0,0,0,0,0,0,0,0 g ; 8 double r, H, H2; 9 int rc; 10 11 if H2= double malloc sizeof double 2==NULL goto error0; 12 if H2[0]= double calloc9, sizeof double ==NULL goto error1; 13 if H2[1]= double calloc25, sizeof double ==NULL goto error2; 14 if H= double malloc sizeof double 2==NULL goto error3; 15 if H[0]= double calloc9, sizeof double ==NULL goto error4; 16 if H[1]= double calloc25, sizeof double ==NULL goto error5; 17 h1=dHamiltonianParametersCreate1,EV1; 18 if h1==NULL goto error6; 19 h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[0]=3.0 PI/4.0; 20 h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[1]=0.0; 21 h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[2]=PI; PAGE 203 182 22 h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> orientation=0; 23 h1 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> eigenPermutation=3; 24 h2=dHamiltonianParametersCreate2,EV2; 25 if h2==NULL goto error7; 26 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[0]=6.014661; 27 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[1]=1.591151; 28 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[2]=4.643043; 29 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[3]=4.804916; 30 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[4]=0.4085940; 31 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[5]=5.847415; 32 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[6]=2.822937; 33 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[7]=3.442965; 34 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[8]=4.834847; 35 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> theta[9]=4.200063; 36 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> orientation=0; 37 h2 )]TJ/F11 9.9626 Tf 5.977 0 Td [(> eigenPermutation=0; 38 CU ASSERTrc=dHamiltonianParametersCPUComputeArrayh1,H[0], NULL==0; 39 CU ASSERTrc=dHamiltonianParametersCPUComputeArrayh2,H[1], NULL==0; 40 //dPrintMatrix"H[0]",3,3,H[0],3; 41 //dPrintMatrix"H[1]",5,5,H[1],5; 42 CU ASSERTrc=dHamiltonianFit1,2,H,X,H2,&r==0; 43 //Tests 44 //dPrintMatrix"X",8,1,X,8; 45 46 dHamiltonianParametersDestroyh2; 47 dHamiltonianParametersDestroyh1; 48 freeH[1]; 49 freeH[0]; PAGE 204 183 50 freeH; 51 freeH2[0]; 52 freeH2[1]; 53 freeH2; 54 return ; 55 56 dHamiltonianParametersDestroyh2; 57 error7: 58 dHamiltonianParametersDestroyh1; 59 error6: 60 freeH[1]; 61 error5: 62 freeH[0]; 63 error4: 64 freeH; 65 error3: 66 freeH2[1]; 67 error2: 68 freeH2[0]; 69 error1: 70 freeH2; 71 error0: 72 CU FAIL"Setup failure"; 73 return ; 74 g PAGE 205 AppendixC hfGPU.c TestPlans FunctionC.0.13 unit dHamiltonianParametersGPUComputeArray ListingC.1: hfGPU.cu:unit dHamiltonianParametersGPUComputeArray 1 extern "C" void unit dHamiltonianParametersGPUComputeArray void 2 f 3 dHamiltonianParameters h; 4 double H[9],Vec[9]; 5 double H2[25],Vec2[25]; 6 double eigenvalues[3]= f 13254.0,12806.9, 16530.7 g ; 7 double eigenvalues2[5]= f 49634.9,46762.5, 45421.3,35591.1,35548.4 g ; 8 int rc; 9 size tfreeMem[2],total; 10 11 h=dHamiltonianParametersCreate1,eigenvalues; 12 if h==NULL goto error0; 13 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[0]=3.0 PI/4.0; 14 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[1]=0; 184 PAGE 206 185 15 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[2]=PI; 16 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation=0; 17 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation=0; 18 cudaMemGetInfo&freeMem[0],&total; 19 //printf"total=%u,free=%u n n",unsignedtotal,unsigned freeMem; 20 CU ASSERTrc=dHamiltonianParametersGPUComputeArray0,h,H, Vec==0; 21 cudaMemGetInfo&freeMem[1],&total; 22 CU ASSERTfreeMem[0]==freeMem[1]; 23 if freeMem[0]!=freeMem[1]printf" n n Lost %lu bytes of device memory n n", unsignedlong freeMem[0] )]TJ/F18 9.9626 Tf 9.212 0 Td [(freeMem[1]; 24 if rc!=0 goto error1; 25 //dPrintMatrix"H",3,3,H,3; 26 //dPrintMatrix"Vec",3,3,Vec,3; 27 CU ASSERT DOUBLE EQUALH[0],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 28 CU ASSERT DOUBLE EQUALH[1],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 29 CU ASSERT DOUBLE EQUALH[2],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 30 CU ASSERT DOUBLE EQUALH[3],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 31 CU ASSERT DOUBLE EQUALH[4],1.280690e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 32 CU ASSERT DOUBLE EQUALH[5],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 33 CU ASSERT DOUBLE EQUALH[6],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 34 CU ASSERT DOUBLE EQUALH[7],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 35 CU ASSERT DOUBLE EQUALH[8],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 36 CU ASSERT DOUBLE EQUALVec[0], )]TJ/F18 9.9626 Tf 8.513 0 Td [(7.071068e )]TJ/F18 9.9626 Tf 8.321 0 Td [(01,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(7; 37 CU ASSERT DOUBLE EQUALVec[1],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 38 CU ASSERT DOUBLE EQUALVec[2],7.071068e )]TJ/F18 9.9626 Tf 8.32 0 Td [(01,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(7; 39 CU ASSERT DOUBLE EQUALVec[3],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 40 CU ASSERT DOUBLE EQUALVec[4], )]TJ/F18 9.9626 Tf 8.154 0 Td [(1,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 41 CU ASSERT DOUBLE EQUALVec[5],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; PAGE 207 186 42 CU ASSERT DOUBLE EQUALVec[6],7.071068e )]TJ/F18 9.9626 Tf 8.32 0 Td [(01,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(7; 43 CU ASSERT DOUBLE EQUALVec[7],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 44 CU ASSERT DOUBLE EQUALVec[8],7.071068e )]TJ/F18 9.9626 Tf 8.32 0 Td [(01,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(7; 45 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation=1; 46 CU ASSERTrc=dHamiltonianParametersGPUComputeArray0,h,H, Vec==0; 47 if rc!=0 goto error1; 48 //dPrintMatrix"H",3,3,H,3; 49 CU ASSERT DOUBLE EQUALH[0],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 50 CU ASSERT DOUBLE EQUALH[1],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 51 CU ASSERT DOUBLE EQUALH[2],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 52 CU ASSERT DOUBLE EQUALH[3],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 53 CU ASSERT DOUBLE EQUALH[4],1.280690e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 54 CU ASSERT DOUBLE EQUALH[5],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 55 CU ASSERT DOUBLE EQUALH[6],1.638350e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 56 CU ASSERT DOUBLE EQUALH[7],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 57 CU ASSERT DOUBLE EQUALH[8],1.489235e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 58 59 dHamiltonianParametersDestroyh; 60 h=dHamiltonianParametersCreate2,eigenvalues2; 61 if h==NULL goto error0; 62 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[0]=6.014661; 63 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[1]=1.591151; 64 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[2]=4.643043; 65 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[3]=4.804916; 66 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[4]=0.4085940; 67 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[5]=5.847415; 68 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[6]=2.822937; 69 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[7]=3.442965; 70 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[8]=4.834847; PAGE 208 187 71 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> theta[9]=4.200063; 72 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> orientation=0; 73 h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> eigenPermutation=0; 74 CU ASSERTrc=dHamiltonianParametersGPUComputeArray0,h,H2, Vec2==0; 75 if rc!=0 goto error1; 76 //dPrintMatrix"H2",5,5,H2,5; 77 //dPrintMatrix"Vec2",5,5,Vec2,5; 78 CU ASSERT DOUBLE EQUALH2[0],4.592370e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 79 CU ASSERT DOUBLE EQUALH2[1], )]TJ/F18 9.9626 Tf 8.513 0 Td [(1.826792e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 80 CU ASSERT DOUBLE EQUALH2[2], )]TJ/F18 9.9626 Tf 8.513 0 Td [(5.311851e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 81 CU ASSERT DOUBLE EQUALH2[3],1.128238e+03,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 82 CU ASSERT DOUBLE EQUALH2[4],4.952531e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 83 CU ASSERT DOUBLE EQUALH2[5], )]TJ/F18 9.9626 Tf 8.513 0 Td [(1.826792e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 84 CU ASSERT DOUBLE EQUALH2[6],3.565272e+04,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 85 CU ASSERT DOUBLE EQUALH2[7], )]TJ/F18 9.9626 Tf 8.513 0 Td [(5.069754e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 86 CU ASSERT DOUBLE EQUALH2[8], )]TJ/F18 9.9626 Tf 8.513 0 Td [(1.847574e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 87 CU ASSERT DOUBLE EQUALH2[9], )]TJ/F18 9.9626 Tf 8.513 0 Td [(6.093458e+02,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(4; 88 dHamiltonianParametersDestroyh; 89 return ; 90 error1: 91 CU FAIL"Second call of dHamiltonianParametersComputeArray failed"; 92 dHamiltonianParametersDestroyh; 93 error0: 94 return ; 95 g PAGE 209 AppendixD jga.c TestPlans Thetestplansforthe jgaPopulation areincludedhere. FunctionD.0.14 unit jgaPopulationCreate ListingD.1: jga.c:unit jgaPopulationCreate 1 void unit jgaPopulationCreate void 2 f 3 jgaPopulation p; 4 double lambda; 5 double HA[2], H2A[2],X[9],r; 6 double HJ1[9],HJ2[25],H2J1[9],H2J2[25]; 7 unsignedlonglong i; 8 9 HA[0]=HJ1;HA[1]=HJ2;H2A[0]=H2J1;H2A[1]=H2J2; 10 if lambda=malloc sizeof double 2==NULL goto error0; 11 if lambda[0]=malloc sizeof double 3==NULL goto error1; 12 if lambda[1]=malloc sizeof double 5==NULL goto error2; 13 lambda[0][0]=16530.7; 14 lambda[0][1]=13254.0; 188 PAGE 210 189 15 lambda[0][2]=12806.9; 16 lambda[1][0]=49634.9; 17 lambda[1][1]=46762.5; 18 lambda[1][2]=45421.3; 19 lambda[1][3]=35591.1; 20 lambda[1][4]=35548.4; 21 CU ASSERT PTR NOT NULLp=jgaPopulationCreate1,2,3,lambda, 1; 22 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[0][0],lambda[0][0],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 23 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[0][1],lambda[0][1],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 24 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[0][2],lambda[0][2],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 25 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[1][0],lambda[1][0],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 26 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[1][1],lambda[1][1],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 27 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[1][2],lambda[1][2],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 28 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[1][3],lambda[1][3],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 29 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> lambda[1][4],lambda[1][4],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 30 CU ASSERT PTR NOT NULLp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e; 31 if p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e==NULL goto error4; 32 if p==0 goto error3; 33 for i=0;i < 3;i++ f 34 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[0] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[0],lambda [0][0],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 35 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[0] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[1],lambda [0][1],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 36 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[0] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[2],lambda [0][2],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 37 CU ASSERTp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation==0 jj p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation==1; 38 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[1] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[0],lambda [1][0],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; PAGE 211 190 39 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[1] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[1],lambda [1][1],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 40 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[1] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[2],lambda [1][2],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 41 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[1] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[3],lambda [1][3],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 42 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[1] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> lambda[4],lambda [1][4],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 43 CU ASSERTp )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation==0 jj p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation==1; 44 dHamiltonianParametersComputeArray0,p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[0],HA[0], NULL; 45 dHamiltonianParametersComputeArray0,p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[i].h[1],HA[1], NULL; 46 dHamiltonianFit1,2,HA,X,H2A,&r; 47 CU ASSERTX[0] > =X[1]&&X[1] > =X[2]; 48 g 49 jgaPopulationDestroyp; 50 freelambda[0]; 51 freelambda[1]; 52 freelambda; 53 return ; 54 error4: 55 jgaPopulationDestroyp; 56 error3: 57 freelambda[1]; 58 error2: 59 freelambda[0]; 60 error1: 61 freelambda; PAGE 212 191 62 error0: 63 CU FAIL"setup error"; 64 return ; 65 g PAGE 213 192 FunctionD.0.15 unit jgaPopulationScore ListingD.2: jga.c:unit jgaPopulationScore 1 void unit jgaPopulationScore void 2 f 3 jgaPopulation p; 4 double lambda[2]; 5 double lambda0[3]= f 16530.7,13254.,12806.9 g ; 6 double lambda1[5]= f 49634.9,46762.5,45421.3, 35591.1,35548.4 g ; 7 int rc; 8 unsignedlonglong i; 9 10 lambda[0]=lambda0;lambda[1]=lambda1; 11 12 if p=jgaPopulationCreate1,2,1,lambda,1==NULL goto error0; 13 for i=0;i < 3;i++ f p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[0] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> theta[i]=PI; g 14 for i=0;i < 10;i++ f p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.717 0 Td [(> theta[i]=PI; g 15 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation=0; 16 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> orientation=0; 17 CU ASSERTrc=jgaPopulationScorep,1==0; 18 if rc!=0 goto error1; 19 CU ASSERT DOUBLE EQUALp )]TJ/F11 9.9626 Tf 5.977 0 Td [(> e[0].fitness,0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6 20 jgaPopulationDestroyp; 21 return ; 22 error1: 23 jgaPopulationDestroyp; 24 error0: 25 CU FAIL"Setup failure"; 26 return ; 27 g PAGE 214 193 FunctionD.0.16 unit jgaPopulationVariance ListingD.3: jga.c:unit jgaPopulationVariance 1 void unit jgaPopulationVariance void 2 f 3 jgaPopulation p; 4 double lambda[2]; 5 double lambda0[3]= f 16530.7,13254.,12806.9 g ; 6 double lambda1[5]= f 49634.9,46762.5,45421.3, 35591.1,35548.4 g ; 7 double v; 8 9 lambda[0]=lambda0;lambda[1]=lambda1; 10 if p=jgaPopulationCreate1,2,3,lambda,1==NULL goto error0; 11 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[0]=1; 12 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[0]=2; 13 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[0]=3; 14 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[1]=4; 15 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[1]=5; 16 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[1]=6; 17 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[2]=7; 18 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[2]=8; 19 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[0] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[2]=9; 20 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[0]=10; 21 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[0]=11; 22 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[0]=12; 23 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[1]=13; 24 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[1]=14; 25 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[1]=15; 26 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[2]=16; PAGE 215 194 27 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[2]=17; 28 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[2]=18; 29 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[3]=19; 30 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[3]=20; 31 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[3]=21; 32 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[4]=22; 33 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[4]=23; 34 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[4]=24; 35 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[5]=25; 36 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[5]=26; 37 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[5]=27; 38 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[6]=28; 39 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[6]=29; 40 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[6]=30; 41 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[7]=31; 42 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[7]=32; 43 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[7]=33; 44 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[8]=34; 45 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[8]=35; 46 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[8]=36; 47 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[0].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[9]=37; 48 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[1].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[9]=38; 49 p )]TJ/F11 9.9626 Tf 5.978 0 Td [(> e[2].h[1] )]TJ/F11 9.9626 Tf 8.718 0 Td [(> theta[9]=39; 50 v=jgaPopulationVariancep; 51 CU ASSERT DOUBLE EQUALv,1,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(5; 52 jgaPopulationDestroyp; 53 error0: 54 CU FAIL"setup failure"; 55 56 g PAGE 216 195 FunctionD.0.17 unit jgaPopulationDestroy ListingD.4: jga.c:unit jgaPopulationDestroy 1 void unit jgaPopulationDestroy void 2 f 3 jgaPopulation p; 4 int rc; 5 struct mallinfomi[2]; 6 double lambda[2]; 7 double lambda0[3]= f 16530.7,13254.,12806.9 g ; 8 double lambda1[5]= f 49634.9,46762.5,45421.3, 35591.1,35548.4 g ; 9 10 mi[0]=mallinfo; 11 lambda[0]=lambda0;lambda[1]=lambda1; 12 p=jgaPopulationCreate1,2,1,lambda,1; 13 CU ASSERT PTR NOT NULLp; 14 if p==NULL goto error0; 15 CU ASSERTrc=jgaPopulationDestroyp==0; 16 mi[1]=mallinfo; 17 CU ASSERTmi[0].uordblks==mi[1].uordblks; 18 return ; 19 error0: 20 return ; 21 g PAGE 217 AppendixE DataStructures Thefollowingdocumentsdatastructuresusedinthecodewhichwillfollow. E.1Queue E.1.1IntroductionAqueueisadatastructurethatstoreselementsandprovidesthefollowingoperations enqueue dequeue whichoperateonarstinrstoutbasis[51].Weimplementathreadsafequeueusingaglobalmutexontheunderlyinglist.Theunderlyinglistisasinglylinkedlist.AqueueElementstructureisusedasthelistnodes.Acopyconstructorisimplementedtogenerateacopyofthelist. Alockhierarchywasconsidered;howeversincelistscansarenotarequirementtherearenoreadsofconsiderablelengthandmanagementofalockhierarchyisbelievedtobeofnovalue. 196 PAGE 218 Queue197 E.1.2Variables TableE.1summarizescommonlyusedshortvariables Variable Description d data n nextornumbercontextdependent h head t tail q queue qe queueelement TableE.1:Variables E.1.3Code queue.h TheheaderleisgiveninListingE.1. ListingE.1: queue.h 1 #ifndef DS QUEUE H 2 #define DS QUEUE H 3 4 #include < config.h > 5 #include < pthread.h > 6 7 typedefstruct queueElement f 8 void d; / data / 9 struct queueElement n; / nextlinkedlistelement / 10 g queueElement; 11 12 typedefstruct queue f PAGE 219 Queue198 13 unsignedlong n; / number / 14 pthread mutex tmutex; 15 void cpy void ; 16 queueElement h, t; / headandtailoflist / 17 g queue; 18 19 #if HAVE CUNIT CUNIT H 20 int init queueElementUnit void ; 21 int clean queueElementUnit void ; 22 void unit queueElementCreate void ; 23 void unit queueElementDestroy void ; 24 void unit queueElementDestroyFree void ; 25 26 int init queueUnit void ; 27 int clean queueUnit void ; 28 void unit queueCreate void ; 29 void unit queueCopy void ; 30 void unit queueEnqueue void ; 31 void unit queueDequeue void ; 32 void unit queueDestroy void ; 33 void unit queueLength void ; 34 void unit queueDestroyFree void ; 35 #endif 36 37 queueElement queueElementCreate void data; 38 void queueElementDestroyqueueElement qe; 39 int queueElementDestroyFreequeueElement qe; 40 41 queue queueCreate void cpy void ; 42 queue queueCopyqueue q; PAGE 220 Queue199 43 int queueEnqueuequeue q, void d; 44 void queueDequeuequeue q; 45 int queueLengthqueue q; 46 int queueDestroyqueue q; 47 #endif ThequeueElementcontaininsdatadandthelinktothenextelementinthelist n .ThequeuestoresthelistofqueueElementswithaheadhandatailtforquickenqueuinganddequeuing,acopyfunctioncpy ,apthreadmutexmutexforthreadedaccesscontrolandalistcountnforquickimplementationofthequeueLength function.Lines19-35denefunctionsusedforunittestingwithcunitandareincludedonlyifthe cunit frameworkisavailableonthesystem.TheremainingledenesoperationsonthequeueElementandqueuestructures.queue.c queue.ccontainscodetoimplementqueueElementandqueuestructuresandtheirassociatedoperators.queueElementstructuresshouldonlybeusedbyqueueoperatorsandnotbyusercode. See[35]pages118{121foranexplanationofthedeclaration. PAGE 221 Queue200 ListingE.2: queue.c Includes 1 #include < config.h > 2 #include < malloc.h > 3 #include < stdlib.h > 4 #include < stdio.h > 5 6 #include "queue.h" 7 8 #if HAVE CUNIT CUNIT H 9 #include < CUnit/Basic.h > 10 #include < CUnit/CUnit.h > 11 #endif Beyondthestandardincludesconfig.hisincludedfromthetoplevelsourcedirectory,generatedbyconfigureandthecunitheaderlesareincludedifcunitisinstalled. queueElementstructuresareusedinternallybyqueuestructuresandarenotaccesseddirectlybytheprogrammerusingthe queue exceptinthecaseofunittesting.Unittestsarealwaysconsidered friend functions. PAGE 222 Queue201 FunctionE.1.1queueElement*queueElementCreatevoid*data.Thefunc-tionqueueElementCreateistheconstructorforthequeueElementstructure.ThecodeisgiveninListingE.3. ListingE.3: queue.c:queueElementCreate 1 queueElement queueElementCreate void data 2 f 3 queueElement qe; 4 5 if qe=malloc sizeof queueElement==NULL goto error0; 6 qe )]TJ/F11 9.9626 Tf 5.977 0 Td [(> d=data; 7 qe )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n=NULL; 8 return qe; 9 error0: 10 return NULL; 11 g OnInput: data isapointertothedatatobestoredintheelement Onoutput:nodataismodied Return:queueElementCreatereturnsapointertoaqueueElementstructureonsuccess,otherwiseitreturns NULL .WhentheelementistakenothelistqueueDestroyshouldbecalledtoreclaimmemory. PAGE 223 Queue202 FunctionE.1.2void*queueElementDestroyqueueElement*qe.ThefunctionqueueElementDestroyisthedestructorforthequeueElementstructure.ThecodeisgiveninListingE.4. ListingE.4: queue.c:queueElementDestroy 1 void queueElementDestroyqueueElement qe 2 f 3 void data; 4 5 if qe==NULL goto error0; 6 data=qe )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d; 7 freeqe; 8 return data; 9 error0: 10 return NULL; 11 g OnInput: qe isapointertothe queueElement tobedestroyed Onoutput:Thestructureunder qe isfreedfrommemory Return:queueElementDestroyreturnsapointertothedatastoredinthedestroyedelementonsuccessor NULL onerror PAGE 224 Queue203 FunctionE.1.3queue*queueCreatevoid**cpyvoid*.ThefunctionqueueCreateistheconstructorfortheaqueue.IfthecpufunctionpointerisNULL thenthecopyconstructorisdisabled.ThecodeisgiveninListingE.5. ListingE.5: queue.c:queueCreate 1 queue queueCreate void cpy void 2 f 3 queue q; 4 5 if q=malloc sizeof queue==NULL f goto error0; g 6 q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n=0; 7 q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h=NULL;q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t=NULL; 8 q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cpy=cpy; 9 pthread mutex init&q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> mutex,NULL; 10 return q; 11 error0: 12 return NULL; 13 g Oninput:cpyisafunctionpointertoafunctionreturningapointerandtakingapointer. Onoutput: Return:queueCreatereturnsapointertoaqueuestructure,usedasaqueuehandle,onsuccessand NULL onerror.WhenthequeueisnolongerneededqueueDestroyshouldbecalledtoreclaimmemoryanddestroythemutex. PAGE 225 Queue204 FunctionE.1.4queue*queueCopyqueue*q.ThefunctionqueueCopyisacopyconstructorforaqueue.Thisusesthecopyconstructorofthedataelementtocopyeachelementoftheexistingqueueandaddittothenewqueue;returningthenewqueue.Managementofthememoryspacegeneratedbythecopyconstructorofthedataelementistheresponsibilityoftheuser. ListingE.6: queue.c:queueCopy 1 queue queueCopyqueue q 2 f 3 queue r; 4 queueElement e; 5 void d; 6 7 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cpy==NULL goto error0; 8 if r=queueCreate void void q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cpy==NULL goto error0; 9 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cpy=q )]TJ/F11 9.9626 Tf 5.977 0 Td [(> cpy; 10 for e=q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h;e!=NULL;e=e )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n f 11 d= q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cpye )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d; 12 queueEnqueuer,d; 13 g 14 pthread mutex init&r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> mutex,NULL; 15 return r; 16 error0: 17 return NULL; 18 g ThecodeisgiveninListingE.6. Oninput: q isahandletothequeuetobecopied Onoutput:anewqueueisgeneratedwithnewdataelementsdynamically PAGE 226 Queue205 allocatedtocontainthesamevaluesasinqusingthecopyconstructorq->cpy.Return:queueCreatereturnsapointertoaqueuestructure,usedasaqueuehandle,onsuccessand NULL onerror.WhenthequeueisnolongerneededqueueDestroyshouldbecalledtoreclaimmemory. PAGE 227 Queue206 FunctionE.1.5intqueueEnqueuequeue*q,void*d.ThefunctionqueueEnqueue addselementstothequeue.ThecodeisgiveninListingE.7. ListingE.7: queue.c:queueEnqueue 1 int queueEnqueuequeue q, void d 2 f 3 queueElement qe; 4 5 if d==NULL goto error0; 6 if qe=queueElement malloc sizeof queueElement==NULL goto error0; 7 pthread mutex lock&q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> mutex; 8 qe )]TJ/F11 9.9626 Tf 5.977 0 Td [(> d=d; 9 qe )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n=NULL; 10 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t!=NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n=qe; 11 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h==NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h=qe; 12 q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t=qe; 13 q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n++; 14 pthread mutex unlock&q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> mutex; 15 return 0; 16 17 error0: 18 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 19 g PAGE 228 Queue207 Oninput: { q isapointertothe queue structure { d isthedatatobestoredinthequeue Onoutput { Thequeue q isupdated. Onreturn { Thevalue0onsuccess. { Thevalue )]TJ/F15 11.9552 Tf 9.298 0 Td [(1onerror. PAGE 229 Queue208 FunctionE.1.6void*queueDequeuequeue*q.ThefunctionqueueDequeueremovestheheadelementofthequeueandreturnsittothecaller.ThecodeisgiveninListingE.8. ListingE.8: queue.c:queueDequeue 1 void queueDequeuequeue q 2 f 3 void d; 4 queueElement qe; 5 6 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h==NULL goto error0; 7 pthread mutex lock&q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> mutex; 8 qe=q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h; 9 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t=NULL; //wedequeuelastelement 10 q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h=q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 11 d=queueElementDestroyqe; 12 q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )13()]TJ/F18 9.9626 Tf 15.298 0 Td [(; 13 pthread mutex unlock&q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> mutex; 14 return d; 15 error0: 16 return NULL; 17 g PAGE 230 Queue209 Oninput: { q isapointertothe queue structuretogetanitemfrom Onoutput:Thequeue q isupdated. Return: { Onsuccessapointertothedataattheheadofthequeueisreturned { Onfailure NULL isreturned PAGE 231 Queue210 FunctionE.1.7void*queueLengthqueue*q.ThefunctionqueueLength returnsthelengthofthequeue.ThecodeisgiveninListingE.9. ListingE.9: queue.c:queueLength 1 int queueLengthqueue q 2 f 3 if q==NULL goto error0; 4 return q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 5 error0: 6 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 7 g Oninput: { q isapointertothe queue structuretodestory Onoutput:Thestructureisunchanged Return: { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned { Onsuccessthenumberofelements, q->n isreturned. PAGE 232 Queue211 FunctionE.1.8void*queueDestroyqueue*q.ThefunctionqueueDestroy isthedestructorforthe queue structure.ThecodeisgiveninListingE.10. ListingE.10: queue.c:queueDestory 1 int queueDestroyqueue q 2 f 3 int rc; 4 int count=10; 5 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n > 0 return q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 6 while 1 f 7 if rc=pthread mutex destroy&q )]TJ/F11 9.9626 Tf 5.977 0 Td [(> mutex==0 break ; 8 if errno==EBUSY f 9 if count )178()]TJ/F18 9.9626 Tf 17.637 0 Td [(==0 break ; 10 g else f 11 perror"pthread mutex destroy"; 12 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 13 g 14 g 15 freeq; 16 return 0; 17 g PAGE 233 Queue212 Oninput: { q isapointertothe queue structuretodestory Onoutput:Thememoryallocatedunderqisfreedifsuccessful,otherwiseitisunchanged. Return: {Iftherearenoelementsonthequeueandthemutexisdestroyedthen0isreturned {Ifthereareelementsonthequeuethatarelefttobehandledthenumberofelementsonthequeuearereturned. { Intheeventofanerror )]TJ/F15 11.9552 Tf 9.299 0 Td [(1isreturnedandthequeueisnotdestroyed.IfthereareitemsonthequeuetheymustberemovedtofreethememoryofthequeueElementsandhandlestothedatareturnedforprocessing.Ifthemutexcannotbedestroyedafter10triesthefunctionreturns.Thereisaonesecondwaitbetweenattemptstodestroythemutex. PAGE 234 Queue213 E.1.4TestPlans Thereareseveralunittestsavailable. FunctionE.1.9 unit queueElementCreate ListingE.11: queue.c:unit queueElementCreate 1 void unit queueElementCreate void 2 f 3 queueElement qe; 4 int d; 5 6 d=0; 7 qe=queueElementCreate&d; 8 CU ASSERT PTR NOT NULL FATALqe; 9 CU ASSERT PTR NOT NULL FATALqe )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d; 10 CU ASSERT int qe )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d==0; 11 d=1; 12 CU ASSERT int qe )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d==1; 13 CU ASSERT PTR NULLqe )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 14 queueElementDestroyqe; 15 return ; 16 g PAGE 235 Queue214 FunctionE.1.10 unit queueElementDestroy ListingE.12: queue.c:unit queueElementDestroy 1 void unit queueElementDestroy void 2 f 3 queueElement qe; 4 int d; 5 void data; 6 struct mallinfosmi,emi; 7 8 smi=mallinfo; 9 qe=queueElementCreate&d; 10 queueElementDestroyqe; 11 emi=mallinfo; 12 CU ASSERTsmi.uordblks==emi.uordblks; 13 data=queueElementDestroyNULL; 14 CU ASSERT PTR NULLdata; 15 return ; 16 g PAGE 236 Queue215 FunctionE.1.11 unit queueElementDestroyFree ListingE.13: queue.c:unit queueElementDestroyFree 1 void unit queueElementDestroyFree void 2 f 3 queueElement qe; 4 int d,rc; 5 struct mallinfosmi,emi; 6 7 smi=mallinfo; 8 d=malloc sizeof int ; 9 CU ASSERT PTR NOT NULL FATALd; 10 qe=queueElementCreated; 11 CU ASSERT PTR NOT NULL FATALqe; 12 rc=queueElementDestroyFreeqe; 13 emi=mallinfo; 14 CU ASSERTrc==0; 15 CU ASSERTsmi.uordblks==emi.uordblks; 16 rc=queueElementDestroyFreeNULL; 17 CU ASSERTrc== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1; 18 qe=queueElementCreateNULL; 19 rc=queueElementDestroyFreeqe; 20 CU ASSERTrc==0; 21 return ; 22 g PAGE 237 Queue216 FunctionE.1.12 unit queueCreate ListingE.14: queue.c:unit queueCreate 1 void unit queueCreate void 2 f 3 queue q; 4 5 q=queueCreate void void 1; 6 CU ASSERT PTR NOT NULL FATALq; 7 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==0; 8 CU ASSERT void void q )]TJ/F11 9.9626 Tf 5.977 0 Td [(> cpy== void void 1; 9 CU ASSERT PTR NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h; 10 CU ASSERT PTR NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t; 11 queueDestroyq; 12 g PAGE 238 Queue217 FunctionE.1.13 unit queueCopy ListingE.15: queue.c:unit queueCopy 1 void unit queueCopy void 2 f 3 queue q; 4 queue r; 5 struct mallinfosmi,emi; 6 int x[4], y,i,rc; 7 8 if q=queueCreate void void intCpy==NULL goto error0; 9 for i=0;i < 4;i++ f 10 x[i]=i; 11 if rc=queueEnqueueq,&x[i] < 0 goto error1; 12 g 13 smi=mallinfo; 14 CU ASSERT PTR NOT NULL FATALr=queueCopyq; 15 CU ASSERT void void r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> cpy== void void intCpy ; 16 for i=0;i < 4;i++ f 17 CU ASSERT y=queueDequeuer==i 18 freey; 19 g 20 queueDestroyr; 21 emi=mallinfo; 22 CU ASSERTsmi.uordblks==emi.uordblks; 23 if smi.uordblks!=emi.uordblksprintf"smi.uordblks = %d, emi. uordblks = %d, diff = %d n n",smi.uordblks, 24 emi.uordblks,emi.uordblks )]TJ/F18 9.9626 Tf 13.87 0 Td [(smi.uordblks; 25 for i=0;i < 4;i++queueDequeueq; PAGE 239 Queue218 26 queueDestroyq; 27 return ; 28 error1: 29 printf"error1 n n"; 30 for i=0;i < 4;i++queueDequeueq; 31 queueDestroyq; 32 error0: 33 CU FAILsetupfailure 34 35 g PAGE 240 Queue219 FunctionE.1.14 unit queueEnqueue ListingE.16: queue.c:unit queueEnqueue 1 void unit queueEnqueue void 2 f 3 queue q; 4 int rc; 5 int x[2]= f 0,1 g ; 6 queueElement qe[1]; //followingapatternwhere inthiscasen=1 7 8 9 q=queueCreateNULL; 10 CU ASSERT PTR NOT NULL FATALq; 11 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==0; 12 rc=queueEnqueueq,NULL; //Enqueue returns )]TJ/F21 9.9626 Tf 7.527 0 Td [(1onNULL 13 CU ASSERTrc= )]TJ/F18 9.9626 Tf 8.014 0 Td [(1; 14 15 rc=queueEnqueueq,&x[0]; 16 CU ASSERTrc==0; 17 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==1; //oneelement 18 CU ASSERT PTR NOT NULLq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h; //headisset 19 CU ASSERT PTR NOT NULLq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> t; //tailisset 20 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h==q )]TJ/F11 9.9626 Tf 5.977 0 Td [(> t; //headandtail arethesameelement 21 CU ASSERT PTR NOT NULL FATALq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h; //theheadis theendofthelist 22 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d==&x[0]; //thefirst element'sdatapointstorc 23 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h!=0CU ASSERT PTR NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; //theheadis PAGE 241 Queue220 theendofthelist 24 qe[0]=q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t; 25 rc=queueEnqueueq,&x[1]; 26 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==2; //twoelements 27 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t!=qe[0]; //thetail shouldupdatetothenewelement 28 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h==qe[0]; //thehead shouldstillbethesame 29 CU ASSERT PTR NOT NULLq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h; //thesecond elementshouldhavenonextelement 30 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h!=NULL f 31 CU ASSERT PTR NOT NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 32 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n!=NULLCU ASSERT PTR NULLq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n; 33 g 34 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h!=NULL f 35 CU ASSERTq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d==&x[0]; 36 if q )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n!=NULL f 37 CU ASSERTq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d==&x[1]; 38 g 39 g 40 queueDequeueq; 41 queueDequeueq; 42 queueDestroyq; 43 g PAGE 242 Queue221 FunctionE.1.15 unit queueDequeue ListingE.17: queue.c:unit queueDequeue 1 void unit queueDequeue void 2 f 3 queue q; 4 int rc; 5 void d; 6 int x[3],i; 7 struct mallinfoml[5]; 8 9 q=queueCreateNULL; 10 CU ASSERT PTR NOT NULL FATALq; 11 rc=queueEnqueueq,&rc; 12 d=queueDequeueq; 13 CU ASSERTd==&rc; //Dequeuedequeuesthe pointertorc 14 d=queueDequeueq; 15 CU ASSERT PTR NULLd; //dequeueanemptylist returnsnull 16 ml[0]=mallinfo; 17 for i=0;i < 3;i++ f 18 x[i]=i; 19 rc=queueEnqueueq,&x[i]; 20 ml[i+1]=mallinfo; 21 g 22 d=queueDequeueq; 23 CU ASSERT int d==&x[0]; //dequeuefirst queuedelement 24 CU ASSERT PTR NOT NULL FATALq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h; 25 CU ASSERT PTR NOT NULL FATALq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> d; PAGE 243 Queue222 26 CU ASSERT int q )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d==1; //theheadis thesecondelement 27 ml[4]=mallinfo; 28 CU ASSERTml[4].uordblks==ml[2].uordblks; //queueElement isdestroyedandmemoryreturned 29 d=queueDequeueq; 30 CU ASSERT int d==&x[1]; 31 CU ASSERT PTR NOT NULL FATALq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h; //theheadis thethirdelement 32 CU ASSERT PTR NOT NULL FATALq )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h )]TJ/F11 9.9626 Tf 5.977 0 Td [(> d; 33 CU ASSERT int q )]TJ/F11 9.9626 Tf 5.977 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d==2; 34 ml[4]=mallinfo; 35 CU ASSERTml[4].uordblks==ml[1].uordblks; //queueElement destroyed 36 d=queueDequeueq; 37 CU ASSERT int d==&x[2]; //lastdequeue isthelastelement 38 CU ASSERT PTR NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h; 39 CU ASSERT PTR NULLq )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t; //tailgets cleanedup 40 ml[4]=mallinfo; 41 CU ASSERTml[4].uordblks==ml[0].uordblks; //queueElement Destroyed 42 queueDestroyq; 43 g PAGE 244 Queue223 FunctionE.1.16 unit queueDestroy ListingE.18: queue.c:unit queueDestroy 1 void unit queueDestroy void 2 f 3 queue q; 4 int rc; 5 struct mallinfomi[4]; 6 7 / queueDestroydestroysaemptyqueue / 8 mi[0]=mallinfo; 9 q=queueCreateNULL; 10 CU ASSERT PTR NOT NULL FATALq; 11 rc=queueDestroyq; 12 mi[1]=mallinfo; 13 CU ASSERTrc==0; 14 CU ASSERTmi[0].uordblks==mi[1].uordblks 15 / queueDestroydoesnotdestroyannon )]TJ/F21 9.9626 Tf 7.516 0 Td [(emptyqueue / 16 q=queueCreateNULL; 17 queueEnqueueq,&rc; 18 rc=queueDestroyq; 19 CU ASSERTrc==1; 20 / emptythequeuethenseethatqueueDestroyemptiesanon )]TJ/F21 9.9626 Tf 7.516 0 Td [(empty queue / 21 queueDequeueq; 22 rc=queueDestroyq; 23 mi[3]=mallinfo; 24 CU ASSERTrc==0; 25 CU ASSERTmi[3].uordblks==mi[0].uordblks; 26 return ; 27 g PAGE 245 Queue224 FunctionE.1.17 unit queueLength ListingE.19: queue.c:unit queueLength 1 void unit queueLength void 2 f 3 queue q; 4 int rc,i; 5 double A[4]= f 1.2,3.4,5.6,7.8 g ; 6 7 CU ASSERT PTR NOT NULL FATALq=queueCreateNULL; 8 for i=0;i < 4;i++ f 9 queueEnqueueq,&A[i]; 10 CU ASSERTrc=queueLengthq==i+1; 11 g 12 for i=0;i < 4;i++ f 13 queueDequeueq; 14 CU ASSERTrc=queueLengthq==4 )]TJ/F18 9.9626 Tf 8.625 0 Td [(i )]TJ/F18 9.9626 Tf 8.081 0 Td [(1; 15 g 16 queueDestroyq; 17 g PAGE 246 AppendixF spcat InterfaceTheprogramspcatisusedtosimulatespectroscopydata.Thiswasusedtocreatethesimulatedspectrumusedasatargetforthegeneticalgorithm.Thissoftwarewillalsoprovidetheforwardcomputationusedtogeneratespectrumbasedoncomputedrotationalconstants.ThefollowingsectiondescribesaCprogramminginterfacetothecongurationlesusedby spcat .Weinterfacewiththeprogramspcatthroughcongurationles,inparticular.intand.varles[10].Thesrc/fitsubdirectorycontainsthecodetointerfacewiththesecongurationles.Thecodeisdesignedtomakeitrelativelyeasytoconstructarbitraryles.Thecodedoesnotvalidateinput,thoughitisdesignedtomaketheinclusionofsuchvalidationrelativelystraightforward.TheinterfacecanbecontrolledthrougharotSpecstructurewhichreducesthenumberofparameterstothoseofinterestforthisprojectandprovidesasimpleinterfacetogeneratingacatFilestructureusedtogeneratespecDatastructuresofvariousresolutions. 225 PAGE 247 .int 226 F.1 .int F.1.1IntroductionThe.intlecontainsoptionsanddipoleinformation.Thecodeallowsonetosettheseoptionsasdesired. F.1.2VariablesTheonlycommonshortvariableusedisfwhichiscommonlyusedforthehandletothe intFile structure. F.1.3Code int.h int.h,ListingF.1,denesthedipoleandintFilestructures.TheintFilestructureistheprimarystructurehandlingtheleandcontainsvariablesfortheoptionsintheleasdescribedinthedocumentation[10].Thedipolestructureisusedastheelementforthelistofdipolesstoredinthele.Thesearecontrolledviaaqueueinthe intFile structure.Lines18-28denefunctionsforunittestingandlines30-37declaretheinterfacetothestructures.Thedipolestructureissimple,welldenedandrequireslittleinteractionfromtheuser;thereforeit'sinterfaceishandledthroughthe intFile . PAGE 248 .int 227 ListingF.1: int.h 1 #ifndef INT H 2 #define INT H 3 4 #include < config.h > 5 #include "../ds/queue.h" 6 7 typedefstruct dipole f 8 int idip; 9 double value; 10 g dipole; 11 12 typedefstruct intFile f 13 char title; 14 int flags,tag; 15 double qrot; 16 int fbgn,fend; 17 double str0,str1,fqlim,temp; 18 queue dipoles; 19 g intFile; 20 21 #if HAVE CUNIT CUNIT H 22 int init dipole void ; 23 int clean dipole void ; 24 void unit dipoleCpy void ; 25 26 int init intFile void ; 27 int clean intFile void ; 28 void unit intFileCreate void ; 29 void unit intFileSetTitle void ; PAGE 249 .int 228 30 void unit intFileSetParameters void ; 31 void unit intFileAddDipole void ; 32 void unit intFileRead void ; 33 void unit intFileWrite void ; 34 void unit intFileDestroy void ; 35 #endif 36 37 dipole dipoleCpydipole d; 38 intFile intFileCreate; 39 int intFileSetTitleintFile f, char title; 40 int intFileSetParametersintFile f, int flags, int tag, double qrot, int fbgn, int fend, double str0, double str1, 41 double fqlim, double temp; 42 int intFileAddDipoleintFile f, int idip, double value; 43 int intFileReadintFile f, char file; 44 int intFileWriteintFile f, char file; 45 int intFileDestroyintFile f; 46 #endif PAGE 250 .int 229 int.c int.c containscodetointerfacewiththe .int le. ListingF.2: int.c Includes 1 #include < config.h > 2 3 #include < fcntl.h > 4 #include < malloc.h > 5 #include < stdio.h > 6 #include < stdlib.h > 7 #include < string.h > 8 #include < unistd.h > 9 10 #include < sys/mman.h > 11 #include < sys/stat.h > 12 #include < sys/types.h > 13 14 #include "../ds/queue.h" 15 #include "int.h" 16 17 #if HAVE CUNIT CUNIT H 18 #include < CUnit/Basic.h > 19 #endif SeveralstandardCandUNIXsystemincludelesareused.config.hisincludedfromthetoplevelsourcedirectory,generatedbyconfigureandthecunitheaderlesareincludedifcunitisinstalled.Additionallythe../ds/queue.hleimportsthe queue interfaceand int.h denestheinterfaceforthisle. PAGE 251 .int 230 FunctionF.1.1dipole*dipoleCpydipole*d.ThefunctiondipoleCpyisacopyconstructorforthedipolestructure.Thestructureisnormallycreatedmanually;however,thestructureisnormallyplacedinaqueueandthecopyconstructorofthequeue requiresacopyconstructor.ThecodeisgiveninListingF.3. ListingF.3: int.c:dipoleCpy 1 dipole dipoleCpydipole d 2 f 3 dipole e; 4 5 if d==NULL goto error0; 6 if e=malloc sizeof dipole==NULL goto error0; 7 e )]TJ/F11 9.9626 Tf 5.978 0 Td [(> idip=d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> idip; 8 e )]TJ/F11 9.9626 Tf 5.978 0 Td [(> value=d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> value; 9 return e; 10 error0: 11 return NULL; 12 g OnInput: { d isthedipoletomakeacopyof Onoutput { Valuesarenotmodied. Onreturn { A dipole isreturnedwithvaluesxedfrom d . PAGE 252 .int 231 FunctionF.1.2intFile*intFileCreate.ThefunctionintFileCreateistheconstructorforthe intFile structure.ThecodeisgiveninListingF.4. ListingF.4: int.c:intFileCreate 1 intFile intFileCreate 2 f 3 intFile f; 4 if f=malloc sizeof intFile==NULL goto error0; 5 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title=NULL; 6 if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles=queueCreate void void dipoleCpy== NULL goto error1; 7 return f; 8 9 //error2: 10 queueDestroyf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; 11 error1: 12 freef; 13 error0: 14 return NULL; 15 g Oninput: { Thereisnoinput Inoutput: { Thereisnomodication Return: PAGE 253 .int 232 {OnsuccessanintFilestructureiscreatedandthequeueforthedipolesiscreatedandahandletothe intFile isreturned. { Intheeventofanerror )]TJ/F15 11.9552 Tf 9.299 0 Td [(1isreturned. FunctionF.1.3intintFileSetTitle.ThefunctionintFileSetTitlesetsthetitleinthe intFile structure.ThecodeisgiveninListingF.5. ListingF.5: int.h:intFileSetTitle 1 int intFileSetTitleintFile f, char title 2 f 3 size tlen; 4 5 if f==NULL goto error0; 6 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title!=NULLfreef )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 7 len=strlentitle+1; 8 if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title=malloc sizeof char len==NULL goto error0; 9 strncpyf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,title,len; 10 return 0; 11 error0: 12 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 13 g PAGE 254 .int 233 Oninput: { f isahandletothe intFile structure { title isthecharacterstringtouseasthetitle Onoutput: { Ifthereisanexistingtitleitisfreedfrommemory. { f->title hasanewarrayallocatedand title iscopiedintothisarray. Return: { Onsuccess0. { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1. PAGE 255 .int 234 FunctionF.1.4 intintFileSetParameters ThecodeisgiveninListingF.6. ListingF.6: int.h:intFileSetParameters 1 int intFileSetParametersintFile f, int flags, int tag, double qrot, int fbgn, int fend, double str0, double str1, 2 double fqlim, double temp 3 f 4 if f==NULL goto error0; 5 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> flags=flags; 6 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag=tag; 7 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> qrot=qrot; 8 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn=fbgn; 9 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend=fend; 10 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> str0=str0; 11 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> str1=str1; 12 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fqlim=fqlim; 13 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> temp=temp; 14 return 0; 15 error0: 16 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 17 g Oninput: { f isahandletothe intFile structure {Theremainingfunctionparametersarethe.intleparametersasdescribedin[10]. Onoutput: PAGE 256 .int 235 {TheelementsoftheintFilestructurearesetaccordingtothepassedvalues Return: { Onsuccess0. { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1. FunctionF.1.5 intintFileAddDipole ThecodeisgiveninListingF.7. ListingF.7: int.h:intFileAddDipole 1 int intFileAddDipoleintFile f, int idip, double value 2 f 3 dipole d; 4 int rc; 5 6 if d=malloc sizeof dipole==NULL goto error0; 7 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> idip=idip; 8 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> value=value; 9 rc=queueEnqueuef )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles,d; 10 if rc!=0 goto error1; 11 return 0; 12 13 error1: 14 freed; 15 error0: 16 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 17 g PAGE 257 .int 236 Oninput: { f isahandletothe intFile structure { idip isthe idip parameterforthedipoleasdenedin[10]. { value isthedipolevalueasdenedin[10] Onoutput: { Anew dipole structureiscreatedandaddedtothe dipoles queue. Return: { Onsuccess0. { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1. PAGE 258 .int 237 FunctionF.1.6 intintFileRead ThecodeisgiveninListingF.8. ListingF.8: int.h:intFileRead 1 int intFileReadintFile f, char file 2 f 3 int fd,rc,buflen; 4 char text, cur, buffer; 5 char token, svptr, svDptr; 6 char ct=" n t,"; 7 dipolecurPole; 8 struct stats; 9 10 if fd=openfile,O RDONLY== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 f fprintfstderr,"Cannot open %s n n",file;perror"open"; goto error0; g 11 if rc=fstatfd,&s== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1 f fprintfstderr,"Couldnot stat %s n n",file;perror"fstat"; goto error1; g 12 if text=mmapNULL,s.st size,PROT READ,MAP PRIVATE,fd,0 ==MAP FAILED f 13 fprintfstderr,"Cannot map file %s n n",file; 14 perror"mmap"; 15 goto error1; 16 g 17 //title 18 cur=text; 19 buflen=strnllencur+1; 20 if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title=malloc sizeof char buflen==NULL f perror" malloc"; goto error2; g 21 strncpyf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,cur,buflen; 22 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title+buflen )]TJ/F18 9.9626 Tf 8.015 0 Td [(1=' n 0'; 23 //secondline 24 cur+=buflen; PAGE 259 .int 238 25 buflen=strnllencur+1; 26 if buffer=malloc sizeof char buflen==NULL f perror" malloc"; goto error2; g 27 strncpybuffer,cur,buflen; //copy totokenize 28 buffer+buflen=' n 0'; 29 if token=strtok rbuffer,ct,&svptr==NULL goto dip; 30 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> flags=atoitoken; 31 if token=strtok rNULL,ct,&svptr==NULL goto dip; 32 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag=atoitoken; 33 if token=strtok rNULL,ct,&svptr==NULL goto dip; 34 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> qrot=atoftoken; 35 if token=strtok rNULL,ct,&svptr==NULL goto dip; 36 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn=atoitoken; 37 if token=strtok rNULL,ct,&svptr==NULL goto dip; 38 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend=atoitoken; 39 if token=strtok rNULL,ct,&svptr==NULL goto dip; 40 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> str0=atoftoken; 41 if token=strtok rNULL,ct,&svptr==NULL goto dip; 42 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> str1=atoftoken; 43 if token=strtok rNULL,ct,&svptr==NULL goto dip; 44 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fqlim=atoftoken; 45 if token=strtok rNULL,ct,&svptr==NULL goto dip; 46 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> temp=atoftoken; 47 dip: //processdipoles 48 49 freebuffer; 50 cur+=buflen; 51 while cur < text+s.st size f 52 buflen=strnllencur+1; 53 if buffer=malloc sizeof char buflen==NULL f perror PAGE 260 .int 239 "malloc"; goto error2; g 54 strncpybuffer,cur,buflen )]TJ/F18 9.9626 Tf 8.014 0 Td [(1; 55 buffer+buflen=' n 0'; 56 if token=strtok rbuffer,ct,&svDptr==NULL goto dipEOL; 57 curPole.idip=atoitoken; 58 if token=strtok rNULL,ct,&svDptr==NULL goto dipEOL; 59 curPole.value=atoftoken; 60 while 1 f if token=strtok rNULL,ct,&svDptr==NULL break ; g //makesurenothingelseisontheline 61 intFileAddDipolef,curPole.idip,curPole.value; 62 cur+=buflen; 63 freebuffer; 64 continue ; 65 66 dipEOL: 67 freebuffer; 68 goto error2; 69 g 70 munmaptext,s.st size; 71 closefd; 72 return 0; 73 error2: 74 munmaptext,s.st size; 75 error1: 76 closefd; 77 error0: 78 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 79 g PAGE 261 .int 240 Oninput: { f isahandletothe intFile structure { file isastringwiththelenametoberead. Onoutput: { Then intFile structurehasbeenledinwithvaluesfrom file Return: { Onsuccess0. { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1. PAGE 262 .int 241 FunctionF.1.7 intintFileWrite ThecodeisgiveninListingF.9. ListingF.9: int.h:intFileWrite 1 int intFileWriteintFile f, char file 2 f 3 FILE fd; 4 int i; 5 dipole d; 6 7 if f==NULL goto error0; 8 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles==NULL goto error0; 9 if fd=fopenfile,"w"==NULL goto error0; 10 fprintffd,"%s n n",f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title; 11 fprintffd,"%d %d %lf %d %d %lf %lf %lf %lf n n",f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> flags,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> qrot,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> str0,f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str1,f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> fqlim,f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> temp; 12 for i=0;i < f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n;i++ f 13 d=queueDequeuef )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles; 14 fprintffd," %03d %lf n n",d )]TJ/F11 9.9626 Tf 5.977 0 Td [(> idip,d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> value; 15 queueEnqueuef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles,d; 16 g 17 fclosefd; 18 return 0; 19 error0: 20 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 21 g PAGE 263 .int 242 Oninput: { f isahandletothe intFile structure { file isastringwiththelenametobewritten. Onoutput: {ThelefilehasbeenwrittentowiththevaluesfromtheintFilestructuresuchthat spcat canprocesstheparameters Return: { Onsuccess0. { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1. PAGE 264 .int 243 FunctionF.1.8intintFileDestroy.ThefunctionintFileDestroyisthedestructorforthe intFile structure.ThecodeisgiveninListingF.10. ListingF.10: int.h:intFileDestroy 1 int intFileDestroyintFile f 2 f 3 dipole d; 4 5 if f==NULL goto error0; 6 while 1 f 7 if d=queueDequeuef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles==NULL break ; 8 freed; 9 g 10 queueDestroyf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; 11 freef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title; 12 freef; 13 return 0; 14 error0: 15 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 16 g PAGE 265 .int 244 Oninput: { f isahandletothe intFile structure Onoutput: {Thedipolesareremovedfromthequeue,freedandthequeueisdestroyed{ Thememoryforthe intFile structureisfreed Return: { Onsuccess0. { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1. PAGE 266 .int 245 F.1.4TestPlans FunctionF.1.9 unit dipoleCpy ListingF.11: int.c:unit dipoleCpy 1 void unit dipoleCpy void 2 f 3 dipoled, e; 4 d.idip=1; 5 d.value=1.23; 6 CU ASSERT PTR NOT NULL FATALe=dipoleCpy&d; 7 CU ASSERTe )]TJ/F11 9.9626 Tf 5.978 0 Td [(> idip==1; 8 CU ASSERT DOUBLE EQUALe )]TJ/F11 9.9626 Tf 5.977 0 Td [(> value,1.23,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 9 freee; 10 return ; 11 g PAGE 267 .int 246 FunctionF.1.10 unit intFileCreate ListingF.12: int.c:unit intFileCreate 1 void unit intFileCreate void 2 f 3 intFile f; 4 5 f=intFileCreate; 6 CU ASSERT PTR NOT NULL FATALf; 7 CU ASSERT PTR NULLf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title; 8 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> flags==0; 9 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag==0; 10 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> qrot,0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 11 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn==0; 12 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend==0; 13 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str0,0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 14 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str1,0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 15 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> fqlim,0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 16 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> temp,0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 17 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles; 18 intFileDestroyf; 19 return ; 20 g PAGE 268 .int 247 FunctionF.1.11 unit intFileSetTitle ListingF.13: int.c:unit intFileSetTitle 1 void unit intFileSetTitle void 2 f 3 intFile f; 4 5 f=intFileCreate; 6 intFileSetTitlef,"Hydrogen"; 7 CU ASSERT PTR NOT NULLf; 8 if f!=NULL f 9 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title; 10 CU ASSERT0==strncmp"Hydrogen",f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,8; 11 g 12 return ; 13 g PAGE 269 .int 248 FunctionF.1.12 unit intFileSetParameters ListingF.14: int.c:unit intFileSetParameters 1 void unit intFileSetParameters void 2 f 3 intFile f; 4 5 f=intFileCreate; 6 CU ASSERT PTR NOT NULL FATALf; 7 intFileSetParametersf,1,2,3,4,5,6,7,8,9; 8 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> flags==1; 9 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag==2; 10 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> qrot,3,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 11 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn==4; 12 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend==5; 13 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str0,6,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 14 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str1,7,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 15 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> fqlim,8,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 16 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> temp,9,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 17 intFileDestroyf; 18 return ; 19 g PAGE 270 .int 249 FunctionF.1.13 unit intFileAddDipole ListingF.15: int.c:unit intFileAddDipole 1 void unit intFileAddDipole void 2 f 3 4 intFile f; 5 int rc; 6 7 f=intFileCreate; 8 CU ASSERT PTR NOT NULL FATALf; 9 rc=intFileAddDipolef,0,1.23; 10 CU ASSERTrc==0; 11 CU ASSERT PTR NOT NULL FATALf; 12 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles; 13 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==1; 14 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h; 15 CU ASSERTdipole f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> idip==0; 16 CU ASSERT DOUBLE EQUALdipole f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> value, 1.23,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 17 CU ASSERT PTR NULLf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 18 rc=intFileAddDipolef,1,2.34; 19 CU ASSERTrc==0; 20 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==2; 21 CU ASSERTdipole f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> idip==1; 22 CU ASSERT DOUBLE EQUALdipole f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> t )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> value, 2.34,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 23 rc=intFileDestroyf; 24 return ; 25 g PAGE 271 .int 250 FunctionF.1.14 unit intFileRead ListingF.16: int.c:unit intFileRead 1 void unit intFileRead void 2 f 3 intFile f; 4 int rc; 5 dipole dipole; 6 7 f=intFileCreate; 8 CU ASSERT PTR NOT NULL FATALf; 9 rc=intFileReadf,"./../data/isopropanol.int"; 10 CU ASSERTrc==0; 11 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 12 CU ASSERT0==strncmp"Isopropanol T fit",f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,17; 13 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> flags==0; 14 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag==91; 15 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> qrot,50000,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 16 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn==0; 17 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend==50; 18 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str0, )]TJ/F18 9.9626 Tf 8.239 0 Td [(10,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 19 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str1, )]TJ/F18 9.9626 Tf 8.239 0 Td [(10,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 20 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> fqlim,20,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 21 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> temp,299,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 22 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles; 23 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==3; 24 dipole=queueDequeuef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; 25 CU ASSERT PTR NOT NULL FATALdipole; 26 CU ASSERTdipole )]TJ/F11 9.9626 Tf 5.977 0 Td [(> idip==1; 27 CU ASSERT DOUBLE EQUALdipole )]TJ/F11 9.9626 Tf 5.978 0 Td [(> value, )]TJ/F18 9.9626 Tf 8.625 0 Td [(0.0021,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 28 dipole=queueDequeuef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; PAGE 272 .int 251 29 CU ASSERT PTR NOT NULL FATALdipole; 30 CU ASSERTdipole )]TJ/F11 9.9626 Tf 5.977 0 Td [(> idip==2; 31 CU ASSERT DOUBLE EQUALdipole )]TJ/F11 9.9626 Tf 5.978 0 Td [(> value, )]TJ/F18 9.9626 Tf 8.625 0 Td [(1.5810,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 32 dipole=queueDequeuef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; 33 CU ASSERT PTR NOT NULL FATALdipole; 34 CU ASSERTdipole )]TJ/F11 9.9626 Tf 5.977 0 Td [(> idip==3; 35 CU ASSERT DOUBLE EQUALdipole )]TJ/F11 9.9626 Tf 5.978 0 Td [(> value,0.8987,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 36 rc=intFileDestroyf; 37 g PAGE 273 .int 252 FunctionF.1.15 unit intFileWrite ListingF.17: int.c:unit intFileWrite 1 void unit intFileWrite void 2 f 3 intFile f, g; 4 int rc; 5 pid tpid; 6 char fileName[32]; 7 8 f=intFileCreate; 9 CU ASSERT PTR NOT NULLf; 10 if f==NULL goto error0; 11 rc=intFileReadf,"../data/isopropanol.int"; 12 CU ASSERTrc==0; 13 if rc!=0 goto error1; 14 pid=getpid; 15 snprintffileName,32,"/tmp/intFileTest.%d",pid; 16 rc=intFileWritef,fileName; 17 if rc!=0 goto error1; 18 g=intFileCreate; 19 CU ASSERT PTR NOT NULLg; 20 if g==NULL goto error1; 21 rc=intFileReadg,fileName; 22 CU ASSERTrc==0; 23 CU ASSERT0==strncmpf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title,g )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,17; 24 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> flags==0; 25 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag==91; 26 CU ASSERT DOUBLE EQUALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> qrot,50000,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 27 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn==0; 28 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend==50; PAGE 274 .int 253 29 CU ASSERT DOUBLE EQUALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str0, )]TJ/F18 9.9626 Tf 8.239 0 Td [(10,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 30 CU ASSERT DOUBLE EQUALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> str1, )]TJ/F18 9.9626 Tf 8.239 0 Td [(10,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 31 CU ASSERT DOUBLE EQUALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> fqlim,20,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 32 CU ASSERT DOUBLE EQUALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> temp,299,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 33 CU ASSERT PTR NOT NULL FATALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles; 34 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==3; 35 CU ASSERT PTR NOT NULL FATALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h; 36 CU ASSERT PTR NOT NULL FATALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d; 37 CU ASSERTdipole g )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> idip==1; 38 CU ASSERT DOUBLE EQUALdipole g )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> value, )]TJ/F18 9.9626 Tf 8.612 0 Td [(.0021,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 39 CU ASSERT PTR NOT NULL FATALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 40 CU ASSERT PTR NOT NULL FATALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d; 41 CU ASSERTdipole g )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.977 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> idip=2; 42 CU ASSERT DOUBLE EQUALdipole g )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> value, )]TJ/F18 9.9626 Tf 8.624 0 Td [(1.5810,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 43 CU ASSERT PTR NOT NULL FATALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 44 CU ASSERT PTR NOT NULL FATALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d; 45 CU ASSERTdipole g )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n )]TJ/F11 9.9626 Tf 5.977 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> idip=3; 46 CU ASSERT DOUBLE EQUALdipole g )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> h )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n )]TJ/F11 9.9626 Tf 5.978 0 Td [(> d )]TJ/F11 9.9626 Tf 6.332 0 Td [(> value,0.8987,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 47 48 intFileDestroyg; 49 error1: 50 intFileDestroyf; 51 error0: 52 return ; 53 54 g PAGE 275 .int 254 FunctionF.1.16 unit intFileDestroy ListingF.18: int.c:unit intFileDestroy 1 void unit intFileDestroy void 2 f 3 4 intFile f; 5 struct mallinfosmi,emi; 6 7 smi=mallinfo; 8 f=intFileCreate; 9 intFileSetTitlef,"Isopropanol"; 10 intFileAddDipolef,1,.124; 11 intFileAddDipolef,2,.124; 12 intFileAddDipolef,3,.124; 13 intFileDestroyf; 14 emi=mallinfo; 15 CU ASSERTsmi.uordblks==emi.uordblks; 16 return ; 17 g PAGE 276 .var 255 F.2 .var F.2.1IntroductionThe.varlecontainsoptionswhichcongurehowspcatgeneratesspectrum;inparticularitcontainsthelistofparametersused,inourcasetherotationalinertiaonthreemutuallyorthogonalaxesandthecentrifugaldistortionconstants,andtheCholeskidecompositionofthecorrelationmatrix[10]. F.2.2VariablesTheonlycommonshortvariableusedisfwhichiscommonlyusedforthehandletothe varFile structure. F.2.3Code int.h var.h,ListingF.19denesthevarParamandvarFilestructures.ThevarParamstructurecontainsinformationaboutthetypeofparameterspeciedandit'svalue.ThevarFilestructurecontainsalltheinformationfora.varleusedtogeneratesimulatedspectrum.Lines23-34denetheinterfacefortheunittests.Lines36-45denetheinterfacetothe varFile structure.The varParam structureishandleddirectly. ListingF.19: var.h 1 #ifndef VAR H 2 #define VAR H 3 #include < config.h > PAGE 277 .var 256 4 #include "../ds/queue.h" 5 6 typedefstruct varParam f 7 int idpar; 8 double value,error; 9 char name; 10 g varParam; 11 12 typedefstruct varFile f 13 char title; //line1 14 int npar,nline,nintr,nxpar; //line2 15 double thresh,errtst,frac,cal; 16 char chr; //line3 17 int spind,nvib,knmin,knmax,ixx,iax,wtpl,wtmn, vsym,ewt,diag; 18 varParam parameters; //parameterlines 19 double correlation; //matrix 20 //notinfile 21 unsigned matrixSize; 22 g varFile; 23 24 25 #if HAVE CUNIT CUNIT H 26 int init varFile void ; 27 int clean varFile void ; 28 void unit varFileCreate void ; 29 void unit varFileSetTitle void ; 30 void unit varFileSetOptions void ; 31 void unit varFileSetParameter void ; 32 void unit varFileSetCorrelation void ; PAGE 278 .var 257 33 void unit varFileRead void ; 34 void unit varFileWrite void ; 35 void unit varFileDestroy void ; 36 #endif 37 38 varFile varFileCreate; 39 int varFileSetTitlevarFile f, char title; 40 int varFileSetOptionsvarFile f, int npar, int nline, int nintr, int nxpar, double thresh, double errtst, 41 double frac, double cal, char chr, int spind, int nvib, int knmin, int knmax, 42 int ixx, int iax, int wtpl, int wtmn int vsym, int ewt, int diag; 43 int varFileSetParametervarFile f, unsigned k, int idpar, double value, double error, char name; 44 int varFileSetCorrelationvarFile f, unsigned k, double matrix; 45 int varFileReadvarFile f, char file; 46 int varFileWritevarFile f, char file; 47 int varFileDestroyvarFile f; 48 #endif PAGE 279 .var 258 var.c var.ccontainscodetointerfacewiththe.varle.SeveralstandardCandUNIXsystemincludelesareused.config.hisincludedfromthetoplevelsourcedirectory,generatedbyconfigureandthecunitheaderlesareincludedifcunitisinstalled.Additionallythe ../ds/queue.h leimportsthe queue interface. FunctionF.2.1varFile*varFileCreate.ThefunctionvarfileCreateistheconstructorforthe varFile structure.ThecodeisgiveninListingF.20. ListingF.20: var.c:varFileCreate 1 varFile varFileCreate 2 f 3 varFile f; 4 5 if f=malloc sizeof varFile==NULL goto error0;f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title =NULL; 6 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters=NULL; 7 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation=NULL; 8 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize=0; 9 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar=0; 10 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline=0; 11 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr=0; 12 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nxpar=0; 13 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> thresh=0.0; 14 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> errtst=0; 15 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> frac=0.0; 16 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cal=0.9; 17 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> chr=' '; 18 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> spind=0; 19 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nvib=0; 20 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmin=0; PAGE 280 .var 259 21 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmax=0; 22 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ixx=0; 23 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> iax=0; 24 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtpl=0; 25 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtmn=0; 26 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> vsym=0; 27 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ewt=0; 28 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> diag=0; 29 return f; 30 error0: 31 return NULL; 32 g Oninput: { Therearenoparameters Onoutput: { A varFile structureisallocatedandvaluesaresettodefault Return: { Onsuccessa varFile handleisreturned. { Onerror NULL isreturned. PAGE 281 .var 260 FunctionF.2.2varFile*varFileSetTitle.ThecodeisgiveninListingF.21.ListingF.21: var.c:varFileSetTitle 1 int varFileSetTitlevarFile f, char title 2 f 3 char t; 4 if f==NULL goto error0; 5 if title==NULL goto error0; 6 if t=mallocstrlentitle+1==NULL goto error0; 7 strncpyt,title,strlentitle+1; 8 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title!=NULLfreef )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 9 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title=t; 10 return 0; 11 error0: 12 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 13 g Oninput: { f isahandletothe varFile structure { title isapointertothestringcontainingthetitle. Onoutput: { f->titleisdeallocatedifitexists,spaceforanewtitleisallocatedandthestringiscopiedtothenewbuer. Return: { Onsuccess0isreturned { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. PAGE 282 .var 261 FunctionF.2.3varFile*varFileSetOptions.ThecodeisgiveninListingF.22. ListingF.22: var.c:varFileSetOptions 1 int varFileSetOptionsvarFile f, int npar, int nline, int nintr, int nxpar, double thresh, double errtst, 2 double frac, double cal, char chr, int spind int nvib, int knmin, int knmax, 3 int ixx, int iax, int wtpl, int wtmn, int vsym, int ewt, int diag 4 f 5 int i; 6 7 if f==NULL goto error0; 8 if npar < 0 goto error0; 9 if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters=malloc sizeof varParam npar==NULL goto error0; 10 for i=0;i < npar;i++f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[i].name=NULL; 11 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar=npar; 12 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline=nline; 13 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr=nintr; 14 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nxpar=nxpar; 15 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> thresh=thresh; 16 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> errtst=errtst; 17 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> frac=frac; 18 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cal=cal; 19 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> chr=chr; 20 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> spind=spind; 21 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nvib=nvib; 22 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmin=knmin; PAGE 283 .var 262 23 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmax=knmax; 24 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ixx=ixx; 25 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> iax=iax; 26 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtpl=wtpl; 27 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtmn=wtmn; 28 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> vsym=vsym; 29 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ewt=ewt; 30 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> diag=diag; 31 return 0; 32 33 error0: 34 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 35 g PAGE 284 .var 263 Oninput: { f isahandletothe varFile structure {Theremainingparametersarethevaluesforlines2and3ofthe.varleasdenedin[10]. Onoutput: {TheelementsofthevarFilestructurearesetasgivenbythepassedpa-rameters.Theparametersissettoanallocatedspacefornparparameters.ThenameelementofeachparameterissettoNULL.ThiswillbeusedbyvarFileSetParameter Return: { Onsuccess0isreturned { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. PAGE 285 .var 264 FunctionF.2.4varFile*varFileSetParameter.ThecodeisgiveninListingF.23. ListingF.23: var.c:varFileSetParameter 1 int varFileSetParametervarFile f, unsigned k, int idpar, double value, double error, char name 2 f 3 char n; 4 5 if f==NULL goto error0; 6 if k > =f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar goto error0; //f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nparisindexedfrom0,kfrom 1sincef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nparisfiledefinednadkisarraydefined 7 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters==NULL goto error0; 8 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[k].idpar=idpar; 9 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[k].value=value; 10 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[k].error=error; 11 if n=mallocstrlenname+1==NULL goto error0; 12 strncpyn,name,strlenname+1; 13 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[k].name!=NULLfreef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[k].name; 14 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[k].name=n; 15 return 0; 16 error0: 17 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 18 g PAGE 286 .var 265 Oninput: { f isahandletothe varFile structure { k isazeroindexedindextotheparametertobeset { idpar value error and name arethevaluestoset Onoutput: {Thek thparameterissetwiththevaluespassed.Thenameeldisdeallo-catedifallocated,thenallocatedwithspacetocopythepassed name Return: { Onsuccess0isreturned { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. PAGE 287 .var 266 FunctionF.2.5varFile*varFileSetCorrelation.ThecodeisgiveninList-ingF.24. ListingF.24: var.c:varFileSetCorrelation 1 int varFileSetCorrelationvarFile f, unsigned k, double matrix 2 f 3 double m; 4 5 if f==NULL goto error0; 6 if matrix==NULL goto error0; 7 if k==0 return 0; 8 if m=malloc sizeof double k==NULL goto error0; 9 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize=k; 10 memcpym,matrix, sizeof double k; 11 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation!=NULLfreef )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation; 12 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation=m; 13 return 0; 14 error0: 15 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 16 g PAGE 288 .var 267 Oninput: { f isahandletothe varFile structure { k isthesizeofthematrix { matrix isthematrixtobecopied. Onoutput: { f->matrixSizeissettok,iff->correlationissetthenitisfreed.Abuerisallocatedfor f->correlation andthevaluescopied. Return: { Onsuccess0isreturned { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. PAGE 289 .var 268 FunctionF.2.6varFile*varFileRead.Thisfunctionreadsavarleandstorestheinformationina varFile handle.ThecodeisgiveninListingF.25. ListingF.25: var.c:varFileRead 1 int varFileReadvarFile f, char file 2 f 3 int fd,rc,i; 4 char text, cur, work; 5 char nl=" n r n n", nlptr, line; 6 char ct=" n t,", ctptr, token; 7 struct stats; 8 queue q, lq; 9 double corLine; 10 char corString[11]; 11 12 13 if f==NULL goto error0; 14 if file==NULL goto error0; 15 if fd=openfile,O RDONLY== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 f fprintfstderr,"Cannot open %s n n",file;perror"open"; goto error0; g 16 if rc=fstatfd,&s== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1 f fprintfstderr,"Can not stat % s n n",file;perror"fstat"; goto error0; g 17 if text=mmapNULL,s.st size,PROT READ,MAP PRIVATE,fd,0 ==MAP FAILED f 18 fprintfstderr,"Can not map file %s n n",file; 19 perror"mmap"; 20 goto error1; 21 g 22 //title 23 if work=mallocs.st size==NULL goto error2; 24 memcpywork,text,s.st size; PAGE 290 .var 269 25 if line=strtok rwork,nl,&nlptr==NULL goto eof; 26 if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title=mallocstrlenline+1==NULL goto error3; 27 strncpyf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,line,strlenline+1; 28 //line2 29 if line=strtok rNULL,nl,&nlptr==NULL goto eof; 30 if token=strtok rline,ct,&ctptr==NULL goto eol2; 31 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar=atoitoken; 32 if token=strtok rNULL,ct,&ctptr==NULL goto eol2; 33 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline=atoitoken; 34 if token=strtok rNULL,ct,&ctptr==NULL goto eol2; 35 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr=atoitoken; 36 if token=strtok rNULL,ct,&ctptr==NULL goto eol2; 37 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nxpar=atoitoken; 38 if token=strtok rNULL,ct,&ctptr==NULL goto eol2; 39 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> thresh=atoftoken; 40 if token=strtok rNULL,ct,&ctptr==NULL goto eol2; 41 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> errtst=atoftoken; 42 if token=strtok rNULL,ct,&ctptr==NULL goto eol2; 43 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> frac=atoftoken; 44 if token=strtok rNULL,ct,&ctptr==NULL goto eol2; 45 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cal=atoftoken; 46 eol2: 47 //line3 48 if line=strtok rNULL,nl,&nlptr==NULL goto eof; 49 if token=strtok rline,ct,&ctptr==NULL goto eol3; 50 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> chr= token; 51 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 52 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> spind=atoitoken; 53 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 54 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nvib=atoitoken; PAGE 291 .var 270 55 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 56 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmin=atoitoken; 57 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 58 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmax=atoitoken; 59 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 60 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ixx=atoitoken; 61 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 62 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> iax=atoitoken; 63 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 64 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtpl=atoitoken; 65 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 66 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtmn=atoitoken; 67 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 68 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> vsym=atoitoken; 69 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 70 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ewt=atoitoken; 71 if token=strtok rNULL,ct,&ctptr==NULL goto eol3; 72 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> diag=atoitoken; 73 eol3: 74 if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters=malloc sizeof varParam f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar==NULL goto error4; 75 for i=0;i < f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar;i++ f 76 if line=strtok rNULL,nl,&nlptr==NULL break ; 77 if token=strtok rline,ct,&ctptr==NULL continue ; 78 f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[i].idpar=atoitoken; 79 if token=strtok rNULL,ct,&ctptr==NULL continue ; 80 f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[i].value=atoftoken; 81 if token=strtok rNULL,ct,&ctptr==NULL continue ; 82 f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[i].error=atoftoken; 83 if token=strtok rNULL,ct,&ctptr==NULL continue ; PAGE 292 .var 271 84 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[i].name=mallocstrlentoken+1==NULL goto error4; 85 strncpyf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[i].name,token,strlentoken+1; 86 g 87 if q=queueCreateNULL==NULL goto error4; 88 if lq=queueCreateNULL==NULL goto error4; 89 while line=strtok rNULL,nl,&nlptr!=NULL f 90 if corLine=malloc sizeof double f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> npar==NULL goto error5; 91 queueEnqueuelq,corLine; 92 for i=0;i < f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> npar;i++ f 93 cur=line+10 i; 94 if cur > =work+s.st size )]TJ/F18 9.9626 Tf 14.169 0 Td [(2 goto dumpQueue; 95 strncpycorString,cur,10; 96 corLine[i]=atofcorString; 97 queueEnqueueq,&corLine[i]; 98 g 99 g 100 dumpQueue: 101 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize=queueLengthq; 102 if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation=malloc sizeof double f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> matrixSize== NULL goto error6; 103 for i=0;i < f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize;i++ f f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation[i]= double queueDequeueq; g 104 while 1 f 105 if corLine=queueDequeuelq==NULL break ; 106 freecorLine; 107 g 108 queueDestroylq; 109 while 1 f PAGE 293 .var 272 110 if queueDequeueq==NULL break ; 111 g 112 queueDestroyq; 113 eof: 114 freework; 115 munmaptext,s.st size; 116 closefd; 117 return 0; 118 error6: 119 while 1 f 120 if corLine=queueDequeuelq==NULL break ; 121 freecorLine; 122 g 123 queueDestroylq; 124 error5: 125 while 1 f 126 if queueDequeueq==NULL break ; 127 g 128 queueDestroyq; 129 error4: 130 f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar=0; 131 error3: 132 freework; 133 error2: 134 munmaptext,s.st size; 135 error1: 136 closefd; 137 error0: 138 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 139 g PAGE 294 .var 273 Oninput: { f isahandletothe varFile structure { file isthelenametoberead Onoutput: {ThevarFilestructureisclearedofexistingbuers,newbuersareallo-catedandvaluessetfromthosefoundin file Return: { Onsuccess0isreturned { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. PAGE 295 .var 274 FunctionF.2.7varFile*varFileWrite.ThefunctionvarFileWritewritesthestructuretoa .var le.ThecodeisgiveninListingF.26. ListingF.26: var.c:varFileWrite 1 int varFileWritevarFile f, char file 2 f 3 FILE fd; 4 int i,j; 5 6 if f==NULL goto error0; 7 if file==NULL goto error0; 8 if fd=fopenfile,"w"==NULL goto error0; 9 fprintffd,"%s n n",f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 10 fprintffd,"%d %d %d %d %lf %lf %lf %lf n n",f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> npar,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr,f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> nxpar,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> thresh,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> errtst,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> frac,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> cal; 11 fprintffd,"%c %d %d %d %d %d %d %d %d %d %d %d n n",f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> chr,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> spind,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nvib,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmin,f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> knmax,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ixx,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> iax,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtpl, 12 f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> wtmn,f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> vsym,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ewt,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> diag; 13 for i=0;i < f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> npar;i++fprintffd,"%d %lf %lf %s n n",f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[i].idpar,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[i].value, 14 f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[i].error,f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[ i].name; 15 if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> matrixSize > 0 f 16 for i=0;i < f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize;i+=f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> npar f 17 for j=0;j < f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar&&i+j < f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize;j++ f 18 fprintffd,"% 01.7lf",f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation[i+j]; 19 g 20 fprintffd," n n"; 21 g 22 g PAGE 296 .var 275 23 fclosefd; 24 return 0; 25 error0: 26 return )]TJ/F18 9.9626 Tf 8.32 0 Td [(1; 27 g Oninput: { f isahandletothe varFile structure { file isthelenametobewrittento Onoutput: {Thelefileiscreatedandtheleispopulatedper[10]withvaluesfromf Return: { Onsuccess0isreturned { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. PAGE 297 .var 276 FunctionF.2.8varFile*varFileDesetroy.ThefunctionvarFileDestroy isthedestructorforthe varFile structure.ThecodeisgiveninListingF.27. ListingF.27: var.c:varFileDestroy 1 int varFileDestroyvarFile f 2 f 3 int i; 4 5 if f==NULL goto error0; 6 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title!=NULLfreef )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 7 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation!=NULLfreef )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation; 8 if f )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters!=NULL f 9 for i=0;i < f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> npar;i++ if f )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[i].name!=NULL freef )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[i].name; 10 freef )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters; 11 g 12 freef; 13 return 0; 14 error0: 15 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 16 g PAGE 298 .var 277 Oninput: { f isahandletothe varFile structure Onoutput: { Internalstructuresarefreedandthenthe varFile structureisfreed Return: { Onsuccess0isreturned { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. PAGE 299 .var 278 F.2.4TestPlans FunctionF.2.9 unit varFileCreate ListingF.28: var.c:unit varFileCreate 1 void unit varFileCreate void 2 f 3 varFile f; 4 5 f=varFileCreate; 6 CU ASSERT PTR NOT NULL FATALf; 7 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize==0; 8 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar==0; 9 CU ASSERT PTR NULLf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title; 10 CU ASSERT PTR NULLf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters; 11 CU ASSERT PTR NULLf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation; 12 return ; 13 g PAGE 300 .var 279 FunctionF.2.10 unit varFileSetTitle ListingF.29: var.c:unit varFileSetTitle 1 void unit varFileSetTitle void 2 f 3 varFile f; 4 int rc; 5 6 CU ASSERT PTR NOT NULL FATALf=varFileCreate; 7 //invalidvarFile 8 CU ASSERTrc=varFileSetTitleNULL,"a"== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1; 9 //invalidtitle 10 CU ASSERTrc=varFileSetTitlef,NULL== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1; 11 //correct 12 CU ASSERTrc=varFileSetTitlef,"Isopropanol"==0; 13 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 14 CU ASSERTrc=strncmpf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,"Isopropanol",11==0; 15 varFileDestroyf; 16 return ; 17 g PAGE 301 .var 280 FunctionF.2.11 unit varFileSetOptions ListingF.30: var.c:unit varFileSetOptions 1 void unit varFileSetOptions void 2 f 3 varFile f; 4 int rc; 5 6 CU ASSERT PTR NOT NULL FATALf=varFileCreate; 7 //invalidvarFile 8 CU ASSERTrc=varFileSetOptionsNULL,1,1,1,1,1.0,1.0, 1.0,1.0,'a',1,1,1,1,1,1,1,1,1,1,1== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1; 9 //correct 10 CU ASSERTrc=varFileSetOptionsf,1,1,1,1,1.0,1.0,1.0, 1.0,'a',1,1,1,1,1,1,1,1,1,1,1==0; 11 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar==1; 12 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline==1; 13 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr==1; 14 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nxpar==1; 15 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> thresh,1.0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 16 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> errtst,1.0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 17 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> frac,1.0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 18 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> cal,1.0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 19 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> chr=='a'; 20 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> spind==1; 21 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nvib==1; 22 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmin==1; 23 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> knmax==1; 24 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ixx==1; 25 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> iax==1; 26 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtpl==1; PAGE 302 .var 281 27 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> wtmn==1; 28 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> vsym==1; 29 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> ewt==1; 30 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> diag==1; 31 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[0].name==NULL; 32 varFileDestroyf; 33 return ; 34 g PAGE 303 .var 282 FunctionF.2.12 unit varFileSetParameter ListingF.31: var.c:unit varFileSetParameters 1 void unit varFileSetParameter void 2 f 3 varFile f; 4 int rc; 5 6 CU ASSERT PTR NOT NULL FATALf=varFileCreate; 7 varFileSetOptionsf,8,1,1,1,1.0,1.0,1.0,1.0,'a',1,1, 1,1,1,1,1,1,1,1,1; 8 CU ASSERTrc=varFileSetParameterNULL,1,1,1.0,1.0,"/A" == )]TJ/F18 9.9626 Tf 8.015 0 Td [(1; 9 CU ASSERTrc=varFileSetParameterf,10,1,1.0,1.0,"/A" == )]TJ/F18 9.9626 Tf 8.015 0 Td [(1; 10 CU ASSERTrc=varFileSetParameterf,0,1,1.0,1.0,"/A"== 0; 11 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters; 12 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[0].idpar==1; 13 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[0].value,1.0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 14 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[0].error,1.0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 15 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[0].name; 16 CU ASSERTrc=strncmpf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[0].name,"/A",2==0; 17 varFileDestroyf; 18 return ; 19 g PAGE 304 .var 283 FunctionF.2.13 unit varFileSetCorrelation ListingF.32: var.c:unit varFileSetCorrelation 1 void unit varFileSetCorrelation void 2 f 3 varFile f; 4 double M[4]= f 1.2,3.4,5.6,7.8 g ; 5 6 CU ASSERT PTR NOT NULL FATALf=varFileCreate; 7 CU ASSERTvarFileSetCorrelationNULL,1,M== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1; 8 CU ASSERTvarFileSetCorrelationf,1,NULL== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1; 9 CU ASSERTvarFileSetCorrelationf,4,M==0; 10 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize==4; 11 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation; 12 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[0],1.2,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 13 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[1],3.4,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 14 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[2],5.6,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 15 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[3],7.8,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 16 varFileDestroyf; 17 return ; 18 g PAGE 305 .var 284 FunctionF.2.14 unit varFileRead ListingF.33: var.c:unit varFileRead 1 void unit varFileRead void 2 f 3 varFile f; 4 int rc; 5 6 CU ASSERT PTR NOT NULL FATALf=varFileCreate; 7 CU ASSERTrc=varFileReadNULL,"../data/isopropanol.var"== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1; 8 CU ASSERTrc=varFileReadf,"/badfile"== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1; 9 CU ASSERTrc=varFileReadf,"../data/isopropanol.var"==0 ; 10 CU ASSERT PTR NOT NULL FATALf; 11 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 12 CU ASSERTrc=strncmpf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title," Isopropanol T fit",18== 0; 13 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar==8; 14 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline==138; 15 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr==51; 16 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters; 17 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[0].idpar==10000; 18 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[0].value,8.488888e+3,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 19 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[0].name; 20 CU ASSERTrc=strncmpf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[0].name,"/A",2==0; 21 CU ASSERTf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize==36; 22 CU ASSERT PTR NOT NULL FATALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation; 23 CU ASSERT DOUBLE EQUALf )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[35], )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 24 varFileDestroyf; PAGE 306 .var 285 25 return ; 26 g PAGE 307 .var 286 FunctionF.2.15 unit varFileWrite ListingF.34: var.c:unit varFileWrite 1 void unit varFileWrite void 2 f 3 varFile f, g; 4 int rc; 5 pid tp; 6 char fileName[32]; 7 8 CU ASSERT PTR NOT NULL FATALf=varFileCreate; 9 CU ASSERTrc=varFileReadf,"../data/isopropanol.var"==0 ; 10 if rc!=0 goto error1; 11 p=getpid; 12 snprintffileName,32,"/tmp/varFileTest.%d",p; 13 CU ASSERTrc=varFileWritef,fileName==0; 14 if rc!=0 goto error1; 15 g=varFileCreate; 16 if g==NULL goto error1; 17 CU ASSERTrc=varFileReadg,fileName==0; 18 CU ASSERTrc=strncmpf )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,g )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,10==0; 19 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> npar==8; 20 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline==138; 21 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr==51; 22 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[0].idpar==10000; 23 CU ASSERT DOUBLE EQUALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> parameters[0].value,8.488888e+3,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 24 CU ASSERTrc=strncmpg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> parameters[0].name,"/A",2==0; 25 CU ASSERTg )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize==36; 26 CU ASSERT DOUBLE EQUALg )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[35], )]TJ/F18 9.9626 Tf 8.579 0 Td [(1.0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; PAGE 308 .var 287 27 varFileDestroyg; 28 error1: 29 varFileDestroyf; 30 return ; 31 32 g PAGE 309 .var 288 FunctionF.2.16 unit varFileDestroy ListingF.35: var.c:unit varFileDestroy 1 void unit varFileDestroy void 2 f 3 varFile f; 4 int rc; 5 double M[4]= f 1.2,3.4,5.6,7.8 g ; 6 struct mallinfosmi,emi; 7 8 smi=mallinfo; 9 CU ASSERT PTR NOT NULL FATALf=varFileCreate; 10 varFileSetTitlef,"Isopropanol"; 11 varFileSetOptionsf,8,1,1,1,1.0,1.0,1.0,1.0,'a',1,1, 1,1,1,1,1,1,1,1,1; 12 varFileSetParameterf,0,1,1.0,1.0,"/A"; 13 varFileSetParameterf,1,1,1.0,1.0,"/A"; 14 varFileSetParameterf,2,1,1.0,1.0,"/A"; 15 varFileSetParameterf,3,1,1.0,1.0,"/A"; 16 varFileSetParameterf,4,1,1.0,1.0,"/A"; 17 varFileSetParameterf,5,1,1.0,1.0,"/A"; 18 varFileSetParameterf,6,1,1.0,1.0,"/A"; 19 varFileSetParameterf,7,1,1.0,1.0,"/A"; 20 varFileSetCorrelationf,4,M; 21 CU ASSERTrc=varFileDestroyf==0; 22 emi=mallinfo; 23 CU ASSERTsmi.uordblks==emi.uordblks; 24 return ; 25 g PAGE 310 .cat 289 F.3 .cat F.3.1IntroductionThe.catleisgeneratedbyspcatwhichtakesthe.varand.intlesasinputs.ThelecontainsalistofemissionspectrawithfrequenciesinMHzandlog 10intensities.Weusethreestructurestomanagethisdata,thecatFilestructurecontainsthepertinentinformationfromthelewitheachlineofspectrainacatLinestructure.WhilethecatLinestructurecontainselementsforallinformationinthelinewecurrentlyonlyusethoseelementsdocumented.OncetheleisreadwegenerateaspecDatastructurewhichresolvesthelinesofspectraintoagivenresolutiondeterminedbybandwidth.Inthiswaywecombinecloselineswhichmayappearasasinglelineinexperimentaldata. F.3.2VariablesThevariableciscommonlyusedforacatFile.ThevariablesdorsisusedforaspecData F.3.3Code cat.hThestructuresusedtomanagethe.catleandtheassociatedspectradataaregiveninListingF.36. ListingF.36: cat.h structures 1 typedefstruct catLine f 2 double freq,err; PAGE 311 .cat 290 3 float intensity; 4 int dr; 5 double elo; 6 int gup,tag,qnfmt,qn[12]; 7 g catLine; 8 9 typedefstruct catFile f 10 catLine line; 11 unsignedlong n; 12 g catFile; 13 14 typedefstruct specData f 15 float bandwidth; 16 unsignedlong minFreq,maxFreq; 17 float intensity; 18 g specData; ThedeclarationforunittestsonthespecDataandthecatFilemodulesisgiveninListingF.37. PAGE 312 .cat 291 ListingF.37: cat.h UnitTestFunctions 1 #if HAVE CUNIT CUNIT H 2 int init specData void ; 3 int clean specData void ; 4 void unit specDataCreate void ; 5 void unit specDataResolve void ; 6 void unit specDataMaximumIntensity void ; 7 void unit specDataGenerate void ; 8 void unit specDataGraph void ; 9 void unit specDataDestroy void ; 10 11 int init catFile void ; 12 int clean catFile void ; 13 void unit catFileCreate void ; 14 void unit catFileRead void ; 15 void unit catFileDestroy void ; 16 #endif ThedeclarationforauxiliaryfunctionsforthespecDataandthecatFilemodulesisgiveninListingF.38. ListingF.38: cat.h AuxiliaryFunctions 1 float resolve int n, float x, int m; Thedeclarationfor catFile functionsisgiveninListingF.39. ListingF.39: cat.hcatFile Functions 1 catFile catFileCreate; 2 int catFileReadcatFile c, char file; 3 int catFileDestroycatFile c; PAGE 313 .cat 292 Thedeclarationfor specData functionsisgiveninListingF.40. ListingF.40: cat.hspecData Functions 1 specData specDataCreate; 2 specData specDataGeneratecatFile c, float bandwidth, unsigned long minFreq, unsignedlong maxFreq; 3 specData specDataResolvespecData s, int factor; 4 float specDataMaximumIntensityspecData s, float bandwidth; 5 int specDataGraphspecData s, int startFreq, int endFreq, char f, float fullIntensity; 6 int specDataDestroyspecData s; cat.c catFileThecatFilestructurecontrolsIOfromthespcat.catledenedin[10].Theleconsistsofaseriesofline,eachlinerepresentinganlineofemissionspectra.Weusethefrequencyandintensityvaluestoconstructaspectra,storedinaspecData structure. PAGE 314 .cat 293 FunctionF.3.1catFile*catFileCreate.ThefunctioncatFileCreateistheconstructorforthe catFile structure.ThecodeisgiveninListingF.41. ListingF.41: cat.c:catFileCreate 1 catFile catFileCreate 2 f 3 catFile c; 4 5 if c=malloc sizeof catFile==NULL goto error0; 6 c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> line=NULL; 7 c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n=0; 8 return c; 9 error0: 10 return NULL; 11 g ThisistheconstructorforthecatFilestructure.ThecodeisgiveninListingF.41. Oninput: { Thereisnoinput Onoutput: { The catFile structureisallocatedandinitialvaluesxed. Return: { Onsuccessa catFile handleisreturned. { Onerror NULL isreturned. PAGE 315 .cat 294 FunctionF.3.2catFile*catFileRead.ThefunctioncatFileReadloadsdatafroma .cat leintothestructure.ThecodeisgiveninListingF.42. ListingF.42: cat.c:catFileRead 1 int catFileReadcatFile c, char file 2 f 3 int fd,rc,i; 4 char text, work, cur, line; 5 char nl=" n r n n", nlptr; 6 char freq[14],intensity[8]; 7 struct stats; 8 9 if c==NULL goto error0; 10 if file==NULL goto error0a; 11 if fd=openfile,O RDONLY== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 goto error0b; 12 if rc=fstatfd,&s== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1 goto error1; 13 if s.st size==0 f 14 c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n=0; 15 c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line=NULL; 16 closefd; 17 return 0; 18 g 19 if text=mmapNULL,s.st size,PROT READ,MAP PRIVATE,fd,0 ==MAP FAILED goto error1b; 20 if work=mallocs.st size==NULL goto error2; 21 memcpywork,text,s.st size; 22 c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n=0; 23 for cur=work;cur < work+s.st size;cur++ if cur==10c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n++; 24 if c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line=malloc sizeof catLine c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> n==NULL goto error3 ; 25 for i=0;i < c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f 26 if line=strtok ri==0?work:NULL,nl,&nlptr== PAGE 316 .cat 295 NULL break ; 27 memsetfreq,0,14;memsetintensity,0,8; 28 strncpyfreq,line,13; 29 strncpyintensity,line+22,7; 30 c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line[i].freq=atoffreq; 31 c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line[i].intensity=powf10,atofintensity; 32 g 33 freework; 34 munmaptext,s.st size; 35 closefd; 36 return 0; 37 38 freec )]TJ/F11 9.9626 Tf 5.978 0 Td [(> line; 39 c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n=0; 40 error3: 41 printf"%s %d n n", FILE LINE ; 42 freework; 43 error2: 44 printf"%s %d n n", FILE LINE ; 45 munmaptext,s.st size; 46 error1b: 47 printf"%s %d n n", FILE LINE ; 48 error1a: 49 printf"%s %d n n", FILE LINE ; 50 error1: 51 printf"%s %d n n", FILE LINE ; 52 closefd; 53 error0b: 54 printf"%s %d n n", FILE LINE ; 55 error0a: 56 printf"%s %d n n", FILE LINE ; 57 error0: PAGE 317 .cat 296 58 printf"%s %d n n", FILE LINE ; 59 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 60 g Oninput: { c isa catFile handle. { file isthelenametoread. Onoutput: {Ifthelehasnolinesitwillbeazerolengthle;whichishandledbymaintainingazerocountand NULL pointerforthe line array. {Ifthelehasoneormorelinestheyarecountedandthevalueisstored.AnarrayofcatLinestructuresisallocated,theneachlineisreadasasequenceofxedlengtheldswithfrequencyandexponentiatedintensitystored Return: { Onsuccess0isreturned. { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. Intensityisstoredinlog 10 valueintheleaccordingto[10]. PAGE 318 .cat 297 FunctionF.3.3catFile*catFileDestroy.ThisisthedestructorforthecatFile structure.ThecodeisgiveninListingF.43. ListingF.43: cat.c:catFileDestroy 1 int catFileDestroycatFile c 2 f 3 if c==NULL goto error0; 4 if c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> line!=NULLfreec )]TJ/F11 9.9626 Tf 5.978 0 Td [(> line; 5 freec; 6 return 0; 7 error0: 8 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 9 g 10 //catFileDestroy// Oninput: { c isthe catFile handle. Onoutput: { The line arrayisfreed. { The catFile structureisfreed. Return: { Onsuccess0isreturned. { Onerror )]TJ/F15 11.9552 Tf 9.298 0 Td [(1isreturned. PAGE 319 .cat 298 FunctionF.3.4float*resolve.Thisfunctionfacilitatesreducingtheresolu-tionofanarraybysummingthevaluesstoredinthearrayintogropusofm.n mod m shouldbe0.ThecodeisgiveninListingF.44. ListingF.44: cat.c:resolve 1 float resolve int n, float x, int m f 2 float y; 3 int i,k; 4 5 if n%m!=0 goto error0; 6 k=n/m; 7 if y=malloc sizeof float n/m==NULL goto error0; 8 for i=0;i < k;i++ f 9 y[i]=cblas sasumm,&x[m i],1; 10 g 11 return y; 12 //error1: 13 freeNULL; 14 error0: 15 return NULL; 16 g PAGE 320 .cat 299 OnInput: { n isthelengthofthearray. { x isthearray. { m isthegroupingsize. OnOutput: { Thenewarrayiscreatedandthesumsstored. OnReturn: { Onsuccessthenewlistisreturned. { Onfailure NULL isreturned. PAGE 321 .cat 300 FunctionF.3.5specData*specDataCreate.ThefunctionspecDataCreateisagenericconstructorforthespecDatastructure.ThecodeisgiveninListingF.45ListingF.45: cat.c:specDataCreate 1 specData specDataCreate 2 f 3 specData d; 4 5 if d=malloc sizeof specData==NULL goto error0; 6 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> bandwidth=0; 7 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq=0; 8 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> minFreq=0; 9 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> intensity=NULL; 10 return d; 11 error0: 12 return NULL; 13 g OnInput: { Thereisnoinput OnOutput: { Memoryisallocatedforthestructureanddefaultvaluesarestored. OnReturn: { Onsuccessahandletothenewstructureisreturned. { Ifmemoryallocationfails NULL isreturned. PAGE 322 .cat 301 FunctionF.3.6specData*specDataGenerate.ThefunctionspecDataGenerateisaconstructorforthespecDatastructurewhichllsthestructurewithdatafroma catFile structure.ThecodeisgiveninListingF.46 ListingF.46: cat.c:specDataGenerate 1 specData specDataGeneratecatFile c, float bandwidth, unsigned long minFreq, unsignedlong maxFreq 2 f 3 specData d; 4 unsignedlong i,n; 5 6 if c==NULL goto error0; 7 if minFreq > =maxFreq goto error0; 8 if bandwidth==0 jj bandwidth > maxFreq )]TJ/F18 9.9626 Tf 13.779 0 Td [(minFreq goto error0; 9 if d=malloc sizeof specData==NULL goto error0; 10 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> bandwidth=bandwidth; 11 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> minFreq=minFreq; 12 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq=maxFreq; 13 if d )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity=calloc sizeof float ,maxFreq )]TJ/F18 9.9626 Tf 7.507 0 Td [(minFreq/ bandwidth==NULL goto error1; 14 for i=0;i < c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n;i++ f 15 if c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> line[i].freq < minFreq jj c )]TJ/F11 9.9626 Tf 5.978 0 Td [(> line[i].freq > maxFreq continue ; 16 n=c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line[i].freq )]TJ/F18 9.9626 Tf 13.78 0 Td [(minFreq/bandwidth; 17 d )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity[n]+=c )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line[i].intensity; 18 g 19 return d; 20 error1: 21 freed; 22 error0: PAGE 323 .cat 302 23 return NULL; 24 g OnInput: { c isahandletoa catFile structurethatcontainssimulatedspectra. { bandwidth istheresolutiontogeneratewith. { minFreq istheminimumfrequencyin MHz forwhichtostoredata. { maxFreq isthemaximumfrequencyin MHz forwhichtostoredata. OnOutput: { Memoryisallocatedforthestructure. { bandwidth minFreq and maxFreq arestored. {Thespectraldatawithinthefrequencyrangeissummedininthearrayatthepointassociatedwiththefrequency. OnReturn: { Onsuccessahandletothenewstructurewithdataisreturned. { Ifmemoryallocationfails NULL isreturned. PAGE 324 .cat 303 FunctionF.3.7specData*specDataResolve.ThefunctionspecDataResolveisaconstructorforthespecDatastructurewhichac-ceptsanotherspecDatastructureandreturnsthesamewithalowerresolutionbysomefactorgivenbythevariable factor .ThecodeisgiveninListingF.47 ListingF.47: cat.c:specDataResolve 1 specData specDataResolvespecData s, int factor f 2 specData d; 3 int rc; 4 5 if s==NULL goto error0; 6 if factor < =0 goto error0; 7 if d=specDataCreate==NULL goto error0; 8 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> bandwidth=s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> bandwidth factor; 9 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> minFreq=s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> minFreq; 10 d )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq=s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq; 11 if d )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity=resolves )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq )]TJ/F18 9.9626 Tf 13.819 0 Td [(s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> minFreq/s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> bandwidth,s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> intensity,factor==NULL goto error1; 12 return d; 13 14 error1: 15 specDataDestroyd; 16 error0: 17 return NULL; 18 g PAGE 325 .cat 304 OnInput: { sisahandletoaspecDatastructurewhosedatawillbeusedtopopulatethenewstructure. { factor isthefactorbywhichtheresolutionwillbereduced. OnOutput: { Memoryisallocatedforthestructure. { bandwidth minFreq and maxFreq arestored. {Thespectraldatawithinthefrequencyrangeissummedininthearrayatthepointassociatedwiththefrequency. OnReturn: { Onsuccessahandletothenewstructurewithdataisreturned. { Ifmemoryallocationfails NULL isreturned. PAGE 326 .cat 305 FunctionF.3.8floatspecDataMaximumIntensity.ThefunctionspecDataMaximumIntensityndsthemaximumintensitystoredinaspecDatastructureatagivenbandwidth.Thecallerisresponsibleforensuringthatthebandwidthisamultipleofthebandwidthstored.Ifthebandwidthrequestedisnotamultipleofthebandwidthstoredthentheresultsareundened.ThecodeisgiveninListingF.48 ListingF.48: cat.c:specDataMaximumIntensity 1 float specDataMaximumIntensityspecData s, float bandwidth f 2 float maxIntensity, resolvedIntensity; 3 int n,m,specMax; 4 5 if bandwidth < s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> bandwidthbandwidth=s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> bandwidth; 6 n=s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq )]TJ/F18 9.9626 Tf 13.819 0 Td [(s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> minFreq/s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> bandwidth; 7 m=s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq )]TJ/F18 9.9626 Tf 13.819 0 Td [(s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> minFreq/bandwidth; 8 if resolvedIntensity=resolves )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq )]TJ/F18 9.9626 Tf 13.819 0 Td [(s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> minFreq/s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> bandwidth,s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> intensity,n/m==NULL goto error0; 9 specMax=cblas isamaxm,resolvedIntensity,1; 10 maxIntensity=resolvedIntensity[specMax]; 11 freeresolvedIntensity; 12 return maxIntensity; 13 error0: 14 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 15 g PAGE 327 .cat 306 OnInput: { s isahandletoa specData structure. { bandwidth isthebandwidthatwhichtheintensityismeasured. OnOutput: OnReturn: { Onsuccessthemaximumintensityisreturned. { Onfailure -1 isreturned. PAGE 328 .cat 307 FunctionF.3.9intspecDataGraph.ThefunctionspecDataGraphgeneratesapdfimageandsavesitinthelef.Thegraphwillberesolvedto1000datapoints.ThecodeisgiveninListingF.49. ListingF.49: cat.c:specDataGraph 1 int specDataGraphspecData s, int startFreq, int endFreq, char f, float fullIntensity f 2 float maxIntensity; 3 float resolvedIntensity; 4 int n,m,specMax; 5 int i; 6 gdImagePtrim; 7 int white,black,red; 8 FILE output; 9 10 if s==NULL goto error0; 11 if f==NULL goto error0; 12 if startFreq < s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> minFreq goto error0; 13 if endFreq > s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq goto error0; 14 n=s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq )]TJ/F18 9.9626 Tf 13.819 0 Td [(s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> minFreq/s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> bandwidth; 15 m=n/1000; 16 if resolvedIntensity=resolven,s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity,m==NULL goto error0; 17 if fullIntensity < 0 f 18 specMax=cblas isamax1000,resolvedIntensity,1; 19 maxIntensity=resolvedIntensity[specMax]; 20 g else f 21 maxIntensity=fullIntensity; 22 g 23 cblas sscal1000,1/maxIntensity,resolvedIntensity,1; PAGE 329 .cat 308 24 if im=gdImageCreate24+1000,1024==NULL goto error1; 25 if white=gdImageColorAllocateim,255,255,255== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 goto error2; 26 if black=gdImageColorAllocateim,0,0,0== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 goto error2; 27 if red=gdImageColorAllocateim,255,0,0== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1 goto error2; 28 if output=fopenf,"w"==NULL goto error2; 29 gdImageLineim,12,12,12,1012,black; 30 gdImageLineim,12,1012,1000+12+1,1012,black; 31 for i=0;i < 1000;i++ f 32 if resolvedIntensity[i] < =1 33 gdImageLineim,i+12+1,1012,i+12+1,1012 )]TJ/F18 9.9626 Tf 8.288 0 Td [( resolvedIntensity[i] 1000,black; 34 else 35 gdImageLineim,i+12+1,1012,i+12+1,12,red; 36 g 37 gdImagePngim,output; 38 fcloseoutput; 39 gdImageDestroyim; 40 freeresolvedIntensity; 41 return 0; 42 fcloseoutput; 43 error2: 44 gdImageDestroyim; 45 error1: 46 freeresolvedIntensity; 47 error0: 48 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 49 g PAGE 330 .cat 309 OnInput: { s isahandletoa specData structure. { startFreq and endFreq denethefrequencyrangetoplot. { f isalenametosaveto. { fullIntensity isthemaximumintensitytoplot. OnOutput: { Thegraphisgeneratedandsavedtothele f OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. PAGE 331 .cat 310 FunctionF.3.10intspecDataDestroy.ThefunctionspecDataDestroyisthedestructorforthe specData structure. ListingF.50: cat.c:specDataDestroy 1 int specDataDestroyspecData s 2 f 3 if s==NULL goto error0; 4 if s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> intensity!=NULLfrees )]TJ/F11 9.9626 Tf 5.978 0 Td [(> intensity; 5 frees; 6 return 0; 7 error0: 8 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 9 g OnInput: { s isthe specData structuretodestroy. OnOutput: { Thememoryassociatedwiththeobjectisdestroyed OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. PAGE 332 .cat 311 F.3.4TestPlans FunctionF.3.11 unit specDataCreate ListingF.51: cat.c:unit specDataCreate 1 void unit specDataCreate void 2 f 3 specData d; 4 5 CU ASSERT PTR NOT NULL FATALd=specDataCreate; 6 CU ASSERT PTR NULLd )]TJ/F11 9.9626 Tf 5.978 0 Td [(> intensity; 7 CU ASSERTd )]TJ/F11 9.9626 Tf 5.978 0 Td [(> bandwidth==0; 8 CU ASSERTd )]TJ/F11 9.9626 Tf 5.978 0 Td [(> minFreq==0; 9 CU ASSERTd )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq==0; 10 specDataDestroyd; 11 return ; 12 g PAGE 333 .cat 312 FunctionF.3.12 unit specDataResolve ListingF.52: cat.c:unit specDataResolve 1 void unit specDataResolve void 2 f 3 specData s, t; 4 catFile c; 5 int rc,i; 6 7 if c=catFileCreate==NULL goto error0; 8 if rc=catFileReadc,"../data/sup 298k.cat" < 0 goto error1; 9 if s=specDataGeneratec,0.5,9000,18000==NULL goto error1; 10 t=specDataResolves,15; 11 CU ASSERT PTR NOT NULLt; 12 if t==NULL goto error2; 13 CU ASSERT DOUBLE EQUALt )]TJ/F11 9.9626 Tf 5.977 0 Td [(> bandwidth,7.5,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 14 CU ASSERT DOUBLE EQUALt )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity[0],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 15 CU ASSERT DOUBLE EQUALt )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity[1],3.20279e )]TJ/F18 9.9626 Tf 8.236 0 Td [(9,1e )]TJ/F18 9.9626 Tf 8.213 0 Td [(14; 16 CU ASSERT DOUBLE EQUALt )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity[2],4.615299e )]TJ/F18 9.9626 Tf 8.235 0 Td [(9,1e )]TJ/F18 9.9626 Tf 8.214 0 Td [(14; 17 specDataDestroyt; 18 specDataDestroys; 19 catFileDestroyc; 20 return ; 21 22 error2: 23 specDataDestroys; 24 catFileDestroyc; 25 CU FAILspecDataResolve==NULL; 26 return ; PAGE 334 .cat 313 27 error1: 28 catFileDestroyc; 29 error0: 30 CU FAILsetupfailure; 31 return ; 32 g PAGE 335 .cat 314 FunctionF.3.13 unit specDataMaximumIntensity ListingF.53: cat.c:unit specDataMaximumIntensity 1 void unit specDataMaximumIntensity void 2 f 3 specData d; 4 catFile c; 5 int rc; 6 float maxInt; 7 8 if c=catFileCreate==NULL goto error0; 9 if rc=catFileReadc,"../data/sup 298k.cat"!=0 goto error0; 10 if d=specDataGeneratec,0.1,9000,18000==NULL goto error1; 11 maxInt=specDataMaximumIntensityd,9; 12 CU ASSERT DOUBLE EQUALmaxInt,1.134273e )]TJ/F18 9.9626 Tf 8.236 0 Td [(5,1e )]TJ/F18 9.9626 Tf 8.213 0 Td [(11; 13 specDataDestroyd; 14 catFileDestroyc; 15 return ; 16 17 //error2: 18 specDataDestroyd; 19 error1: 20 catFileDestroyc; 21 error0: 22 CU FAILsetupfailed; 23 return ; 24 g PAGE 336 .cat 315 FunctionF.3.14 unit specDataGenerate ListingF.54: cat.c:unit specDataGenerate 1 void unit specDataGenerate void 2 f 3 specData d; 4 catFile c; 5 int rc; 6 7 CU ASSERT PTR NOT NULL FATALc=catFileCreate; 8 CU ASSERTrc=catFileReadc,"../data/sup 298k.cat"==0; 9 CU ASSERT PTR NOT NULL FATALd=specDataGeneratec,0.5,9000, 18000; 10 CU ASSERT DOUBLE EQUALd )]TJ/F11 9.9626 Tf 5.977 0 Td [(> bandwidth,0.5,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 11 CU ASSERTd )]TJ/F11 9.9626 Tf 5.978 0 Td [(> minFreq==9000; 12 CU ASSERTd )]TJ/F11 9.9626 Tf 5.978 0 Td [(> maxFreq==18000; 13 CU ASSERT PTR NOT NULL FATALd )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity; 14 CU ASSERT DOUBLE EQUALd )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity[0],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 15 CU ASSERT DOUBLE EQUALd )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity[1],0,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 16 CU ASSERT DOUBLE EQUALd )]TJ/F11 9.9626 Tf 5.977 0 Td [(> intensity[20],3.983821e )]TJ/F18 9.9626 Tf 8.321 0 Td [(10,1e )]TJ/F18 9.9626 Tf 8.213 0 Td [(15; 17 specDataDestroyd; 18 catFileDestroyc; 19 return ; 20 g PAGE 337 .cat 316 FunctionF.3.15 unit specDataGraph ListingF.55: cat.c:unit specDataGraph 1 void unit specDataGraph void 2 f 3 specData d; 4 catFile c; 5 int rc; 6 7 float x[100], y; 8 int i,j,z; 9 10 for i=0;i < 100;i++ f 11 x[i]=i; 12 g 13 CU ASSERT PTR NOT NULL FATALy=resolve100,x,10; 14 for i=0;i < 10;i++ f 15 z=0; 16 for j=0;j < 10;j++z+=i 10+j; 17 CU ASSERTy[i]==z; 18 g 19 freey; 20 CU ASSERT PTR NOT NULL FATALc=catFileCreate; 21 CU ASSERTrc=catFileReadc,"../data/sup 298k.cat"==0; 22 CU ASSERT PTR NOT NULL FATALd=specDataGeneratec,0.1,9000, 18000; 23 CU ASSERTrc=specDataGraphd,9000,18000,"/tmp/sup 298k.png ", )]TJ/F18 9.9626 Tf 8.015 0 Td [(1==0; 24 specDataDestroyd; 25 catFileDestroyc; 26 return ; 27 g PAGE 338 .cat 317 FunctionF.3.16 unit specDataDestroy ListingF.56: cat.c:unit specDataDestroy 1 void unit specDataDestroy void 2 f 3 specData d; 4 catFile c; 5 int rc; 6 struct mallinfosmi,emi; 7 8 CU ASSERT PTR NOT NULL FATALc=catFileCreate; 9 CU ASSERT FATALrc=catFileReadc,"../data/sup 298k.cat"== 0; 10 smi=mallinfo; 11 CU ASSERT PTR NOT NULL FATALd=specDataGeneratec,0.5,9000, 18000; 12 CU ASSERTrc=specDataDestroyd==0; 13 emi=mallinfo; 14 CU ASSERTsmi.uordblks==emi.uordblks; 15 catFileDestroyc; 16 return ; 17 g PAGE 339 .cat 318 FunctionF.3.17 unit catFileCreate ListingF.57: cat.c:unit catFileCreate 1 void unit catFileCreate void 2 f 3 catFile c; 4 5 CU ASSERT PTR NOT NULL FATALc=catFileCreate; 6 CU ASSERT PTR NULLc )]TJ/F11 9.9626 Tf 5.978 0 Td [(> line; 7 CU ASSERTc )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==0; 8 return ; 9 g PAGE 340 .cat 319 FunctionF.3.18 unit catFileRead ListingF.58: cat.c:unit catFileRead 1 void unit catFileRead void 2 f 3 catFile c; 4 int rc; 5 6 CU ASSERT PTR NOT NULL FATALc=catFileCreate; 7 CU ASSERTrc=catFileReadNULL,"/badfile"== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1; 8 CU ASSERTrc=catFileReadc,"/badfile"== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1; 9 CU ASSERTrc=catFileReadc,"../data/sup 298k.cat"==0; 10 CU ASSERTc )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==4512; 11 CU ASSERT PTR NOT NULL FATALc )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line; 12 CU ASSERT DOUBLE EQUALc )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line[1].freq,165.2556,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 13 CU ASSERT DOUBLE EQUALc )]TJ/F11 9.9626 Tf 5.977 0 Td [(> line[1].intensity,1.099258e )]TJ/F18 9.9626 Tf 8.32 0 Td [(10,1e )]TJ/F18 9.9626 Tf 8.214 0 Td [(16; 14 return ; 15 g PAGE 341 .cat 320 FunctionF.3.19 unit catFileDestroy ListingF.59: cat.c:unit catFileDestroy 1 void unit catFileDestroy void 2 f 3 catFile c; 4 int rc; 5 struct mallinfosmi,emi; 6 7 smi=mallinfo; 8 CU ASSERT PTR NOT NULL FATALc=catFileCreate; 9 CU ASSERTrc=catFileReadc,"../data/sup 298k.cat"==0; 10 emi=mallinfo; 11 CU ASSERTsmi.uordblks < emi.uordblks; //ensuretestfails ifcatFileReadisanoop 12 CU ASSERTrc=catFileDestroyc==0; 13 emi=mallinfo; 14 CU ASSERTsmi.uordblks==emi.uordblks; 15 return ; 16 g PAGE 342 Simulator321 F.4Simulator F.4.1IntroductionSimulatingspectraiscontrolledthrougharotSpecstructurewhichmakesuseoftheabovecode.Parametersforbothcongurationlescanbesetandthe.catlecanbegenerated.Thisinterfacesimpliesuseofthe.varand.intlesbyxingmanyoftheoptionswhichshouldnotbechangedforthesimulationsrequiredforthiswork.F.4.2Variables TableF.1summarizescommonlyusedshortvariables Variable Description r rotSpec structure TableF.1:Variables F.4.3Code sim.hThestructurestructrotSpecdenesthevariableparametersforsimulatingtherotationalspectrathatmightbeobtainedusingchirped-pulseFouriertransformmicrowavespectroscopy.Optionswhichmustbedenedinthe.intand.varlesbutwhicharenotmodiedforthesimulationsofinterestarenotedinthecomments.Ifwewishtomodifyoneoftheseparametersthecodemaybemodiedaccordingly.ThestructureisdenedinListingF.60. See[21]. PAGE 343 Simulator322 ListingF.60: sim.h:structrotSpec 1 typedefstruct rotSpec f 2 //.var 3 char title; 4 //npar=8 5 int nline,nintr; 6 //nxpar=0,thresh=0,errtst=1e5,frac=1e0,cal=1.0 7 //chr='a',spind=1,nvib=1,knmin=0,kmax=15,ixx=0, iax=1 8 //wtpl=1,wtmn=1,vsym=1,ewt= )]TJ/F21 9.9626 Tf 8.089 0 Td [(1,diag=0 9 double Parameters[8]; 10 double correlation; 11 int matrixSize; //sizeofcorrelation 12 13 //.int 14 //titletakenfromabove 15 //flags=0 16 int tag; 17 double qrot; 18 int fbgn,fend; 19 //str0=str1= )]TJ/F21 9.9626 Tf 8.293 0 Td [(10.0 20 //fqlim=20.0 21 double temp; 22 queue dipoles; 23 g rotSpec; ThereareseveraltestplansdenedforthesoftwareasdenedinListingF.61 PAGE 344 Simulator323 ListingF.61: sim.h UnitTests 1 #if HAVE CUNIT CUNIT H 2 int init rotSpec void ; 3 int clean rotSpec void ; 4 void unit rotSpecCreate void ; 5 void unit rotSpecCopy void ; 6 void unit rotSpecSetTitle void ; 7 void unit rotSpecSetVarOptions void ; 8 void unit rotSpecSetParameters void ; 9 void unit rotSpecSetCorrelation void ; 10 void unit rotSpecSetIntOptions void ; 11 void unit rotSpecAddDipole void ; 12 void unit rotSpecGenerateCat void ; 13 void unit rotSpecDestroy void ; 14 #endif Thefunctionsdenedonthe rotSpec structurearedenedinListingF.62. PAGE 345 Simulator324 ListingF.62: sim.h Functions 1 rotSpec rotSpecCreate; 2 rotSpec rotSpecCopyrotSpec r; 3 int rotSpecSetTitlerotSpec r, char title; 4 int rotSpecSetVarOptionsrotSpec r, int nline, int nintr; 5 int rotSpecSetParametersrotSpec r, double A, double B, double C, double DJ, double DJK, double DK, 6 double delJ, double delK; 7 int rotSpecSetCorrelationrotSpec r, int n, double C; 8 int rotSpecSetIntOptionsrotSpec r, int tag, double qrot, int fbgn, int fend, double temp; 9 int rotSpecSetTemprotSpec r, double temp; 10 int rotSpecAddDipolerotSpec r, int idip, double value; 11 catFile rotSpecGenerateCatrotSpec r, char spcat; 12 int rotSpecDestroyrotSpec r; PAGE 346 Simulator325 sim.c FunctionF.4.1rotSpec*rotSpecCreate.ThefunctionrotSpecCreateisaconstructorforthe rotSpec structure.ThecodeisgiveninlistingF.63. ListingF.63: sim.c:rotSpecCreate 1 rotSpec rotSpecCreate 2 f 3 rotSpec r; 4 5 if r=malloc sizeof rotSpec==NULL goto error0; 6 if r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles=queueCreate void void dipoleCpy== NULL goto error1; 7 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation=NULL; 8 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title=NULL; 9 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize=0; 10 return r; 11 12 //error2: 13 queueDestroyr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; 14 error1: 15 freer; 16 error0: 17 return NULL; 18 g PAGE 347 Simulator326 OnInput: { NoInput. OnOutput: { Thememoryspaceforthestructureisallocated. OnReturn: { Onsuccessapointertoa rotSpec structureisreturned. { Onerror NULL isreturned. PAGE 348 Simulator327 FunctionF.4.2rotSpec*rotSpecCopy.ThefunctionrotSpecCopyisacopyconstructorforthe rotSpec structure.ThecodeisgiveninlistingF.64. ListingF.64: sim.c:rotSpecCopy 1 rotSpec rotSpecCopyrotSpec r 2 f 3 rotSpec s; 4 int rc; 5 6 if s=rotSpecCreate==NULL goto error0; 7 if rc=rotSpecSetTitles,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title < 0 goto error1; 8 if rc=rotSpecSetVarOptionss,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline,r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> nintr < 0 goto error1; 9 if rc=rotSpecSetParameterss,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[0],r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters [1],r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[2],r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[3], 10 r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[4],r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters [5],r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[6],r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[7] 11 < 0 goto error1; 12 if rc=rotSpecSetCorrelations,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize,r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation < 0 goto error1; 13 if rc=rotSpecSetIntOptionss,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> qrot,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> temp < 0 goto error1; 14 queueDestroys )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; //queuecreatedinrotSpecCreate 15 if s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles=queueCopyr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles==NULL goto error1; 16 return s; 17 error1: 18 rotSpecDestroys; 19 error0: 20 return NULL; 21 g PAGE 349 Simulator328 OnInput: { r isa rotSpec structuretobecopied OnOutput: { Thememoryspaceforanewstructureisallocatedandlled. OnReturn: { Onsuccessapointertoanew rotSpec structureisreturned. { Onerror NULL isreturned. PAGE 350 Simulator329 FunctionF.4.3introtSpecSetTitle.ThefunctionrotSpecSetTitlesetsthetitleforthesimulatedspectrainarotSpecstructure.ThecodeisgiveninlistingF.65. ListingF.65: sim.c:rotSpecSetTitle 1 int rotSpecSetTitlerotSpec r, char title 2 f 3 char t; 4 5 if r==NULL goto error0; 6 if title==NULL return 0; 7 if t=mallocstrlentitle+1==NULL goto error0; 8 strncpyt,title,strlentitle+1; 9 if r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title!=NULLfreer )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 10 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title=t; 11 return 0; 12 error0: 13 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 14 g PAGE 351 Simulator330 OnInput: { r isthe rotSpec structureinwhichthetitlewillbeset OnOutput: { Ifthereisanexistingtitlethememoryforitwillbefreed. { Memoryforthetitleisallocatedandset. OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. PAGE 352 Simulator331 FunctionF.4.4introtSpecSetVarOptions.ThefunctionrotSpecSetVarOptionssetstherotSpecstructureoptionsforthe.varleofasimulatedspectra.ThecodeisgiveninlistingF.66. ListingF.66: sim.c:rotSpecSetVarOptions 1 int rotSpecSetVarOptionsrotSpec r, int nline, int nintr 2 f 3 if r==NULL goto error0; 4 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline=nline;r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> nintr=nintr; 5 return 0; 6 error0: 7 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 8 g OnInput: { r isthe rotSpec structureinwhichtheoptionswillbeset. { nline isthemaximumnumberoflinestogenerate. { nintr isthemaximumnumberofiterations OnOutput: { Thevaluesinthestructureareset. OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. see[10] PAGE 353 Simulator332 FunctionF.4.5introtSpecSetParameters.ThefunctionrotSpecSetParameterssetstherotationalconstantsintherotSpecstruc-ture.fThecodeisgiveninlistingF.67. ListingF.67: sim.c:rotSpecSetParameters 1 int rotSpecSetParametersrotSpec r, double A, double B, double C, double DJ, double DJK, double DK, 2 double delJ, double delK 3 f 4 if r==NULL goto error0; 5 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[0]=A; 6 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[1]=B; 7 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[2]=C; 8 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[3]=DJ; 9 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[4]=DJK; 10 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[5]=DK; 11 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[6]=delJ; 12 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[7]=delK; 13 return 0; 14 error0: 15 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 16 g PAGE 354 Simulator333 OnInput: { r isthe rotSpec structureinwhichtheoptionswillbeset. { A isthevalueoftherotationalconstant A { B isthevalueoftherotationalconstant B { C isthevalueoftherotationalconstant C { DJ isthevalueoftherotationalconstant j { DJK isthevalueoftherotationalconstant jk { DK isthevalueoftherotationalconstant k { delJ isthevalueoftherotationalconstant j { delK isthevalueoftherotationalconstant k OnOutput: { Thevaluesinthestructureareset. OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. PAGE 355 Simulator334 FunctionF.4.6introtSpecSetCorrelation.ThefunctionrotSpecSetCorrelationsetsthecorrelationarrayintherotSpecstructureforthe .var leofasimulatedspectra.ThecodeisgiveninlistingF.68. ListingF.68: sim.c:rotSpecSetCorrelation 1 int rotSpecSetCorrelationrotSpec r, int n, double C 2 f 3 double matrix; 4 5 if r==NULL goto error0; 6 if n==0 return 0; 7 if C==NULL goto error0; 8 if matrix=malloc sizeof double n==NULL goto error0; 9 memcpymatrix,C, sizeof double n; 10 if r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation!=NULLfreer )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation; 11 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation=matrix; 12 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> matrixSize=n; 13 return 0; 14 error0: 15 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 16 g PAGE 356 Simulator335 OnInput: { r isthe rotSpec structureinwhichthearraywillbeset. { n isthelengthofthearrayasasingledimensionalarray. { C isthearray. OnOutput: { Thevaluesinthestructureareset. OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. PAGE 357 Simulator336 FunctionF.4.7introtSpecSetIntOptions.ThefunctionrotSpecSetIntOptionssetstheoptionsforthe.intleintherotSpec structure.ThecodeisgiveninlistingF.69. ListingF.69: sim.c:rotSpecSetIntOptions 1 int rotSpecSetIntOptionsrotSpec r, int tag, double qrot, int fbgn, int fend, double temp 2 f 3 if r==NULL goto error0; 4 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag=tag;r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> qrot=qrot;r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn=fbgn; 5 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend=fend;r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> temp=temp; 6 return 0; 7 error0: 8 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 9 g PAGE 358 Simulator337 OnInput: { r isthe rotSpec structureinwhichthearraywillbeset. { tag qrot fbgn fend temp aretheoptionsforthe .int le OnOutput: { Thevaluesinthestructureareset. OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. see[10]. PAGE 359 Simulator338 FunctionF.4.8introtSpecSetTemp.ThefunctionrotSpecSetTempsetsthetemperatureforthesimulationintherotSpecstructure.ThecodeisgiveninlistingF.70. ListingF.70: sim.c:rotSpecSetTemp 1 int rotSpecSetTemprotSpec r, double temp 2 f 3 if r==NULL goto error0; 4 r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> temp=temp; 5 return 0; 6 error0: 7 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 8 g OnInput: { r isthe rotSpec structureinwhichthearraywillbeset. { tag qrot fbgn fend temp aretheoptionsforthe .int le OnOutput: { Thevaluesinthestructureareset. OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. see[10]. PAGE 360 Simulator339 FunctionF.4.9introtSpecAddDipole.ThefunctionrotSpecAddDipoleaddsadipoletotherotSpecstructure.Inrealityitisaprojectionofthedipoleontotheprincipleaxesofrotationandallthreeprojectionsmustbemadeindividually.Currentlyweonlyuseelectricdipolesbutthisshouldallowmagneticdipoles.ThecodeisgiveninlistingF.71. PAGE 361 Simulator340 ListingF.71: sim.c:rotSpecAddDipole 1 int rotSpecAddDipolerotSpec r, int idip, double value 2 f 3 dipole di; 4 int rc; 5 6 if r==NULL goto error0; 7 if r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles==NULL goto error0; 8 if di=malloc sizeof dipole==NULL goto error0; 9 di )]TJ/F11 9.9626 Tf 5.977 0 Td [(> idip=idip; 10 di )]TJ/F11 9.9626 Tf 5.977 0 Td [(> value=value; 11 if rc=queueEnqueuer )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles,di!=0 goto error1; 12 return 0; 13 error1: 14 freedi; 15 error0: 16 return )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 17 g PAGE 362 Simulator341 OnInput: { r isthe rotSpec structureinwhichthedipolewillbeadded. { idip isthedipoleidentier { value isthevalueofthedipole. OnOutput: { Thedipoleisaddedtothelistofdipolesinthestructure. OnReturn: { Onsuccess 0 isreturned. { Onerror -1 isreturned. See[10]. PAGE 363 Simulator342 FunctionF.4.10catFile*rotSpecGenerateCat.ThefunctionrotSpecGenerateCatprovidesthecorefunctionalityofthecode;generat-ingthe.intand.varlesandrunningspcatagainstthem.ThecodeisgiveninlistingF.72. ListingF.72: sim.c:rotSpecGenerateCat 1 catFile rotSpecGenerateCatrotSpec r, char spcat 2 f 3 varFile varF; 4 intFile intF; 5 catFile catF; 6 dipole di; 7 int n,i,rc,status,lfd; 8 pid tpid,cpid; 9 pthread ttid; 10 char vFileName[30],iFileName[30],cFileName[30],id[30], oFileName[30],lFileName[30]; 11 12 if r==NULL goto error0; 13 pid=getpid; 14 tid=pthread self; 15 if intF=intFileCreate==NULL goto error0; 16 if varF=varFileCreate==NULL goto error1; 17 if catF=catFileCreate==NULL goto error2; 18 19 if rc=varFileSetTitlevarF,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title!=0 goto error3; 20 if rc=varFileSetOptionsvarF,8,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline,r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> nintr, 21 0,0,1e5,1e0,1.0,'a',1,1,0, 15,0,1,1,1,1, )]TJ/F18 9.9626 Tf 8.155 0 Td [(1,0!=0 goto error3; PAGE 364 Simulator343 22 if rc=varFileSetParametervarF,0,10000,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[0], 0,"/A"!=0 goto error3; 23 if rc=varFileSetParametervarF,1,20000,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[1], 0,"/B"!=0 goto error3; 24 if rc=varFileSetParametervarF,2,30000,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[2], 0,"/C"!=0 goto error3; 25 if rc=varFileSetParametervarF,3,200,r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[3],0, "/ )]TJ/F18 9.9626 Tf 7.297 0 Td [(DJ"!=0 goto error3; 26 if rc=varFileSetParametervarF,4,1100,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[4],0, "/ )]TJ/F18 9.9626 Tf 6.918 0 Td [(DJK"!=0 goto error3; 27 if rc=varFileSetParametervarF,5,2000,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[5],0, "/ )]TJ/F18 9.9626 Tf 6.42 0 Td [(DK"!=0 goto error3; 28 if rc=varFileSetParametervarF,6,40100,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[6], 0,"/ )]TJ/F18 9.9626 Tf 8.767 0 Td [(delJ"!=0 goto error3; 29 if rc=varFileSetParametervarF,7,41000,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[7], 0,"/ )]TJ/F18 9.9626 Tf 8.241 0 Td [(delK"!=0 goto error3; 30 if rc=varFileSetCorrelationvarF,r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> matrixSize,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> correlation!=0 goto error3; 31 32 if rc=intFileSetTitleintF,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title!=0 goto error3; 33 if rc=intFileSetParametersintF,0,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> qrot,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn, r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend, )]TJ/F18 9.9626 Tf 8.239 0 Td [(10, )]TJ/F18 9.9626 Tf 8.239 0 Td [(10,20.0,r )]TJ/F11 9.9626 Tf 5.978 0 Td [(> temp!=0 34 goto error3; 35 n=queueLengthr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; 36 for i=0;i < n;i++ f 37 di=queueDequeuer )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles; 38 queueEnqueueintF )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles,di; 39 queueEnqueuer )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles,di; 40 g 41 sprintfvFileName,"%d )]TJ/F18 9.9626 Tf 6.383 0 Td [(%ld.var",pid,tid; PAGE 365 Simulator344 42 sprintfiFileName,"%d )]TJ/F18 9.9626 Tf 6.383 0 Td [(%ld.int",pid,tid; 43 sprintfcFileName,"%d )]TJ/F18 9.9626 Tf 6.383 0 Td [(%ld.cat",pid,tid; 44 sprintfoFileName,"%d )]TJ/F18 9.9626 Tf 6.383 0 Td [(%ld.out",pid,tid; 45 sprintflFileName,"%d )]TJ/F18 9.9626 Tf 6.383 0 Td [(%ld.log",pid,tid; 46 varFileWritevarF,vFileName; 47 intFileWriteintF,iFileName; 48 if cpid=fork < 0 goto error4; 49 if cpid==0 f 50 if lfd=openlFileName,O RDWR j O CREAT j O APPEND, S IRUSR j S IWUSR== )]TJ/F18 9.9626 Tf 8.014 0 Td [(1 f 51 printf"Cannot open log file n n"; 52 exit )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 53 g 54 sprintfid,"%d )]TJ/F18 9.9626 Tf 6.383 0 Td [(%ld",pid,tid; 55 dup2lfd,STDOUT FILENO; 56 if rc=execlpspcat,spcat,id,NULL== )]TJ/F18 9.9626 Tf 8.015 0 Td [(1exit )]TJ/F18 9.9626 Tf 8.321 0 Td [(1; 57 g else f 58 if cpid=waitpidcpid,&status,0 < 0 goto error5; 59 g 60 if catFileReadcatF,cFileName!=0 goto error6; 61 while 1 f 62 if di=queueDequeueintF )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles==NULL break ; 63 g 64 varFileDestroyvarF; 65 intFileDestroyintF; 66 unlinkvFileName; 67 unlinkiFileName; 68 unlinkcFileName; 69 unlinkoFileName; 70 unlinklFileName; PAGE 366 Simulator345 71 return catF; 72 error6: 73 printf"%s %d n n", FILE LINE ; 74 error5: 75 printf"%s %d n n", FILE LINE ; 76 error4: 77 printf"%s %d n n", FILE LINE ; 78 while 1 f 79 if di=queueDequeueintF )]TJ/F11 9.9626 Tf 5.977 0 Td [(> dipoles==NULL break ; 80 g 81 82 error3: 83 printf"%s %d n n", FILE LINE ; 84 catFileDestroycatF; 85 error2: 86 printf"%s %d n n", FILE LINE ; 87 varFileDestroyvarF; 88 error1: 89 printf"%s %d n n", FILE LINE ; 90 intFileDestroyintF; 91 error0: 92 printf"%s %d n n", FILE LINE ; 93 return NULL; 94 g PAGE 367 Simulator346 OnInput: { ristherotSpecstructurecontainingthedataagainstwhichthesimulationwillberun. { spcat isthelocationofthebinaryprogramtorun. OnOutput: { The .var leand .int learecreated. { Theprogram spcat isrunagainsttheles. { Theoutputinthe .cat leisreadintoa catFile structure. { Thegeneratedlesareunlinkeddeleted. OnReturn: { Onsuccessa catFile handleisreturned. { Onerror NULL isreturned. PAGE 368 Simulator347 F.4.4TestPlans FunctionF.4.11 unit rotSpecCreate ListingF.73: sim.c:unit rotSpecCreate 1 void unit rotSpecCreate void 2 f 3 rotSpec r; 4 5 CU ASSERT PTR NOT NULL FATALr=rotSpecCreate; 6 rotSpecDestroyr; 7 g PAGE 369 Simulator348 FunctionF.4.12 unit rotSpecCopy ListingF.74: sim.c:unit rotSpecCopy 1 void unit rotSpecCopy void 2 f 3 rotSpec r, s; 4 int rc; 5 struct mallinfosmi,emi; 6 double M[36]= f)]TJ/F18 9.9626 Tf 21.91 0 Td [(0.2447184,0.0391131,0.2405730,0.2626411, 0.2232851, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.3672985,0.0039128, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.2728508, 7 )]TJ/F18 9.9626 Tf 8.65 0 Td [(0.4786857,0.5187591, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1872719, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.2947686, 0.1655103, )]TJ/F18 9.9626 Tf 8.83 0 Td [(0.2953110,0.9641336, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.9079403, 8 )]TJ/F18 9.9626 Tf 8.65 0 Td [(0.3818704,0.5629960, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.4158666, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1418836, 0.8937219, )]TJ/F18 9.9626 Tf 8.791 0 Td [(0.0371151, )]TJ/F18 9.9626 Tf 8.791 0 Td [(0.7425169,0.5257007, 9 0.4689989, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.2076671, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1847271,0.9947412, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.0937208, 0.1837821, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1234194, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.5007748, 10 )]TJ/F18 9.9626 Tf 8.675 0 Td [(0.0847934, )]TJ/F18 9.9626 Tf 8.676 0 Td [(0.4088240, )]TJ/F18 9.9626 Tf 8.676 0 Td [(0.1024203, )]TJ/F18 9.9626 Tf 8.676 0 Td [(1.0000000 g ; 11 12 if r=rotSpecCreate==NULL goto error0; 13 if rc=rotSpecSetTitler,"test" < 0 goto error1; 14 if rc=rotSpecSetVarOptionsr,138,51!=0 goto error1; 15 if rc=rotSpecSetParametersr, 16 8.488888E+003,8.041802E+003,4.765117E+003,0,2.252e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.427 0 Td [(6.048 e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.427 0 Td [(1.462e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.426 0 Td [(2.351e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3!=0 goto error1; 17 if rc=rotSpecSetCorrelationr,36,M!=0 goto error1; 18 if rc=rotSpecSetIntOptionsr,91,25000.00,0,400,299!=0 goto error1; 19 if rc=rotSpecAddDipoler,1, )]TJ/F18 9.9626 Tf 8.585 0 Td [(.0021!=0 goto error1; 20 if rc=rotSpecAddDipoler,2, )]TJ/F18 9.9626 Tf 8.601 0 Td [(1.5810!=0 goto error1; 21 if rc=rotSpecAddDipoler,3,.8987!=0 goto error1; 22 smi=mallinfo; PAGE 370 Simulator349 23 s=rotSpecCopyr; 24 CU ASSERT PTR NOT NULLs )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title; 25 if s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title!=NULL&&r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title!=NULLCU ASSERTrc=strncmps )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,r )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title,strlenr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> title==0; 26 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline==s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline 27 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr==s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> nintr 28 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[0],s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[0],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(5; 29 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[1],s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[1],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(5; 30 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[2],s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[2],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(5; 31 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[3],s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[3],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(5; 32 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[4],s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[4],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(8; 33 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[5],s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[5],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(8; 34 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[6],s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[6],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(8; 35 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[7],s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> Parameters[7],1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(8; 36 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag==s )]TJ/F11 9.9626 Tf 5.977 0 Td [(> tag; 37 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> qrot,s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> qrot,1; 38 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn==s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn; 39 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend==s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend; 40 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> temp,s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> temp,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 41 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n==s )]TJ/F11 9.9626 Tf 5.978 0 Td [(> dipoles )]TJ/F11 9.9626 Tf 5.978 0 Td [(> n; 42 rotSpecDestroys; 43 emi=mallinfo; 44 if smi.uordblks!=emi.uordblksprintf"smi.uordblks = %d, emi. uordblks = %d, diff = %d n n",smi.uordblks, 45 emi.uordblks,emi.uordblks )]TJ/F18 9.9626 Tf 13.869 0 Td [(smi.uordblks; 46 CU ASSERTsmi.uordblks==emi.uordblks; 47 rotSpecDestroyr; 48 return ; 49 error1: 50 rotSpecDestroyr; PAGE 371 Simulator350 51 error0: 52 CU FAILsetupfailed; 53 return ; 54 g PAGE 372 Simulator351 FunctionF.4.13 unit rotSpecSetTitle ListingF.75: sim.c:unit rotSpecSetTitle 1 void unit rotSpecSetTitle void 2 f 3 rotSpec r; 4 int rc; 5 CU ASSERT PTR NOT NULL FATALr=rotSpecCreate; 6 CU ASSERTrc=rotSpecSetTitler,"title"==0; 7 CU ASSERTrc=strncmpr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> title,"title",5==0; 8 rotSpecDestroyr; 9 return ; 10 g PAGE 373 Simulator352 FunctionF.4.14 unit rotSpecSetVarOptions ListingF.76: sim.c:unit rotSpecSetVarOptions 1 void unit rotSpecSetVarOptions void 2 f 3 rotSpec r; 4 int rc; 5 6 if r=rotSpecCreate==NULL goto error0; 7 CU ASSERTrc=rotSpecSetVarOptionsr,138,51==0; 8 if rc!=0 goto error1; 9 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nline==138; 10 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> nintr==51; 11 rotSpecDestroyr; 12 return ; 13 14 error1: 15 rotSpecDestroyr; 16 error0: 17 return ; 18 g PAGE 374 Simulator353 FunctionF.4.15 unit rotSpecSetParameters ListingF.77: sim.c:unit rotSpecSetParameters 1 void unit rotSpecSetParameters void 2 f 3 rotSpec r; 4 int rc; 5 6 if r=rotSpecCreate==NULL goto error0; 7 CU ASSERTrc=rotSpecSetParametersr,1,2,3,4,5,6,7,8 ==0; 8 if rc!=0 goto error1; 9 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[0],1,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 10 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[1],2,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 11 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[2],3,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 12 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[3],4,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 13 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[4],5,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 14 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[5],6,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 15 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[6],7,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 16 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> Parameters[7],8,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 17 rotSpecDestroyr; 18 return ; 19 20 error1: 21 rotSpecDestroyr; 22 error0: 23 return ; 24 g PAGE 375 Simulator354 FunctionF.4.16 unit rotSpecSetCorrelation ListingF.78: sim.c:unit rotSpecSetCorrelation 1 void unit rotSpecSetCorrelation void 2 f 3 rotSpec r; 4 int rc; 5 double M[4]= f)]TJ/F18 9.9626 Tf 15.276 0 Td [(0.1,0.2,1.3,2.4 g ; 6 7 if r=rotSpecCreate==NULL goto error0; 8 CU ASSERTrc=rotSpecSetCorrelationr,4,M==0; 9 if rc!=0 goto error1; 10 CU ASSERT PTR NOT NULL FATALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation; 11 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[0], )]TJ/F18 9.9626 Tf 8.579 0 Td [(0.1,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(6; 12 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[1],0.2,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 13 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[2],1.3,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 14 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> correlation[3],2.4,1e )]TJ/F18 9.9626 Tf 8.08 0 Td [(6; 15 rotSpecDestroyr; 16 return ; 17 error1: 18 rotSpecDestroyr; 19 error0: 20 return ; 21 g PAGE 376 Simulator355 FunctionF.4.17 unit rotSpecSetIntOptions ListingF.79: sim.c:unit rotSpecSetIntOptions 1 void unit rotSpecSetIntOptions void 2 f 3 rotSpec r; 4 int rc; 5 6 if r=rotSpecCreate==NULL goto error0; 7 CU ASSERTrc=rotSpecSetIntOptionsr,91,50000.00,0,50, 299==0; 8 if rc!=0 goto error1; 9 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> tag==91; 10 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> qrot,50000.00,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(2; 11 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fbgn==0; 12 CU ASSERTr )]TJ/F11 9.9626 Tf 5.978 0 Td [(> fend==50; 13 CU ASSERT DOUBLE EQUALr )]TJ/F11 9.9626 Tf 5.977 0 Td [(> temp,299,1e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3; 14 rotSpecDestroyr; 15 return ; 16 error1: 17 rotSpecDestroyr; 18 error0: 19 return ; 20 g PAGE 377 Simulator356 FunctionF.4.18 unit rotSpecAddDipole ListingF.80: sim.c:unit rotSpecAddDipole 1 void unit rotSpecAddDipole void 2 f 3 g PAGE 378 Simulator357 FunctionF.4.19 unit rotSpecGenerateCat ListingF.81: sim.c:unit rotSpecGenerateCat 1 void unit rotSpecGenerateCat void 2 f 3 rotSpec r; 4 catFile c; 5 specData s; 6 int rc; 7 double M[36]= f)]TJ/F18 9.9626 Tf 21.91 0 Td [(0.2447184,0.0391131,0.2405730, 0.2626411,0.2232851, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.3672985,0.0039128, )]TJ/F18 9.9626 Tf 8.83 0 Td [(0.2728508, 8 )]TJ/F18 9.9626 Tf 8.65 0 Td [(0.4786857,0.5187591, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1872719, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.2947686, 0.1655103, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.2953110, 0.9641336, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.9079403, 9 )]TJ/F18 9.9626 Tf 8.65 0 Td [(0.3818704,0.5629960, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.4158666, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1418836, 0.8937219, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.0371151, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.7425169, 0.5257007, 10 0.4689989, )]TJ/F18 9.9626 Tf 8.791 0 Td [(0.2076671, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1847271, 0.9947412, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.0937208, 0.1837821, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1234194, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.5007748, 11 )]TJ/F18 9.9626 Tf 8.676 0 Td [(0.0847934, )]TJ/F18 9.9626 Tf 8.675 0 Td [(0.4088240, )]TJ/F18 9.9626 Tf 8.676 0 Td [(0.1024203, )]TJ/F18 9.9626 Tf 8.676 0 Td [(1.0000000 g ; 12 pid tpid; 13 char lFileName[10]; 14 15 16 if r=rotSpecCreate==NULL goto error0; 17 if rc=rotSpecSetTitler,"Isopropanol T fit"!=0 goto error1; 18 if rc=rotSpecSetVarOptionsr,138,51!=0 goto error1; 19 if rc=rotSpecSetParametersr,8.488888E+003,8.041802E+003, PAGE 379 Simulator358 4.765117E+003,0,2.252e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.427 0 Td [(6.048e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.427 0 Td [(1.462e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.426 0 Td [(2.351e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3 20 !=0 goto error1; 21 if rc=rotSpecSetCorrelationr,36,M!=0 goto error1; 22 if rc=rotSpecSetIntOptionsr,91,25000.00,0,400,299!= 0 goto error1; 23 if rc=rotSpecAddDipoler,1, )]TJ/F18 9.9626 Tf 8.585 0 Td [(.0021!=0 goto error1; 24 if rc=rotSpecAddDipoler,2, )]TJ/F18 9.9626 Tf 8.601 0 Td [(1.5810!=0 goto error1; 25 if rc=rotSpecAddDipoler,3,.8987!=0 goto error1; 26 CU ASSERT PTR NOT NULL FATALc=rotSpecGenerateCatr,"../ reference/calpgm/spcat"; 27 if s=specDataGeneratec,0.5,9000,18000==NULL goto error2; 28 if rc=specDataGraphs,9000,18000,"/tmp/isopropanol.png", 3.976298e )]TJ/F18 9.9626 Tf 8.214 0 Td [(06!=0 goto error3; 29 30 pid=getpid; 31 sprintflFileName,"%d.log",pid; 32 unlinklFileName; 33 34 specDataDestroys; 35 catFileDestroyc; 36 rotSpecDestroyr; 37 return ; 38 error3: 39 specDataDestroys; 40 error2: 41 catFileDestroyc; 42 error1: 43 rotSpecDestroyr; 44 error0: PAGE 380 Simulator359 45 CU FAILsetupfailure; 46 return ; 47 g PAGE 381 Simulator360 FunctionF.4.20 unit rotSpecDestroy ListingF.82: sim.c:unit rotSpecDestroy 1 void unit rotSpecDestroy void 2 f 3 rotSpec r; 4 int rc; 5 struct mallinfosmi,emi; 6 double M[36]= f)]TJ/F18 9.9626 Tf 21.91 0 Td [(0.2447184,0.0391131,0.2405730, 0.2626411,0.2232851, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.3672985,0.0039128, )]TJ/F18 9.9626 Tf 8.83 0 Td [(0.2728508, 7 )]TJ/F18 9.9626 Tf 8.65 0 Td [(0.4786857,0.5187591, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1872719, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.2947686, 0.1655103, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.2953110, 0.9641336, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.9079403, 8 )]TJ/F18 9.9626 Tf 8.65 0 Td [(0.3818704,0.5629960, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.4158666, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1418836, 0.8937219, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.0371151, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.7425169, 0.5257007, 9 0.4689989, )]TJ/F18 9.9626 Tf 8.791 0 Td [(0.2076671, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1847271, 0.9947412, )]TJ/F18 9.9626 Tf 8.829 0 Td [(0.0937208, 0.1837821, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.1234194, )]TJ/F18 9.9626 Tf 8.792 0 Td [(0.5007748, 10 )]TJ/F18 9.9626 Tf 8.676 0 Td [(0.0847934, )]TJ/F18 9.9626 Tf 8.675 0 Td [(0.4088240, )]TJ/F18 9.9626 Tf 8.676 0 Td [(0.1024203, )]TJ/F18 9.9626 Tf 8.676 0 Td [(1.0000000 g ; 11 12 smi=mallinfo; 13 if r=rotSpecCreate==NULL goto error0; 14 if rc=rotSpecSetTitler,"Isopropanol T fit"!=0 goto error1; 15 if rc=rotSpecSetVarOptionsr,138,51!=0 goto error1; 16 if rc=rotSpecSetParametersr,8.488888E+003,8.041802E+003, 4.765117E+003,0,2.252e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.427 0 Td [(6.048e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.427 0 Td [(1.462e )]TJ/F18 9.9626 Tf 8.236 0 Td [(3, )]TJ/F18 9.9626 Tf 8.426 0 Td [(2.351e )]TJ/F18 9.9626 Tf 8.081 0 Td [(3 17 !=0 goto error1; 18 if rc=rotSpecSetCorrelationr,36,M!=0 goto error1; PAGE 382 Simulator361 19 if rc=rotSpecSetIntOptionsr,91,25000.00,0,400,299!= 0 goto error1; 20 if rc=rotSpecAddDipoler,1, )]TJ/F18 9.9626 Tf 8.585 0 Td [(.0021!=0 goto error1; 21 if rc=rotSpecAddDipoler,2, )]TJ/F18 9.9626 Tf 8.601 0 Td [(1.5810!=0 goto error1; 22 if rc=rotSpecAddDipoler,3,.8987!=0 goto error1; 23 24 CU ASSERTrc=rotSpecDestroyr==0; 25 emi=mallinfo; 26 CU ASSERTsmi.uordblks==emi.uordblks; 27 if smi.uordblks!=emi.uordblksprintf"smi.uordblks = %d, emi. uordblks = %d, diff = %d n n",smi.uordblks, 28 emi.uordblks,emi.uordblks )]TJ/F18 9.9626 Tf 13.87 0 Td [(smi.uordblks; 29 return ; 30 error1: 31 rotSpecDestroyr; 32 error0: 33 CU FAILsetupfailure; 34 return ; 35 g PAGE 383 Bibliography [1]InstituteofElectricalandElectronicsEngeineers, IEEEEditorialStyleManual [2]R.Munroe,Footnotelabyrinths." http://xkcd.com/1208/ ,May2013. [3]C.H.TownesandA.L.Schawlo,MicrowaveSpectroscopy.DoverPublicationsInc.,1075. [4]H.C.AllenandP.C.Cross,MolecularVib-Rotors;Thetheoryandinterpretationofhighresolutioninfraredspectra .NewYork:JohnWileyandSons,Inc,1963. [5]W.GordyandR.L.Cook,MicrowaveMolecularSpectra,vol.IXofTechniqueofOrganicChemistry .IntersciencePublishers,2nded.,1970. [6]J.L.Neill,N.R.Crockett,E.A.Bergin,andHEXOSTeam,HerschelObserva-tionsofExtraordinarySourcesHEXOS.,"in67thInternationalSymposiumonMolecularSpectroscopy ,June2012. [7]J.E.BrightWilsonandJ.B.Howard,Thevibration-rotationenergylevelsofpolyatomicmoleculesi.mathematicaltheoryofsemirigidasymmetricaltopmolecules," TheJournalofChemicalPhysics ,vol.4,no.4,pp.260{268,1936. 362 PAGE 384 BIBLIOGRAPHY363 [8]J.K.G.Watson,Determinationofcentrifugaldistortioncoecientsofasymmetric-topmolecules,"TheJournalofChemicalPhysics,vol.46,no.5,pp.1935{1949,1967. [9]J.K.G.Watson,Determinationofcentrifugal-distortioncoecientsofasymmetric-topmoleculesii.dreizler,dendl,andrudolph'sresults,"JournalofChemicalPhysics ,vol.48,no.1,p.181,1968. [10]NASA,JetPropulsionLaboratory,CalroniaInstituteofTechnology,Documen-tationforSPFITandSPCAT [11]J.Dods,D.Gruner,andP.Brumer,Ageneticalgorithmapproachtottingpolyatomicspectraviageometryshifts,"ChemicalPhysicsLetters,vol.261,pp.612{619,1996. [12]J.Hageman,R.Wehrens,R.deGelder,W.Meerts,andL.Buydens,Fittinguorescencespectrawithgeneticalgorithms,"inParallelProblemSolvingfromNaturePPSNVIM.Schoenauer,K.Deb,G.Rudolph,X.Yao,E.Lutton,J.Merelo,andH.-P.Schwefel,eds.,vol.1917ofLectureNotesinComputerScience ,pp.702{711,SpringerBerlin/Heidelberg,2000. [13]M.H.HennessyandA.M.Kelley,Usingreal-valuedmulti-objectivegeneticalgorithmstomodelmolecularabsorptionspectraandramanexcitationprolesinsolution,"PhysicalChemistryChemicalPhysics,vol.6,no.6,pp.1085{1095,2004. [14]W.L.Meerts,M.Schmitt,andG.C.Groenenboom,Newapplicationsofthegeneticalgorithmfortheinterpretationofhigh-resolutionspectra,"CanadianJournalofChemistry ,vol.82,pp.804{819,2004. PAGE 385 BIBLIOGRAPHY364 [15]W.L.MeertsandM.Schmitt,Anewautomatedassignandanalysingmethodforhigh-resolutionrotationallyresolvedspectrausinggeneticalgorithms,"PhysicaScripta ,vol.73,pp.C47{C52,2006. [16]N.Anderson,Guerrillaclustersforscience:Theapplicationofgeneticalgorithmstospectroscopy."Bachelor'sThesis,2012. [17]G.W.King,R.M.Hainer,andP.C.Cross,Theasymmetricrotori.calculationandsymmetryclassicationofenergylevels,"JournalofChemicalPhysics,vol.11,p.27,1943. [18]D.KivelsonandE.B.Wilson,Approximatetreatmentoftheeectofcentrifugaldistortionontherotationalenergylevelsofasymmetricrotormolecules,"JournalofChemicalPhysics ,vol.20,p.1575,1952. [19]S.T.ShipmanandB.H.Pate,NewTechniquesinMicrowaveSpectroscopy,pp.801{827.JohnWiley&Sons,Ltd,2011. [20]S.T.Shipman,J.L.Neill,R.D.Suenram,M.T.Muckle,andB.H.Pate,Struc-turedeterminationofstrawberryaldehydebybroadbandmicrowavespectroscopy:Conformationalstabilizationbydispersiveinteractions,"PhysicalChemistryLetters ,vol.2,February2011. [21]B.Reinhold,I.A.Finneran,andS.T.Shipman,Roomtemperaturechriped-pulseFouriertransformmicrowavespectroscopyofanisole,"JournalofMolecularSpectroscopy ,vol.270,pp.89{97,2011. [22]W.McCullochandW.Pitts,Alogicalcalculusoftheideasimmanentinnervousactivity,"BulletinofMathematicalBiology,vol.5,pp.115{133,1943.10.1007/BF02478259. PAGE 386 BIBLIOGRAPHY365 [23]M.MinskyandS.Papert,Perceptrons:AnIntroductiontoComputationalGeom-etry .CambridgeMA:TheMITPress,1969. [24]J.Holland, AdaptationinNaturalandArticialSystems .MITPress,1992. [25]D.FloreanoandC.Mattiussi,Bio-insipiredArticialIntelligence:Theories,MethodsandTechnologies .MITPress,2008. [26]D.E.Goldbert,GeneticAlgorithmsinSearch,OptimizationandMachineLearn-ing .AddisonWesleyLongman,Inc.,1989. [27]D.Whitley,T.Starkweather,andD.Fuquay,Schedulingproblemsandtravelingsalesman:Thegeneticedgerecombinationoperator,"inProceedingsoftheThirdInternationalConferenceonGeneticAlgorithmsJ.D.Schaer,ed.,CampusDriveSanMateo,CA94303-9953,pp.133{140,MorganKaufmannPublishers,Inc,June1989. [28]D.PapousekandM.Aliev,Molecularvibrational-rotationalspectra:theoryandapplicationsofhighresolutioninfrared,microwave,andRamanspectroscopyofpolyatomicmolecules .ElsevierScientic,1982. [29]G.Polya,Approximationstotheareaoftheellipsoid."StanfordUniversity,California. [30]H.Wadell,Volume,shapeandroundnessofquartzparticles,"TheJournalofGeology ,vol.43,no.3,pp.250{280,1935. [31]nVidia,cublasuserguide."http://docs.nvidia.com/cuda/cublas/index. html . PAGE 387 BIBLIOGRAPHY366 [32]Intel,IntelR CoreTMi7-3770processorspecications."http://ark.intel.com/ products/65719/ [33]PCI-SIG,Pciexpress3.0frequentlyaskedquestions."http://www.pcisig.com/ news_room/faqs/pcie3.0_faq/ [34]nVidia,nVidiaGeForceGTX680specications."http://www.geforce.com/ hardware/desktop-gpus/geforce-gtx-680/specifications [35]B.W.KernighanandD.M.Ritchie,TheCProgrammingLanguage.PrenticeHall,Inc.,seconded.,1988. [36]nVidia,CUDACprogrammingguide."http://docs.nvidia.com/cuda/ cuda-c-programming-guide/ [37]C.L.Lawson,R.J.Hanson,D.R.Kincaid,andF.T.Krogh,Basiclinearalgebrasubprogramsforfortranusage,"ACMTrans.Math.Softw.,vol.5,pp.308{323,Sept.1979. [38]J.J.Dongarra,J.DuCroz,S.Hammarling,andR.J.Hanson,Anextendedsetoffortranbasiclinearalgebrasubprograms,"ACMTrans.Math.Softw.,vol.14,pp.1{17,Mar.1988. [39]J.J.Dongarra,J.DuCroz,S.Hammarling,andR.J.Hanson,Algorithm656:anextendedsetofbasiclinearalgebrasubprograms:modelimplementationandtestprograms," ACMTrans.Math.Softw. ,vol.14,pp.18{32,Mar.1988. [40]J.J.Dongarra,J.DuCroz,S.Hammarling,andI.S.Du,Asetoflevel3basiclinearalgebrasubprograms,"ACMTrans.Math.Softw.,vol.16,pp.1{17,Mar.1990. PAGE 388 BIBLIOGRAPHY367 [41]J.J.Dongarra,J.D.Cruz,S.Hammerling,andI.S.Du,Algorithm679:Asetoflevel3basiclinearalgebrasubprograms:modelimplementationandtestprograms," ACMTrans.Math.Softw. ,vol.16,pp.18{28,Mar.1990. [42]L.S.Blackford,J.Demmel,J.Dongarra,I.Du,S.Hammarling,H.G.,M.Heroux,L.Kaufman,A.Lumsdaine,A.Petitet,R.Pozo,K.Remington,andR.C.Whaley,Anupdatedsetofbasiclinearalgebrasubprogramsblas,"ACMTrans.Math.Softw. ,vol.28,pp.135{151,June2002. [43]J.Dongarra,Basiclinearalgebrasubprogramstechnicalforumstandard,"Inter-nationalJournalofHighPerformanceApplicationsandSupercomputing,vol.16,no.1,pp.1{111,2002. [44]J.Dongarra,Basiclinearalgebrasubprogramstechnicalforumstandard,"Inter-nationalJournalofHighPerformanceApplicationsandSupercomputing,vol.16,no.2,pp.115{199,2002. [45]R.C.WhaleyandA.Petitet,Minimizingdevelopmentandmain-tenancecostsinsupportingpersistentlyoptimizedBLAS,"Soft-ware:PracticeandExperience,vol.35,pp.101{121,February2005.http://www.cs.utsa.edu/~whaley/papers/spercw04.ps [46]R.C.Whaley,A.Petitet,andJ.J.Dongarra,AutomatedempiricaloptimizationofsoftwareandtheATLASproject,"ParallelComputing,vol.27,no.1{2,pp.3{35,2001.AlsoavailableasUniversityofTennesseeLAPACKWorkingNote#147,UT-CS-00-448,2000 www.netlib.org/lapack/lawns/lawn147.ps . PAGE 389 BIBLIOGRAPHY368 [47]R.C.WhaleyandJ.Dongarra,AutomaticallyTunedLinearAlgebraSoftware,"inNinthSIAMConferenceonParallelProcessingforScienticComputing,1999.CD-ROMProceedings. [48]R.C.WhaleyandJ.Dongarra,Automaticallytunedlinearalgebrasoftware,"in SuperComputing1998:HighPerformanceNetworkingandComputing ,1998. [49]R.C.WhaleyandJ.Dongarra,AutomaticallyTunedLinearAlgebraSoftware,"Tech.Rep.UT-CS-97-366,UniversityofTennessee,December1997.URL:http://www.netlib.org/lapack/lawns/lawn131.ps [50]E.Anderson,Z.Bai,B.C.,S.Blackford,J.Demmel,J.Dongarra,J.DuCroz,A.Greenbaum,S.Hammarling,A.McKenney,andD.Sorensen,LAPACKUsers'Guide .SocietyforIndurstrialandAppliedMathematics,3rded.,1999. [51]T.H.Cormen,C.E.Leiserson,R.L.Rivest,andC.Stein,IntroductiontoAlgorithms .MassachusettsInstituteofTechnology,3rded.,2009. |