[
  {
    "path": ".gitignore",
    "content": "*.svn*\n.Rproj.user\n.Rhistory"
  },
  {
    "path": "PAK.Rproj",
    "content": "Version: 1.0\n\nRestoreWorkspace: Default\nSaveWorkspace: Default\nAlwaysSaveHistory: Default\n\nEnableCodeIndexing: Yes\nUseSpacesForTab: Yes\nNumSpacesForTab: 2\nEncoding: UTF-8\n\nRnwWeave: Sweave\nLaTeX: pdfLaTeX\n"
  },
  {
    "path": "README.md",
    "content": "# PAK\nA performance tuning and knowledge management suit\n#Introduction\nPAK is a general scientific application autotuning framework which can significantly decrease the work of the programmer \nand improve the speed of optimising code.\nWe believe optimising code must be an enjoyable, creative experience. PAK attempts to take the pain out of programmers by\ntaking different models used in processes of optimising projects, such as extracter feature model, optimiser model.\nPAK is accessible, yet powerful, providing powerful tools needed for large, robust applications. \n#PAK models\n![PAK models](https://github.com/luoyulong/PAK/image)\n\n##Analyser\n###functional description of analyser\n\nAnalyse the feature of application instance and the index of performance.\n\n###Customizing\n\nFirst define the configuration file which including featureinfo.xml and analysis.sh.\n\n####featureinfo.xml\n\n#####feature defination\nincluding static/dynamic, feature name, feature description, enable environment variable(when the variable is true meaning \nthat the relative feature needs to be analysed), data type\nfeature data type including numerical, category, boolen, combination(supporting nesting)\n\n#####examples\n```\n  <features>\n    <feature>\n      <type>static</type>\n      <name>arrayshape</name>\n      <description>the shape of array in target program</description>   \n      <enable_variable>Enable_arrayshape</enable_variable>\n      <datatype>\n        <datatype>numerical</datatype>\n        <datatype>numerical</datatype>\n        <datatype>numerical</datatype>\n      </datatype>\n    </feature>\n  </features> \n```\n\n####analysis.sh\n\n- imput: target application, environment variable.\n- output: result file, the name of result file\n- example of output format:\n\n```\n<features>  \n    <feature>\n         <name>arrayshape</name>\n         <value>\n            <value>128</value>\n            <value>128</value>\n            <value>256</value>\n         </value>\n    </feature> \n</features> \n```\n\n###Initializing object\n\n`C.Analyser(Name,Path,Features)`\n\n- Name: the name of analysis(the file name of the configuration file)\n- Path: the path of configuration file\n- Feature: the features during the analysis\n\n##Generator\n###functional description of generator\n\nbased on the input parameters,optimise and change the application instance.\n\n###Customizing\n\nFirst define the configuration file which including variantinfo.xml and atransform.sh.\n\n####variantinfo.xml\n\n#####variable parameter defination\nincluding the name of variant parameter, the description of features, enable environment variable(transferring \nthe parameter of variant), data type(the same with the data type of feature).\n\n#####examples\n\n```\n  <variants>\n        <variant>\n         <name>Unrolling</name>\n         <description>the unrolling factor</description>\n         <enable_variable>ENABLE_Unrolling</enable_variable>\n         <datatype>numerical</datatype>\n        </variant>\n  </variants> \n```\n\n####transform.sh\n - input: the name of target application, the name of output file, environment variable.\n - output: the instance of having optimised, the name of output file\n\n###Initializing object\n\n`C.Generator(Name,Path,Parameters)`\n\n- Name: the name of analysis(the file name of the configuration file)\n- Path: the path of configuration file\n- Feature: the received parameters\n\n##Extractor\n###functional description of extractor\n\ninstance analyzer, in charge of static analyzing, environment analyzing and input analyzing of instance. Every \nextractor analyze the instance in the general through including one or multiple analyser objects. The result of\nanalyzing could produce the parameters, predict and knoledge mining.\n\n###Customizing\n\nleveraging the input parameters, instantiate the customized objects.\n\n###Initializing object\n\n`C.Extractor$new(analysers)`\n- analysers: the table object appointing the extractor of feature.\n\n###example\n\n```\n# create a list that contains hpsFrontend-flop_intensity\nanalyser.hpsFrontend<-list(hpsFrontend=c(\"flop_intensity\"))\n#init an extractor object using previous list\nmyextractor<-C.Extractor$new(list(hpsFrontend=analyser.hpsFrontend))\n```\n\n##Producer\n###functional description of producer\nthe base class of producer, defining the interface method of instantiating producer. producer optimise the \nprocess of producing parameters, and by using the result of analyzing instance and the evaluation of last time\nimplement various complex algorithm including heuristic seaching method, exhaustive searching method and model \npredicting method.\n\n###Customizing\n\ncustomise complex producer by implementing interface method--getParameter.\n\n###base class: `C. Producer()` :\n\n`getParameter(step,extractor.result,score)`:\n- step: current interation step\n- extractor.result: running instance anf analyzing features\n- score: the score of parameter in the last time\n\n###example:\n```\n# an exhaustion search producer\nC.Producer.Exhaustion<-setRefClass(\n  \"C.Producer.Exhaustion\",\n  contains=\"C.Producer\",\n  fields = list(parameter.space=\"data.frame\"),\n  methods = list(\n    #Init function\n    initialize=function(parameter.space){\n    parameter.space<<-parameter.space\n    },\n    #Implemente the interface method\n    getParameter=function(step,extractor.result,score)\n    {\n      if(step<nrow(parameter.space))\n        return(parameter.space[step,])\n    }\n  )\n)\n# a greedy search producer\nC.Producer.Greedy<-setRefClass(\n  \"C.Producer.Greedy\",\n  contains=\"C.Producer\",\n  fields = list(parameter.range=\"list\",#list(p1=c(1,2,3..),p2=c(1,2,3..)..)\n                v.idx =\"numeric\",\n                v.score =\"numeric\",\n                v.pos =\"numeric\",\n                local.optimal= \"data.frame\"),\n  methods = list(\n    #init function\n    initialize=function(parameter.range=list()){\n      parameter.range<<-parameter.range\n    },\n    #Implemente the interface method\n    getParameter=function(step,extractor.result,last.score)\n    {\n      if(step==1)\n      {\n        local.optimal<-default.parameters\n        v.idx<<-1\n        v.score<<-c()\n        v.pos<<-0\n      }\n      else if(v.pos<v.length)\n      { \n        v.pos<<-v.pos+1\n        v.score[v.pos]<<-last.score\n      }else{#finish local optimal search for a parameter\n        optimal.pos<-which.max(v.score)\n        local.optimal[[v.idx]]<<-parameter.range[[v.idx]][optimal.pos]\n        v.idx<<-v.idx+1\n        if(v.idx>parameter.number)\n          return (data.frame())\n        v.score<<-c()\n        v.pos<<-0\n      }\n      new.parameter<-local.optimal\n      new.parameter[[v.idx]]<-parameter.range[[v.idx]][v.pos+1]\n      return (new.parameter)\n    }\n  )\n)\n```\n\n##Optimizer\n###functional description of optimiser\n\noptimise the instance including code change, generating optimising variant, environment set. Every optimiser only \ncontain a generator for optimising variant currently.\n\n###Customizing\n\ninstantiating customised object by using the input parameter.\n\n###Initializing object\n\n`C.Optimizer(generator.name,output.name)`\n\n- generator.name: optimising variant generator\n- output.name: the output of optimising variant, default: \"optimized.cpp\"\n\n###example\n\n```\n#init an optimizer use hpsGen which is a code generator for stencil \nmyoptimizer<-C.Optimizer$new(generator.name=\"hpsGen\")\n```\n\n##Evaluator\n###functional description of evaluator\n\nevaluate the running instance during the process of autotuning, including obtaining the performance index,\nscore index and so on. Every evaluator include one or mutiple analyser objects for evaluating the optimising \nvariant index. Every evaluating index need to associate one  evaluation function. When the index is enough, \nreturn 0, otherwise return a negative number. Absolute number mean the distance to requirement. The evalutor \nfinally return a tatal score--sum of all evaluation index. When then total score is 0, autotuning is  convergent.\n\n###Customizing\n\ninstantiating customised object by using the input parameter.\n\n###Initializing object\n\n`C.Evaluator(sub.evaluators)`\n- sub.evaluators: include multiple evaluators. the index is the name of evaluator. the value is the table of evaluator\nfunction.\n\n###example\n```\n# create a sub.evaluaor, which is list of feautres to evluate functions  \nsub.evaluator.tau<-list(P_WALL_CLOCK_TIME=function(x){if(x>100) return (100-x) else return(0)})\n#init a C.Evaluator object\nmyevaluator<-C.Evaluator$new(sub.evaluators=list(tau=sub.evaluator.tau)) \n```\n\n##example: implementing a full tuning\n\n```\n# create a tuner\nmytuner<-C.Tuner$new(app=app,optimizer=myoptimizer,evaluator=myevaluator,producer =myproducer,need.store=TRUE)\n# perform tuning\nmytuner$tune()\n# output best parameters\nprint(mytuner$best.parameters)\n```\n\n\n"
  },
  {
    "path": "analysis_module/appinfo/analysis.sh",
    "content": "#!/bin/bash\n \nsource /home/lyl/.bashrc\nRscript $(cd \"$(dirname \"$0\")\"; pwd)/appinfo.R $1 \n\n\n\n"
  },
  {
    "path": "analysis_module/appinfo/appinfo.R",
    "content": "library(\"XML\")\n\nbashrc<-\"/home/lyl/.bashrc\"\nanalysername<-\"appinfo\"\nappinfo.list<-list() \n\nargs<-commandArgs(T)\nappname<-args[1]\nappinfo.list$MD5<-gsub(\" .*\",\"\",system(paste0(\"md5sum \",appname),intern = TRUE))\n\n\n\ndoc = newXMLDoc()\nfsnode<-newXMLNode(name=\"features\",doc=doc)\nfor(i in 1:length(appinfo.list))\n{ \n  fnode<-newXMLNode(name = \"feature\",parent = fsnode)\n  addChildren(fnode,\n              newXMLNode(name=\"name\",names(appinfo.list[i])),\n              newXMLNode(name=\"value\",appinfo.list[[i]])\n  )\n  \n  \n}\nrfilename<-paste0(Sys.time(),analysername,\"anaylsisresult.xml\")\nrfilename<-sub(\":\",\"\",rfilename)\nrfilename<-sub(\"-\",\"\",rfilename)\nrfilename<-sub(\" \",\"\",rfilename)\noutput<-saveXML(doc,file=rfilename,prefix = sprintf(\"<!--this is a file contain the analysis result for %s features--> \",analysername))\ncat(output)\n\n  "
  },
  {
    "path": "analysis_module/appinfo/featureinfo.xml",
    "content": "<!--this is a file contain the analysis result for EnvGather features-->\n<features> \n    <feature>     \n        <name>MD5</name>  \n        <datatype>category</datatype> \n        <type>static</type>   \n        <description>calculates and verifies 128-bit MD5 hashes, as described in RFC 1321</description> \n        <avail>TRUE</avail> \n        <enable_variable>ENABLE_MD5</enable_variable> \n    </feature> \n</features>\n"
  },
  {
    "path": "analysis_module/envinfo/EnvGather.R",
    "content": "library(\"XML\")\n\nbashrc<-\"/home/lyl/.bashrc\"\n\nanalysername<-\"EnvGather\"\nenvlist<-list()\n\ncpuinfo<-system(\"lscpu\",intern = TRUE)\nmeminfo<-system(\"cat /proc/meminfo\",intern = TRUE)\ninfo<-c(cpuinfo,meminfo)\nfor(i in info)\n{\n  tmp<-unlist(strsplit(i,\": *\"))\n  \n  if(tmp[1]==\"Architecture\")\n    envlist[tmp[1]]<-as.character(tmp[2])\n  \n  if(tmp[1]==\"CPUs\")\n    envlist[tmp[1]]<-as.numeric(tmp[2])\n  \n  if(tmp[1]==\"CPU MHz\")\n    envlist[sub(\" \",\"_\",tmp[1])]<-as.numeric(tmp[2])\n  \n  if(tmp[1]==\"Threads per core\")\n    envlist[sub(\" \",\"_\",tmp[1])]<-as.numeric(tmp[2])\n  \n  if(tmp[1]==\"Cores per socket\")\n    envlist[sub(\" \",\"_\",tmp[1])]<-as.numeric(tmp[2])\n  \n  if(tmp[1]==\"Byte Order\")\n    envlist[sub(\" \",\"_\",tmp[1])]<-as.character(tmp[2])\n  \n    if(tmp[1]==\"Sockets\")\n      envlist[sub(\" \",\"_\",tmp[1])]<-as.numeric(tmp[2])\n  \n  if(tmp[1]==\"NUMA nodes\")\n    envlist[sub(\" \",\"_\",tmp[1])]<-as.numeric(tmp[2])\n  \n  if(tmp[1]==\"L1d cache\")\n    envlist[\"L1d_cache_K\"]<-as.numeric(sub(\"K\",\"\",tmp[2]))\n  \n  if(tmp[1]==\"L1i cache\")\n    envlist[\"L1i_cache_K\"]<-as.numeric(sub(\"K\",\"\",tmp[2]))\n  \n  if(tmp[1]==\"L2 cache\")\n    envlist[\"L2_cache_K\"]<-as.numeric(sub(\"K\",\"\",tmp[2]))\n  \n  if(tmp[1]==\"L3 cache\")\n    envlist[\"L3_cache_K\"]<-as.numeric(sub(\"K\",\"\",tmp[2]))\n  \n  if(tmp[1]==\"MemTotal\")\n    envlist[\"MemTotal_K\"]<-as.numeric(sub(\"kB\",\"\",tmp[2]))\n  \n  \n}\nenvlist[\"OS_version\"]<-system(\"head -n 1 /etc/issue\",intern = TRUE)\n\nenvlist[\"gcc_version\"]<-system(sprintf(\"source %s; gcc -dumpversion;\",bashrc),intern = TRUE)\n\nenvlist[\"icc_version\"]<-system(sprintf(\"source %s; icc -dumpversion;\",bashrc),intern = TRUE)\n\nenvlist[\"nvcc_version\"]<-gsub(\".*release *|,.*\",\"\",system(sprintf(\"source %s; nvcc --version | grep release\",bashrc),intern = TRUE))\n\n\n\n\ndoc = newXMLDoc()\nfsnode<-newXMLNode(name=\"features\",doc=doc)\nfor(i in 1:length(envlist))\n{ \n  fnode<-newXMLNode(name = \"feature\",parent = fsnode)\n  addChildren(fnode,\n              newXMLNode(name=\"name\",names(envlist[i])),\n              newXMLNode(name=\"value\",envlist[[i]])\n  )\n  \n  \n}\nrfilename<-paste0(Sys.time(),analysername,\"anaylsisresult.xml\")\nrfilename<-sub(\":\",\"\",rfilename)\nrfilename<-sub(\"-\",\"\",rfilename)\nrfilename<-sub(\" \",\"\",rfilename)\noutput<-saveXML(doc,file=rfilename,prefix = sprintf(\"<!--this is a file contain the analysis result for %s features--> \",analysername))\ncat(output)\n\n\n# \n# featureinfo_doc = newXMLDoc()\n# fsnode<-newXMLNode(name=\"features\",doc=featureinfo_doc)\n# for(i in 1:length(envlist))\n# { \n#   fnode<-newXMLNode(name = \"feature\",parent = fsnode)\n#   if(is.numeric(envlist[[i]]))\n#     type<-\"numerical\"\n#   else\n#     type<-\"category\"\n#   \n#   addChildren(fnode,\n#               newXMLNode(name=\"name\",names(envlist[i])),\n#               newXMLNode(name=\"datatype\",type),\n#               newXMLNode(name=\"type\",\"static\"),\n#               newXMLNode(name=\"description\",\"As name shows\"),\n#               newXMLNode(name=\"avail\",\"TRUE\"),\n#               newXMLNode(name=\"enable_variable\",paste0(\"ENABLE_\",names(envlist[i])))\n#   )\n#   \n# \n# }\n# \n# output<-saveXML(featureinfo_doc,file=\"featureinfo.xml\",prefix = sprintf(\"<!--this is a file contain the analysis result for %s features--> \",analysername))\n\n"
  },
  {
    "path": "analysis_module/envinfo/analysis.sh",
    "content": "#!/bin/bash\n \nsource /home/lyl/.bashrc\nRscript $(cd \"$(dirname \"$0\")\"; pwd)/EnvGather.R\n\n\n\n"
  },
  {
    "path": "analysis_module/envinfo/featureinfo.xml",
    "content": "<!--this is a file contain the analysis result for EnvGather features-->  <features>   <feature>     <name>Architecture</name>     <datatype>category</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_Architecture</enable_variable>   </feature>   <feature>     <name>Byte_Order</name>     <datatype>category</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_Byte_Order</enable_variable>   </feature>   <feature>     <name>CPU_MHz</name>     <datatype>numerical</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_CPU_MHz</enable_variable>   </feature>   <feature>     <name>L1d_cache_K</name>     <datatype>numerical</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_L1d_cache_K</enable_variable>   </feature>   <feature>     <name>L1i_cache_K</name>     <datatype>numerical</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_L1i_cache_K</enable_variable>   </feature>   <feature>     <name>L2_cache_K</name>     <datatype>numerical</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_L2_cache_K</enable_variable>   </feature>   <feature>     <name>L3_cache_K</name>     <datatype>numerical</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_L3_cache_K</enable_variable>   </feature>   <feature>     <name>MemTotal_K</name>     <datatype>numerical</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_MemTotal_K</enable_variable>   </feature>   <feature>     <name>OS_version</name>     <datatype>category</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_OS_version</enable_variable>   </feature>   <feature>     <name>gcc_version</name>     <datatype>category</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_gcc_version</enable_variable>   </feature>   <feature>     <name>icc_version</name>     <datatype>category</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_icc_version</enable_variable>   </feature>   <feature>     <name>nvcc_version</name>     <datatype>category</datatype>     <type>static</type>     <description>As name shows</description>     <avail>TRUE</avail>     <enable_variable>ENABLE_nvcc_version</enable_variable>   </feature> </features>"
  },
  {
    "path": "analysis_module/paktimer/Makefile",
    "content": "CXX=gcc\nINCLUDES=-I.\nCXXFLAGS=$(INCLUDES)\n\ndefault: \n\t$(CXX) paktimer.c -o paktimer \nclean::\n\t-rm -f  paktimer\n"
  },
  {
    "path": "analysis_module/paktimer/analysis.sh",
    "content": "#!/bin/bash\n#export ENABLE_PAKTIME=TRUE\nTIMEENABLE=`env |grep ENABLE_PAKTIME | grep TRUE`\nif [ $TIMEENABLE = \"ENABLE_PAKTIME=TRUE\" ];then   \n    $(cd \"$(dirname \"$0\")\"; pwd)/paktimer $1 1>/dev/null 2>/dev/null\n    time=`cat temp.time`\n    rm temp.time result.xml\n    echo \"<features>  \n    <feature>\n    <name>time</name>\n    <value>\"$time\"</value>\n    </feature> \n    </features>\">>result.xml \n    echo \"result.xml\"\nfi\n\n\n\n\n"
  },
  {
    "path": "analysis_module/paktimer/featureinfo.xml",
    "content": "<features>\n    <feature>\n        <type>dynamic</type>\n        <name>time</name>\n        <description>the execution time of a given application</description>\n        <enable_variable>ENABLE_PAKTIME</enable_variable>\n        <datatype>numerical</datatype>\n    </feature>\n</features>\n"
  },
  {
    "path": "analysis_module/paktimer/paktimer.c",
    "content": "#include <stdio.h>\n#include <sys/time.h>\nstruct timeval t1;\nstruct timeval t2;\n\nint main(int argc,char** argv)\n{\n    FILE *fp;\n    double time;\n    //printf(\"the target file is %s \\n\", argv[1]);\n    gettimeofday(&t1,0);\n    system(argv[1]);\n    gettimeofday(&t2,0);\n    time = ((((1000000.0 * (t2.tv_sec - t1.tv_sec)) + t2.tv_usec) - t1.tv_usec) / 1000000.0);\n    \n    if(fp=fopen(\"temp.time\",\"wb\"))\n        fprintf(fp,\"%.4f\",time);\n\n    return 0;\n}\n"
  },
  {
    "path": "analysis_module/tau/analysis.sh",
    "content": "#!/bin/bash\nsource /home/lyl/.bashrc\nexport PATH=/home/lyl/tools/tau2.23_icpc_pdt_papi/x86_64/bin:$PATH\n\n\nexport TAU_MAKEFILE=/home/lyl/tools/tau2.23_icpc_pdt_papi/x86_64/lib/Makefile.tau-icpc-papi-pdt\nexport TAU_THROTTLE=0\n\ni=1\nfor f in `env |grep ENABLE_ | grep TRUE`\ndo\n    FNAME=${f#ENABLE_}\n    FNAME=${FNAME%%=*}\n    export COUNTER${i}=$FNAME\n    let i+=1\ndone\n\n\n\n\nicpc_flag=$icpc_flag\nicpc_flag=$icpc_flag\nicpc_flag=$icpc_flag\nicpc_flag=$icpc_flag\nicpc_flag=$icpc_flag\n\n\n\n#CC=icc\nCC=tau_cxx.sh\nrm MULTI__P* -rf\n$CC $icpc_flag -c  -vec-report2  $1 -o mid.o  2>/dev/null 1>/dev/null\n$CC $icpc_flag mid.o main.cpp  -o myexe 2>/dev/null 1>/dev/null\n\n./myexe 2>/dev/null 1>/dev/null\n\n\nRscript $(cd \"$(dirname \"$0\")\"; pwd)/outputformat.R\n\nrm *.o\nrm myexe\n\n\n\n"
  },
  {
    "path": "analysis_module/tau/featureinfo.xml",
    "content": "<!--this is a file describe feature extracted by XXX--> \n<features>  \n    <feature>     <name>P_WALL_CLOCK_TIME </name>     <description>Time cost of target application</description> \n        <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_P_WALL_CLOCK_TIME </enable_variable> <datatype>numerical</datatype> \n    </feature>\n    <feature>     <name>PAPI_REF_CYC </name>     <description>Reference clock cycles</description> \n        <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_REF_CYC </enable_variable>     <datatype>numerical</datatype>  \n    </feature> \n    <feature>     <name>PAPI_VEC_DP  </name>     <description>Double precision vector/SIMD instructions</description> \n        <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_VEC_DP  </enable_variable>     <datatype>numerical</datatype>  \n</feature>  \n<feature>     <name>PAPI_VEC_SP  </name>     <description>Single precision vector/SIMD instructions</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_VEC_SP  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_DP_OPS  </name>     <description>Floating point operations; optimized to count scaled double precision vector operations</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_DP_OPS  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_SP_OPS  </name>     <description>Floating point operations; optimized to count scaled single precision vector operations</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_SP_OPS  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FP_OPS  </name>     <description>Floating point operations</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_FP_OPS  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FNV_INS </name>     <description>Floating point inverse instructions</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FNV_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FSQ_INS </name>     <description>Floating point square root instructions</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FSQ_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FDV_INS </name>     <description>Floating point divide instructions</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_FDV_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FAD_INS </name>     <description>Floating point add instructions</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FAD_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FML_INS </name>     <description>Floating point multiply instructions</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FML_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_TCW  </name>     <description>Level 3 total cache writes</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_TCW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_TCW  </name>     <description>Level 2 total cache writes</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_TCW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_TCW  </name>     <description>Level 1 total cache writes</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_TCW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_TCR  </name>     <description>Level 3 total cache reads</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_TCR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_TCR  </name>     <description>Level 2 total cache reads</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_TCR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_TCR  </name>     <description>Level 1 total cache reads</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_TCR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_TCA  </name>     <description>Level 3 total cache accesses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_TCA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_TCA  </name>     <description>Level 2 total cache accesses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_TCA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_TCA  </name>     <description>Level 1 total cache accesses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_TCA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_TCH  </name>     <description>Level 3 total cache hits</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L3_TCH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_TCH  </name>     <description>Level 2 total cache hits</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L2_TCH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_TCH  </name>     <description>Level 1 total cache hits</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_TCH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_ICW  </name>     <description>Level 3 instruction cache writes</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L3_ICW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_ICW  </name>     <description>Level 2 instruction cache writes</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L2_ICW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_ICW  </name>     <description>Level 1 instruction cache writes</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_ICW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_ICR  </name>     <description>Level 3 instruction cache reads</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_ICR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_ICR  </name>     <description>Level 2 instruction cache reads</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_ICR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_ICR  </name>     <description>Level 1 instruction cache reads</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_ICR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_ICA  </name>     <description>Level 3 instruction cache accesses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_ICA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_ICA  </name>     <description>Level 2 instruction cache accesses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_ICA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_ICA  </name>     <description>Level 1 instruction cache accesses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_ICA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_ICH  </name>     <description>Level 3 instruction cache hits</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L3_ICH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_ICH  </name>     <description>Level 2 instruction cache hits</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_ICH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_ICH  </name>     <description>Level 1 instruction cache hits</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_ICH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_DCW  </name>     <description>Level 3 data cache writes</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_DCW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_DCW  </name>     <description>Level 2 data cache writes</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_DCW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_DCW  </name>     <description>Level 1 data cache writes</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_DCW  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_DCR  </name>     <description>Level 3 data cache reads</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_DCR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_DCR  </name>     <description>Level 2 data cache reads</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_DCR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_DCR  </name>     <description>Level 1 data cache reads</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_DCR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_DCA  </name>     <description>Level 3 data cache accesses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_DCA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_DCA  </name>     <description>Level 2 data cache accesses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_DCA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_DCA  </name>     <description>Level 1 data cache accesses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_DCA  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_DCH  </name>     <description>Level 2 data cache hits</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_DCH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_DCH  </name>     <description>Level 1 data cache hits</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L1_DCH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_SYC_INS </name>     <description>Synchronization instructions completed</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_SYC_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_LST_INS </name>     <description>Load/store instructions completed</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_LST_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_TOT_CYC </name>     <description>Total cycles</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_TOT_CYC </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FP_STAL </name>     <description>Cycles the FP unit(s) are stalled</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FP_STAL </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_RES_STL </name>     <description>Cycles stalled on any resource</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_RES_STL </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_VEC_INS </name>     <description>Vector/SIMD instructions (could include integer)</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_VEC_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BR_INS  </name>     <description>Branch instructions</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_BR_INS  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_SR_INS  </name>     <description>Store instructions</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_SR_INS  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_LD_INS  </name>     <description>Load instructions</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_LD_INS  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FP_INS  </name>     <description>Floating point instructions</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_FP_INS  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_INT_INS </name>     <description>Integer instructions</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_INT_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_TOT_INS </name>     <description>Instructions completed</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_TOT_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_TOT_IIS </name>     <description>Instructions issued</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_TOT_IIS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FMA_INS </name>     <description>FMA instructions completed</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FMA_INS </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BR_PRC  </name>     <description>Conditional branch instructions correctly predicted</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_BR_PRC  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BR_MSP  </name>     <description>Conditional branch instructions mispredicted</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_BR_MSP  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BR_NTK  </name>     <description>Conditional branch instructions not taken</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_BR_NTK  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BR_TKN  </name>     <description>Conditional branch instructions taken</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_BR_TKN  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BR_CN   </name>     <description>Conditional branch instructions</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_BR_CN   </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BR_UCN  </name>     <description>Unconditional branch instructions</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_BR_UCN  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_HW_INT  </name>     <description>Hardware interrupts</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_HW_INT  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FUL_CCY </name>     <description>Cycles with maximum instructions completed</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FUL_CCY </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_STL_CCY </name>     <description>Cycles with no instructions completed</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_STL_CCY </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FUL_ICY </name>     <description>Cycles with maximum instruction issue</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FUL_ICY </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_STL_ICY </name>     <description>Cycles with no instruction issue</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_STL_ICY </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_MEM_WCY </name>     <description>Cycles Stalled Waiting for memory writes</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_MEM_WCY </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_MEM_RCY </name>     <description>Cycles Stalled Waiting for memory Reads</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_MEM_RCY </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_MEM_SCY </name>     <description>Cycles Stalled Waiting for memory accesses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_MEM_SCY </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_CSR_TOT </name>     <description>Total store conditional instructions</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_CSR_TOT </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_CSR_SUC </name>     <description>Successful store conditional instructions</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_CSR_SUC </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_CSR_FAL </name>     <description>Failed store conditional instructions</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_CSR_FAL </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_TLB_SD  </name>     <description>Translation lookaside buffer shootdowns</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_TLB_SD  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_DCH  </name>     <description>Level 3 data cache hits</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L3_DCH  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_PRF_DM  </name>     <description>Data prefetch cache misses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_PRF_DM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BTAC_M  </name>     <description>Branch target address cache misses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_BTAC_M  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_STM  </name>     <description>Level 2 store misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_STM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_LDM  </name>     <description>Level 2 load misses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L2_LDM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_STM  </name>     <description>Level 1 store misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L1_STM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_LDM  </name>     <description>Level 1 load misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L1_LDM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_TLB_TL  </name>     <description>Total translation lookaside buffer misses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_TLB_TL  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_TLB_IM  </name>     <description>Instruction translation lookaside buffer misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_TLB_IM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_TLB_DM  </name>     <description>Data translation lookaside buffer misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_TLB_DM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_LSU_IDL </name>     <description>Cycles load/store units are idle</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_LSU_IDL </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FPU_IDL </name>     <description>Cycles floating point units are idle</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FPU_IDL </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_FXU_IDL </name>     <description>Cycles integer units are idle</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_FXU_IDL </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_BRU_IDL </name>     <description>Cycles branch units are idle</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_BRU_IDL </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_STM  </name>     <description>Level 3 store misses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L3_STM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_LDM  </name>     <description>Level 3 load misses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L3_LDM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_CA_ITV  </name>     <description>Requests for cache line intervention</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_CA_ITV  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_CA_INV  </name>     <description>Requests for cache line invalidation</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_CA_INV  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_CA_CLN  </name>     <description>Requests for exclusive access to clean cache line</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_CA_CLN  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_CA_SHR  </name>     <description>Requests for exclusive access to shared cache line</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_CA_SHR  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_CA_SNP  </name>     <description>Requests for a snoop</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_CA_SNP  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_TCM  </name>     <description>Level 3 cache misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L3_TCM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_TCM  </name>     <description>Level 2 cache misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_TCM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_TCM  </name>     <description>Level 1 cache misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L1_TCM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_ICM  </name>     <description>Level 3 instruction cache misses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L3_ICM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L3_DCM  </name>     <description>Level 3 data cache misses</description>     <type>dynamic</type>     <avail>FALSE</avail>     <enable_variable>ENABLE_PAPI_L3_DCM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_ICM  </name>     <description>Level 2 instruction cache misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_ICM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L2_DCM  </name>     <description>Level 2 data cache misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L2_DCM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_ICM  </name>     <description>Level 1 instruction cache misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L1_ICM  </enable_variable>     <datatype>numerical</datatype>   </feature>   <feature>     <name>PAPI_L1_DCM  </name>     <description>Level 1 data cache misses</description>     <type>dynamic</type>     <avail>TRUE</avail>     <enable_variable>ENABLE_PAPI_L1_DCM  </enable_variable>     <datatype>numerical</datatype>   </feature> </features>\n"
  },
  {
    "path": "analysis_module/tau/featureofPAPI.r",
    "content": "library(XML)\n\npapi_str<-system(\"source ~/.bashrc; papi_avail\",intern=TRUE)\nstr(papi_str)\nbg<-FALSE\nfor(oneline in papi_str)\n{\n  tmp<-unlist(strsplit(oneline,\"[ ][ ][ ]*\"))\n  \n  if(length(tmp)>2 && tmp[2]==\"Name\")\n  {\n    featuredata<<-data.frame(name=character(),avail=logical(),description=character(),enable_variable=character(),stringsAsFactors=FALSE)\n    bg<-TRUE\n  }else if(bg){\n    if(length(tmp)<2) \n      break;\n    \n    part1<-unlist(strsplit(oneline,\"0x\"))\n    namestr<-part1[1]\n    \n    part2<-unlist(strsplit(part1[2],\"[ ][ ][ ]*\"))\n    \n    Avail<-part2[2]\n    if(Avail==\"Yes\")\n      Avail<- TRUE\n    else\n      Avail<-FALSE\n    \n    featuredata<<-rbind(data.frame(name=namestr,description=part2[4],avail=Avail,enable_variable=sprintf(\"ENABLE_%s\",namestr),stringsAsFactors=FALSE),featuredata)\n  }\n}\n\nfeaturedata$type<-\"dynamic\"\nfeaturedata$datatype<-\"numerical\"\n\n\ndoc = newXMLDoc()\nfsnode<-newXMLNode(name=\"features\",doc=doc)\nfor(i in 1:nrow(featuredata))\n{ \n  feature<-featuredata[i,]\n  fnode<-newXMLNode(name = \"feature\",parent = fsnode)\n  addChildren(fnode,\n              newXMLNode(name=\"name\",feature$name),\n              newXMLNode(name=\"description\",feature$description),\n              newXMLNode(name=\"type\",feature$type),\n              newXMLNode(name=\"avail\",feature$avail),\n              newXMLNode(name=\"enable_variable\",feature$enable_variable),\n              newXMLNode(name=\"datatype\",feature$datatype)\n  )\n  \n}\nsaveXML(doc,file=\"./featureinfo.xml\",prefix = \"<!--this is a file describe feature extracted by XXX--> \")\n"
  },
  {
    "path": "analysis_module/tau/outputformat.R",
    "content": "library(\"XML\")\nanalysername<-\"tau\"\nmetrics.vec<- system(\"env |grep ENABLE\",intern = TRUE)\n\nmetrics.list<-list()\nfor(m in metrics.vec)\n{\n  m.name<-gsub(\"ENABLE_||=TRUE\",\"\",m)\n  if(length(metrics.vec)>1)\n    r<-system(paste0(\"tail MULTI__\",m.name,\"/profile.0.0.0 |grep main;\"),intern = TRUE)\n  else\n    r<-system(paste0(\"tail profile.0.0.0 |grep main;\"),intern = TRUE)\n  r<-unlist(strsplit(r,'\"'))[3]\n  r<-unlist(strsplit(r,' '))[5]\n  metrics.list[m.name]<-r\n}\n\n\n\ndoc = newXMLDoc()\nfsnode<-newXMLNode(name=\"features\",doc=doc)\nfor(i in 1:length(metrics.list))\n{ \n  fnode<-newXMLNode(name = \"feature\",parent = fsnode)\n  addChildren(fnode,\n              newXMLNode(name=\"name\",names(metrics.list[i])),\n              newXMLNode(name=\"value\",metrics.list[[i]])\n  )\n  \n  \n}\nrfilename<-paste0(Sys.time(),analysername,\"anaylsisresult.xml\")\nrfilename<-sub(\":\",\"\",rfilename)\nrfilename<-sub(\"-\",\"\",rfilename)\nrfilename<-sub(\" \",\"\",rfilename)\noutput<-saveXML(doc,file=rfilename,prefix = sprintf(\"<!--this is a file contain the analysis result for %s features--> \\n\",analysername))\ncat(output)"
  },
  {
    "path": "applications/multiplyexample.c",
    "content": "#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n#define DATATYPE float\n#define NX 3000\n#define NY 3000\n#define ITER 30\nDATATYPE a[NX][NY];\nDATATYPE b[NX][NY];\nDATATYPE c[NX][NY];\nint main()\n{\n    int i,j,t;\n\n    for(i=0;i<NX;i++)\n        for(j=0;j<NY;j++)\n        {\n            a[i][j]=rand();\n            b[i][j]=rand();\n            c[i][j]=rand();\n        }\n    for(t=0;t<ITER;t++)\n        for(i=0;i<NX;i++)\n            for(j=0;j<NY;j++)\n                c[i][j]=a[i][j]*b[i][j]/c[j][i];\n\n    //printf(\"result is %.2f\\n\",c[100][100]);\n    return 0;\n}\n"
  },
  {
    "path": "applications/result.xml",
    "content": "<features>  \n    <feature>\n    <name>time</name>\n    <value>1.7945</value>\n    </feature> \n    </features>\n"
  },
  {
    "path": "framework/DBModule/functions.R",
    "content": "OpenDB <- function() {\n  # Open a SQL conn if the global.conn has not been initialized,\n  # and save the conn to global.conn, or just return global.conn\n  #\n  # Returns:\n  #   The conn opened or geted from the global\n  if(!exists(\"global.conn\")) \n    global.conn <<- odbcConnect(datasource,database.user,database.pwd)\n  conn <- global.conn\n  return(conn)\n}\n\n\nCloseDB <- function() {\n  # Close the connection \n  #\n  # Args:\n  #   conn: The conn opened by performanceDB.SQL.dbopen\n  if(exists(\"global.conn\")) {\n    close(global.conn)\n    rm(global.conn)\n  }\n}\n\nCheckTableExistence<-function(dbname,tbname){\n  # check if a table 'tbname' exist in database 'dbname' \n  # is specificed by format\n  #\n  # Returns:\n  # TRUE if exist, or FALSE if not exist\n  cmd.str <- sprintf('show tables in %s like \"%s\";', \n                     dbname, tbname)\n  conn <- OpenDB()\n  result <- sqlQuery(conn,cmd.str)\n  if(!is.data.frame(result))\n    stop(paste0(\"error when execute sql command in CreateTable: \",result))\n  if(nrow(result)==0)\n    return (FALSE)\n  else\n    return (TRUE)\n}\n\nCreateTable<-function(format,dbname,tbname){\n  # create a table 'dbname' in datable 'dbname'. The structure of table \n  # is specificed by dataframe 'format'\n  #\n  # Returns:\n  # TRUE if success, or FALSE if fail\n  \n  cmd.str <- sprintf('show tables in %s like \"%s\";', \n                     dbname, tbname)\n  conn <- OpenDB()\n  result <- sqlQuery(conn,cmd.str)\n  if(!is.data.frame(result))\n    stop(paste0(\"error when execute sql command in CreateTable: \",result))\n  if(nrow(result)==1)\n  {\n    print(\"there has existed table %s in database %s \",tbname,dbname)\n    return (FALSE)\n  }\n  \n  FormatTable<-function(format)\n  {\n    fmt.str<-\"id int(10) primary key not null auto_increment,\"\n    for(i in 1:nrow(format))\n    {\n      name<-format[i,]$name\n      datatype<-format[i,]$datatype\n      if(datatype==\"numerical\")\n        fmt.str<-paste0(fmt.str,name,\" DOUBLE\") \n      if(datatype==\"category\")\n        fmt.str<-paste0(fmt.str,name,\" VARCHAR(255)\") \n      if(datatype==\"boolen\")\n        fmt.str<-paste0(fmt.str,name,\" TINYINT\") \n      \n      if(i!=nrow(format))\n        fmt.str<-paste0(fmt.str,\",\")\n    }\n    return (fmt.str)\n  }\n  cmd.str<-sprintf(\"create table %s.%s (%s);\",dbname,tbname,FormatTable(format))\n  result <- sqlQuery(conn,cmd.str)\n  return(TRUE)  \n}\n\nCheckAndUpdateMainTableCol<-function(subtable.names,dbname=\"hpts\"){\n  # check if the main table contains colmun that connects to subtable.\n  # If not, alter the main table.\n  # Args:\n  #      subtable.names: the names of subtable that will connecte to main table\n  #      dbname: the name of database\n  #\n  \n  cmd.str<-sprintf(\"select COLUMN_NAME from information_schema.COLUMNS where table_name = 'main' and table_schema = '%s';\",dbname)\n  conn<-OpenDB()\n  result<-sqlQuery(conn,cmd.str)\n  \n  maintable.names<-as.character(result[[1]])\n  \n  notin.names<-subtable.names[!(subtable.names %in% maintable.names)]\n  if(length(notin.names)>0)\n    for(i in 1:length(notin.names))\n    {\n      result<-sqlQuery(conn,sprintf(\"alter table %s.main add %s int(10);\",dbname,notin.names[i]))\n    }\n}\n\nCheckAndUpdateTableStructure<-function(data.names,dbname=\"hpts\",tbname=\"main\"){\n  # check if the table 'tbname' contains column that named as data.names.\n  # If not, alter the table.\n  # Args:\n  #      data.names: the names of data that will be inserted to the table\n  #      dbname: the name of database\n  #      tbname: the name of table\n  \n  cmd.str<-sprintf(\"select COLUMN_NAME from information_schema.COLUMNS where table_name = '%s' and table_schema = '%s';\",tbname,dbname)\n  conn<-OpenDB()\n  result<-sqlQuery(conn,cmd.str)\n  \n  table.names<-as.character(result[[1]])\n  \n  not.in.names<-data.names[!(data.names %in% table.names)]\n  if(length(not.in.names)>0)\n    for(i in 1:length(not.in.names))\n    {\n      result<-sqlQuery(conn,sprintf(\"alter table %s.%s add %s int(10);\",dbname,tbname,not.in.names[i]))\n    }\n}\n\nStoreAnalysis<-function(analysis.results,override=TRUE,\n                        analysis_module.path=path.generator_tools)\n{\n  # store the analysis result to DB. \n  # Args:\n  #       analysis.results: a list that contain analysis result of mutiple analyzers\n  #       analysis_module.path: the directory path of analyzers\n  #\n  # Returns:\n  # the id in main table if success, or 0 if fail\n  key.analyser.names<-c(\"appinfo\",\"envinfo\")\n  for(ka in key.analyser.names)\n  { \n    if(length(analysis.results[[ka]])==0)\n      stop(sprintf(\"%s module can not be NULL!\",ka))\n  }\n  analyser.names<-names(analysis.results) \n  nonkey.analyser.names<-analyser.names[!analyser.names  %in% key.analyser.names]\n  \n  keytable.id<-data.frame(name=character(),value=integer(),stringsAsFactors = FALSE)\n  keytable.id.format<-data.frame(name=character(),datatype=character(),stringsAsFactors = FALSE)\n  nonkeytable.id<-data.frame(name=character(),value=integer(),stringsAsFactors = FALSE)\n  nonkeytable.id.format<-data.frame(name=character(),datatype=character(),stringsAsFactors = FALSE)\n  \n  # key\n  for(analyser in key.analyser.names)\n  {\n    result<-analysis.results[[analyser]]\n    format<-SerializeXmlDoc(paste0(analysis_module.path,analyser,\"/featureinfo.xml\"),\"datatype\")\n    if(CheckTableExistence(\"hpts\",analyser)==FALSE)\n      CreateTable(format,\"hpts\",analyser)\n    \n    if(override)\n    {\n      df<-SelectFromDB(result,format,\"hpts\",analyser)\n      if(nrow(df)>0)\n        sub.id<-df[1,]$id\n      else\n        sub.id<-InsertToDB(result,format,\"hpts\",analyser)\n    }\n    else\n      sub.id<-InsertToDB(result,format,\"hpts\",analyser)\n    subtable.id<-data.frame(name=analyser,value=sub.id,stringsAsFactors = FALSE)\n    subtable.id.format<-data.frame(name=analyser,datatype=\"numerical\",stringsAsFactors = FALSE)\n    keytable.id<-rbind(keytable.id,subtable.id)\n    keytable.id.format<-rbind(keytable.id.format,subtable.id.format)\n  }\n  \n  \n  #   non key\n  for(analyser in nonkey.analyser.names)\n  {\n    result<-analysis.results[[analyser]]\n    format<-SerializeXmlDoc(paste0(analysis_module.path,analyser,\"/featureinfo.xml\"),\"datatype\")\n    if(CheckTableExistence(\"hpts\",analyser)==FALSE)\n      CreateTable(format,\"hpts\",analyser)\n    \n    sub.id<-InsertToDB(result,format,\"hpts\",analyser)\n    subtable.id<-data.frame(name=analyser,value=sub.id,stringsAsFactors = FALSE)\n    subtable.id.format<-data.frame(name=analyser,datatype=\"numerical\",stringsAsFactors = FALSE)\n    nonkeytable.id<-rbind(nonkeytable.id,subtable.id)\n    nonkeytable.id.format<-rbind(nonkeytable.id.format,subtable.id.format)\n  }\n  \n  \n  \n  if(CheckTableExistence(\"hpts\",\"main\")==FALSE)\n  {\n    print(\"<h1>main table does not exist, please create a main table!<h1>\")\n    return(0)\n  }else{\n    subtable<-rbind(keytable.id,nonkeytable.id)\n    subtable.format<-rbind(keytable.id.format,nonkeytable.id.format)\n    #check if the table structure is same to subtable.format. if not, alter table structure in database\n    CheckAndUpdateMainTableCol(subtable.format$name,\"hpts\")\n    \n    \n    if(override)\n    {\n      target.row<-SelectFromDB(keytable.id,keytable.id.format,\"hpts\",\"main\")\n      if(nrow(target.row)>0)\n        UpdateForDB(keytable.id,keytable.id.format,nonkeytable.id,nonkeytable.id.format,\"hpts\",\"main\")\n      else\n        InsertToDB(subtable,subtable.format,\"hpts\",\"main\")\n      \n      newdata<-SelectFromDB(keytable.id,keytable.id.format,\"hpts\",\"main\")\n      mid<-newdata[1,]$id\n    }\n    else  \n    {\n      \n      mid<-InsertToDB(subtable,subtable.format,\"hpts\",\"main\")\n    }\n    return (mid)\n  }\n}\n\n\nStoreTransformation<-function(main.id, generator.results,analysis.results,override=TRUE,\n                              generator_module.path=path.generator_tools,\n                              analysis_module.path=path.analysis_tools)\n{\n  # store the main table id, generator parameters, analysis result to DB. \n  # Args:\n  #       generator.results: a list that contain data of a generator. The size of list is 1\n  #       generator_module.path: the directory path of generators\n  #       override: if override record that have same generator parameter and main.id\n  #       analysis.results: a list that contain analysis result of mutiple analyzers\n  #       analysis_module.path: the directory path of analyzers\n  #\n  # Returns:\n  # the id in main table if success, or 0 if fail\n  \n  #check if the generator.result size =1\n  if(length(generator.results)!=1)\n    stop(sprintf(\"Error length of generator.results in StoreResultForGeneratorToDB,should be 1 but actual be %d\",length(generator.results)))\n  \n  \n  # format analysis.results to subtable\n  subtable<-data.frame(name=character(),value=character(),stringsAsFactors = FALSE)\n  subtable.format<-data.frame(name=character(),value=character(),stringsAsFactors = FALSE)\n  for(i in 1:length(analysis.results))\n  {\n    analyser<-names(analysis.results[i])\n    result<-analysis.results[[i]]\n    format<-SerializeXmlDoc(paste0(analysis_module.path,analyser,\"/featureinfo.xml\"),\"datatype\")\n    \n    if(CheckTableExistence(\"hpts\",analyser)==FALSE)\n      CreateTable(format,\"hpts\",analyser)\n    \n    sub.id<-InsertToDB(result,format,\"hpts\",analyser)\n    \n    subtable<-rbind(subtable,data.frame(name=analyser,value=as.character(sub.id),stringsAsFactors = FALSE))\n    subtable.format<-rbind(subtable.format,data.frame(name=analyser,datatype=\"numerical\",stringsAsFactors = FALSE))\n  }\n  \n  #combine generator.parameter and subtable\n  generator.name<-names(generator.results[1])\n  generator.parameters<-generator.results[[1]]\n  generator.format<-SerializeXmlDoc(paste0(generator_module.path,generator.name,\"/variantinfo.xml\"),\"datatype\")\n  \n  generator.parameters<-rbind(generator.parameters,data.frame(name=\"instanceId\",value=as.character(main.id),stringsAsFactors = FALSE)) \n  generator.format<-rbind(generator.format,data.frame(name=\"instanceId\",datatype=\"numerical\",stringsAsFactors = FALSE))\n  \n  cond.parameters<-generator.parameters\n  cond.format<-generator.format\n  \n  generator.parameters<-rbind(generator.parameters,subtable) \n  generator.format<-rbind(generator.format,subtable.format)\n  \n  if(CheckTableExistence(\"hpts\",generator.name)==FALSE)\n    CreateTable(generator.format,\"hpts\",generator.name)\n  else \n    CheckAndUpdateTableStructure(generator.format$name,\"hpts\",generator.name)\n  \n  if(override)\n  {\n    target.row<-SelectFromDB(cond.parameters,cond.format,\"hpts\",generator.name)\n    if(nrow(target.row)>0)\n    {\n      UpdateForDB(cond.parameters,cond.format,subtable,subtable.format,\"hpts\",generator.name)\n      newdata<-SelectFromDB(generator.parameters,generator.format,\"hpts\",generator.name)\n      generator.table.id<-newdata[1,]$id\n    }\n    else\n      generator.table.id<-InsertToDB(generator.parameters,generator.format,\"hpts\",generator.name)\n  }\n  else  \n    generator.table.id<-InsertToDB(generator.parameters,generator.format,\"hpts\",generator.name)\n  \n  return(generator.table.id)\n}\n\nparseCombinedData<-function(name,data,datastr){\n  name<-sub(\" \",\"\",name)\n  r<-eval(parse(text=paste0(\"data.frame(name=character(),\",datastr,\"=character(),stringsAsFactors = FALSE)\")))  \n  if(length(data)==0)\n    stop(\"data is NULL in function parseCombinedData\")\n  if(is.list(data))\n  {\n    for(i in 1:length(data))\n    {\n      subname<-paste0(name,\"_\",i)\n      r<-rbind(r,parseCombinedData(subname,data[i][[datastr]],datastr))\n    }\n  }else{\n    #filter blank for features defination in xml\n    name<-gsub(\" \",\"\",name)\n    data<-gsub(\" \",\"\",data)\n    r<-eval(parse(text=paste0(\"data.frame(name=name,\",datastr,\"=data,stringsAsFactors = FALSE)\")))\n  }\n  return (r)\n}\n\n\n# serialize xml feature/variant file to a dataframe  \nSerializeXmlDoc<-function(doc.xml,datastr)\n{\n  doc.list<-xmlToList(doc.xml)\n  doc.seril<-eval(parse(text=paste0(\"data.frame(name=character(),\",datastr,\"=character())\")))  \n  for(i in 1:length(doc.list))\n  {\n    f<-doc.list[i]\n    if(names(f)!=\"feature\"&&names(f)!=\"variant\")\n      stop(sprintf(\"error format in xml with %s!\\n\",datastr))\n    \n    doc.seril<-eval(parse(text=paste0('rbind(doc.seril,parseCombinedData(f$',names(f),'$name,f$',names(f),'$',\n                                      datastr,',\"',datastr,'\"))')))\n  }\n  return(doc.seril)\n}\n\n\n\nGetEnableList<-function(doc.xml,Nameaskey=TRUE)\n{\n  doc.list<-xmlToList(doc.xml)\n  doc.seril<-data.frame(name=character(),datatype=character())\n  for(i in 1:length(doc.list))\n  {\n    f<-doc.list[i]\n    if(names(f)!=\"feature\"&&names(f)!=\"variant\")\n      stop(\"error format in xml with datatype!\\n\")\n    \n    tmp<-eval(parse(text=paste0('parseCombinedData(f$',names(f),\n                                '$name,f$',names(f),'$datatype,\"datatype\")')))\n    tmp$enable_variable<-eval(parse(text=paste0('f$',names(f),'$enable_variable')))\n    tmp$oldname<-gsub(\" \",\"\",eval(parse(text=paste0('f$',names(f),'$name'))))\n    doc.seril<-rbind(doc.seril,tmp)\n  }\n  enable.list<-list()\n  for(i in 1:nrow(doc.seril))\n  {\n    tmp<-doc.seril[i,] \n    enable_str<-sub(tmp$oldname,tmp$name,tmp$enable_variable)\n    if(Nameaskey)\n      enable.list[[tmp$name]]<-enable_str\n    else  \n      enable.list[[enable_str]]<-tmp$name\n  }\n  return(enable.list)\n}\n\nGetDatatypeList<-function(doc.xml)\n{\n  doc.seril<-SerializeXmlDoc(doc.xml,\"datatype\")\n  datatype.list<-list()\n  for(i in 1:nrow(doc.seril))\n  {\n    tmp<-doc.seril[i,] \n    datatype.list[[tmp$name]]<-tmp$datatype\n  }\n  return(datatype.list)\n}\n\n\n\n# unserialize a dataframe to a xml format file, which need a xmlformat file\nUnSerializeXmlDoc<-function(doc.seril,xmlformat)\n{\n  # subformat  \n  FillXMLNode<-function(subformat,data,name)\n  {\n    if(is.list(subformat))\n    {\n      fnode<-newXMLNode(name = \"value\",parent = fsnode);\n      for(i in 1:length(str))\n      {\n        subname<-paste0(name,\"_\",i);\n        addChildren(fnode,\n                    FillXMLNode(subformat[i],data,name)\n        );\n      }\n    }else{\n      value<-data[which(data$name==name),];\n      if(nrow(value)==0)\n        return (NA);\n      if(nrow(value)==1)\n      { \n        return (newXMLNode(name=\"value\",value));\n      }else{\n        stop(\"stop in Fill FillXMLNode, because there are two atrribute have same name\");\n      }\n    }\n  }\n  doc.xml = newXMLDoc();\n  fsnode<-newXMLNode(name=\"features\",doc=doc.xml);\n  xmlformat.list<-xmlToList(xmlformat);\n  for(i in 1:nrow(xmlformat.list))\n  { \n    feature<-xmlformat.list[i,]$feature;\n    subformat<-feature$value;\n    \n    xmlnode<-FillXMLNode(subformat,doc.seril,feature$name); \n    if(is.na(xmlnode))\n    { \n      next;\n    } else{\n      fnode<-newXMLNode(name = \"feature\",parent = fsnode);\n      addChildren(fnode,\n                  newXMLNode(name=\"name\",feature$name),\n                  xmlnode\n      );\n    }\n    \n  }\n  return (doc.xml);\n}\n\n\nInsertToDB<-function(data,format,\n                     dbname = \"hpts\", tbname = \"ttable\"){\n  # Perform a insert operation using 'data' in 'format'  to table 'tbname' of database 'dbname'\n  #\n  # Args:\n  #   data: The data need to insert to database, need be a dataframe\n  #   format: The format that specifics data structure and type\n  #   dbname: The database name\n  #   tbname: The table name\n  #\n  # Returns:\n  #   The last insert it\n  stopifnot(is.data.frame(data)==TRUE)\n  stopifnot(is.vector(data$name)==TRUE)\n  stopifnot(is.vector(data$value)==TRUE)\n  \n  formatvalue<-function(data,format)\n  {\n    values_str<-\"\"\n    for(i in 1:nrow(data))\n    {\n      fname<-data[i,]$name\n      value<-data[i,]$value\n      if(i!=1)\n        values_str<-paste0(values_str,\",\")\n      for(j in 1:nrow(format))\n      { \n        if(fname==format[j,]$name)\n        {\n          datatype<-format[j,]$datatype\n          if(datatype==\"numerical\")\n            values_str<-paste0(values_str,value) \n          if(datatype==\"category\")\n            values_str<-paste0(values_str,'\"',value,'\"') \n          if(datatype==\"boolen\")\n            values_str<-paste0(values_str,value) \n          break\n        }\n      } \n    }\n    return (values_str)\n  }\n  s1 <- paste(data$name, collapse = \",\")\n  \n  s2 <- formatvalue(data,format)\n  \n  cmd.str <- sprintf('insert into %s.%s(%s) values(%s);', dbname, tbname, s1, s2)\n  conn <- OpenDB()\n  result<-sqlQuery(conn, cmd.str)\n  \n  if(length(result)!=0)\n    stop(result)\n  \n  tableid <- sqlQuery(conn, \"select last_insert_id()\")\n  return(tableid[[1]])\n}\n\nSelectFromDB<-function(condition,format,\n                       dbname = \"hpts\", tbname = \"ttable\"){\n  # Perform a select operation using 'condition' in 'format'  to table 'tbname' of database 'dbname'\n  #\n  # Args:\n  #   condition: The condition of select, need be a dataframe\n  #   format: The format that specifics condition structure and type\n  #   dbname: The database name\n  #   tbname: The table name\n  #\n  # Returns:\n  #   The last insert it\n  stopifnot(is.data.frame(condition)==TRUE)\n  stopifnot(is.vector(condition$name)==TRUE)\n  stopifnot(is.vector(condition$value)==TRUE)\n  \n  FormatCondition<-function(condition,format)\n  {\n    condition.str<-\"\"\n    for(i in 1:nrow(condition))\n    {\n      fname<-condition[i,]$name\n      value<-condition[i,]$value\n      for(j in 1:nrow(format))\n      { \n        if(fname==format[j,]$name)\n        {\n          datatype<-format[j,]$datatype\n          if(datatype==\"numerical\")\n            condition.str<-sprintf(\" %s and %s=%s\",condition.str,fname,value) \n          if(datatype==\"category\")\n            condition.str<-sprintf(\" %s and %s='%s'\",condition.str,fname,value)  \n          if(datatype==\"boolen\")\n            condition.str<-sprintf(\" %s and %s=%s\",condition.str,fname,value) \n          break\n        }\n      } \n    }\n    return (condition.str)\n  }\n  \n  condition.str <- FormatCondition(condition,format)\n  cmd.str <- sprintf('select * from %s.%s where TRUE %s ;', dbname, tbname, condition.str)\n  conn <- OpenDB()\n  result<-sqlQuery(conn, cmd.str)\n  \n  return (result)\n}\n\n\n\nRemoveFromDB<-function(condition,format,\n                       dbname = \"hpts\", tbname = \"ttable\"){\n  # Perform a rm operation using 'condition' in 'format'  to table 'tbname' of database 'dbname'\n  #\n  # Args:\n  #   condition: The condition of select, need be a dataframe\n  #   format: The format that specifics condition structure and type\n  #   dbname: The database name\n  #   tbname: The table name\n  #\n  # Returns:\n  #    \n  stopifnot(is.data.frame(condition)==TRUE)\n  stopifnot(is.vector(condition$name)==TRUE)\n  stopifnot(is.vector(condition$value)==TRUE)\n  \n  FormatCondition<-function(condition,format)\n  {\n    condition.str<-\"\"\n    for(i in 1:nrow(condition))\n    {\n      fname<-condition[i,]$name\n      value<-condition[i,]$value\n      for(j in 1:nrow(format))\n      { \n        if(fname==format[j,]$name)\n        {\n          datatype<-format[j,]$datatype\n          if(datatype==\"numerical\")\n            condition.str<-sprintf(\" %s and %s=%s\",condition.str,fname,value) \n          if(datatype==\"category\")\n            condition.str<-sprintf(\" %s and %s='%s'\",condition.str,fname,value)  \n          if(datatype==\"boolen\")\n            condition.str<-sprintf(\" %s and %s=%s\",condition.str,fname,value) \n          break\n        }\n      } \n    }\n    return (condition.str)\n  }\n  \n  condition.str <- FormatCondition(condition,format)\n  if(condition.str==\"\")\n    stop(\"error ! you will clean up the table\")\n  cmd.str <- sprintf('rm from %s.%s where TRUE %s ;', dbname, tbname, condition.str)\n  print(cmd.str)\n  conn <- OpenDB()\n  result<-sqlQuery(conn, cmd.str)\n  \n  return (result)\n}\n\n\nUpdateForDB<-function(condition,condition.format,\n                      newdata,newdata.format,\n                      dbname = \"hpts\", tbname = \"ttable\"){\n  # Perform a rm operation using 'condition' in 'format'  to table 'tbname' of database 'dbname'\n  #\n  # Args:\n  #   condition: The condition of select, need be a dataframe\n  #   format: The format that specifics condition structure and type\n  #   dbname: The database name\n  #   tbname: The table name\n  #\n  # Returns:\n  #         0: there is no need to updata\n  #    \n  stopifnot(is.data.frame(condition)==TRUE)\n  stopifnot(is.vector(condition$name)==TRUE)\n  stopifnot(is.vector(condition$value)==TRUE)\n  \n  stopifnot(is.data.frame(newdata)==TRUE)\n  stopifnot(is.vector(newdata$name)==TRUE)\n  stopifnot(is.vector(newdata$value)==TRUE)\n  \n  if(nrow(newdata)==0)\n    return(0)\n  \n  Format<-function(data,format,linker=\",\")\n  {\n    data.str<-\"\"\n    for(i in 1:nrow(data))\n    {\n      \n      fname<-data[i,]$name\n      value<-data[i,]$value\n      for(j in 1:nrow(format))\n      { \n        if(fname==format[j,]$name)\n        {\n          if(i>1)\n            data.str<-paste(data.str,linker)\n          \n          datatype<-format[j,]$datatype\n          if(datatype==\"numerical\")\n            data.str<-sprintf(\" %s %s=%s\",data.str,fname,value) \n          if(datatype==\"category\")\n            data.str<-sprintf(\" %s  %s='%s'\",data.str,fname,value)  \n          if(datatype==\"boolen\")\n            data.str<-sprintf(\" %s %s=%s\",data.str,fname,value) \n          break\n        }\n      } \n    }\n    return (data.str)\n  }\n  \n  update.str<- Format(newdata,newdata.format)\n  condition.str <- Format(condition,condition.format,\"and\")\n  \n  if(condition.str==\"\")\n    stop(\"error ! you will update the whole table\")\n  cmd.str <- sprintf('update %s.%s set %s where TRUE and %s ;', dbname, tbname, update.str,condition.str)\n  \n  conn <- OpenDB()\n  result<-sqlQuery(conn, cmd.str)\n  return (result)\n}\n"
  },
  {
    "path": "framework/EvaluatorModule/Evaluator.R",
    "content": "PAK.Evaluator<-setRefClass(\n  \"PAK.Evaluator\",\n  fields = list(sub.evaluators = \"list\",\n                analysers.results.store =\"list\",\n                analysers.results.evaluate=\"list\"),\n  methods = list(\n    #init function\n    initialize=function(sub.evaluators=list()){\n      sub.evaluators<<-sub.evaluators\n    },\n    # the max score is 0\n    getScore=function(analysers.results){\n      score<-0\n      for(analyser in names(sub.evaluators))\n      {\n        analyser.evaluator<-sub.evaluators[[analyser]]\n        analyser.results<-analysers.results[[analyser]]\n        \n        #for each measurement\n        for(m.name in names(analyser.results))\n        {\n          m.result<-analyser.results[[m.name]]\n          score<-score+analyser.evaluator[[m.name]](m.result)\n        }\n      }\n      return (score)\n    },\n    evaluate=function(app){\n      for(aly in names(sub.evaluators))\n      {\n        one.analyser<-PAK.Analyser$new(name=aly,features=names(sub.evaluators[[aly]]),app=app)\n        one.analyser$anaylze()\n        analysers.results.store[[aly]]<<-one.analyser$getResultForDB()\n        analysers.results.evaluate[[aly]]<<-one.analyser$getResult()\n      }\n      score<-getScore(analysers.results.evaluate)\n      return (score)\n    },\n    getResults2store=function(){\n      return (analysers.results.store)\n    }\n  )\n)"
  },
  {
    "path": "framework/ExtractorModule/Analyze.old",
    "content": "library(XML)\nInstanceAnaylze<-function(analyser,analyser.features,app,\n                          analysis_module.path=\"/home/lyl/program/hpts/web/script/ExtractorModule/anaylsis_module/\"){\n  # perform analysis on target running instance \n  #\n  # Args:\n  #     analyzer:a string give generator name \n  #     analyser.feature: a string vector that contain enable variable for feauture to analysis\n  #     app:a string give target program name(with path)\n  \n  envstr<-\"\"\n  for(i in 1:length(analyser.features))\n  {\n    envvar<-gsub(\" \",\"\",analyser.features[i])\n    envstr<-paste(envstr,sprintf(\"export %s=TRUE;\",envvar))\n  }\n  \n  app.name<-basename(app)\n  app.path<-dirname(app)\n  \n  #go applications directions\n  envstr<-paste0(envstr,'cd ',app.path,';')\n  envstr<-paste0(envstr,'sh ',analysis_module.path,analyser,\"/analysis.sh \",app.name)\n  \n  r<-system(envstr,intern = TRUE)\n  resultfile<-paste0(app.path,\"/\",r)\n  anaylsis.result<-xmlToDataFrame(paste0(app.path,\"/\",r),stringsAsFactors=FALSE)\n  \n  return(anaylsis.result)\n}\n\n#anaylsis.result<-InstanceAnaylze(\"tau\",c(\"ENABLE_P_WALL_CLOCK_TIME\"),\"/home/lyl/program/hpts/applications/optimized_1.cpp\")"
  },
  {
    "path": "framework/ExtractorModule/Extractor.R",
    "content": "PAK.Extractor<-setRefClass(\n  \"PAK.Extractor\",\n  fields = list(analysers = \"list\",\n                analysers.results.store=\"list\",\n                analysers.results.produce=\"list\"\n  ),\n  methods = list(\n    #init function\n    initialize=function(analysers=list()){\n      analysers<<-analysers\n    },\n    \n    # the max score is 0\n    extractFeatures=function(app){\n      for(aly in names(analysers))\n      {\n        one.analyser<-PAK.Analyser$new(name=aly,features=analysers[[aly]],app=app)\n        one.analyser$anaylze()\n        analysers.results.store[[aly]]<<-one.analyser$getResultForDB()\n        analysers.results.produce[[aly]]<<-one.analyser$getResult()\n      }\n      return (analysers.results.produce)\n    },\n    getFeatures2produce=function(){\n      return (analysers.results.produce)\n    },\n    getFeatures2store=function(){\n      return (analysers.results.store)\n    }\n  )\n)"
  },
  {
    "path": "framework/Interface/Analyser.R",
    "content": "PAK.Analyser<-setRefClass(\n  \"PAK.Analyser\",\n  fields = list(app = \"character\",\n                name = \"character\",\n                features = \"character\",\n                result = \"data.frame\",\n                path = \"character\",\n                enable.list =\"list\",\n                datatype.list=\"list\"),\n  methods = list(\n    #init function\n    initialize=function(name=\"\",app=\"\",features=character()){\n      name<<-name\n      app<<-app\n      features<<-features\n      path<<-path.analysis_tools\n      enable.list<<-GetEnableList(paste0(path,\"/\",name,\"/featureinfo.xml\"),Nameaskey = TRUE)\n      datatype.list<<-GetDatatypeList(paste0(path,\"/\",name,\"/featureinfo.xml\"))\n    },\n    enableAllfeatures=function(){\n      features<<-names(enable.list)\n    },\n    anaylze=function(){\n      # perform analysis on target running instance \n      #\n      # Args:\n      #     analyzer:a string give generator name \n      #     analyser.feature: a string vector that contain enable variable for feauture to analysis\n      #     app:a string give target program name(with path)\n      envstr<-\"\"\n      if(length(features)==0)\n        stop(sprintf(\"error! features of analyser %s is NULL!\",name))\n      \n      for(i in 1:length(features))\n      {\n        envvar<-gsub(\" \",\"\",enable.list[[features[i]]])\n        envstr<-paste(envstr,sprintf(\"export %s=TRUE;\",envvar))\n      }\n      app.name<-basename(app)\n      app.path<-dirname(app)\n      #go applications directions\n      envstr<-paste0(envstr,'cd ',app.path,';')\n      envstr<-paste0(envstr,'sh ',path,name,\"/analysis.sh \",\"./\",app.name)\n      r<-system(envstr,intern = TRUE)\n      resultfile<-paste0(app.path,\"/\",r)\n      result<<-xmlToDataFrame(paste0(app.path,\"/\",r),stringsAsFactors=FALSE)\n    },\n    getResultForDB=function()\n    {\n      return (result)\n    },\n    getResult=function()\n    {\n      result.evaluate<-list()\n      for(i in 1:nrow(result))\n      {\n        tmp<-result[i,]\n        \n        if(datatype.list[[tmp$name]]!=\"category\")\n          result.evaluate[[tmp$name]]<-as.numeric(tmp$value)  \n        else\n          result.evaluate[[tmp$name]]<-tmp$value  \n      }\n      return (result.evaluate)\n    }\n  )\n)"
  },
  {
    "path": "framework/Interface/Generator.R",
    "content": "library(\"methods\")\nPAK.Generator<-setRefClass(\n  \"PAK.Generator\",\n  fields = list(app = \"character\",\n                name = \"character\",\n                parameters = \"data.frame\",\n                output = \"character\",\n                result = \"character\",\n                path=\"character\"),\n  methods = list(\n    #init function\n    initialize=function(name=\"\",app=\"\",output=\"\",p.os=NA){\n      name<<-name\n      app<<-app\n      output<<-output\n      path<<-path.generator_tools\n      \n      if(is.data.frame(p.os))\n        setPUsingSpace(p.os)\n    },\n    transform=function(){\n      # perform code transforming on target program\n      envstr<-\"\"\n      for(i in 1:nrow(parameters))\n      {\n        envvar.name<-gsub(\" \",\"\",parameters[i,]$enable_variable)\n        envvar.value<-gsub(\" \",\"\",parameters[i,]$parameter)\n        envstr<-paste(\n          envstr,sprintf(\"export %s='%s';\",\n                         envvar.name,\n                         envvar.value))\n      }\n      #go applications directions\n      app.name<-basename(app)\n      app.path<-dirname(app)\n      envstr<-paste0(envstr,'cd ',app.path,';')\n      envstr<-paste0(envstr,'sh ',path,name,\n                     \"/transform.sh \",app.name,\" \",output)\n      variant.file<-system(envstr,intern = TRUE)\n      result<<-paste0(app.path,\"/\",variant.file)\n    },\n    setPUsingSpace=function(p.in.space){\n      enable.list<-GetEnableList(paste0(path,\"/\",name,\"/variantinfo.xml\"))\n      parameters<<-data.frame(enable_variable=character(),\n                              parameter=character())\n      for(p in names(p.in.space) )\n        parameters<<-\n        rbind(parameters,data.frame(enable_variable=enable.list[[p]],\n                                    parameter=p.in.space[[p]]))\n    },\n    getParameterForDB=function(){\n      enable.list<-GetEnableList(paste0(path,\"/\",name,\"/variantinfo.xml\"),FALSE)\n      df<-as.data.frame(do.call(rbind,mapply(SIMPLIFY = FALSE,function(e,p)\n      {data.frame(name=enable.list[[e]],value=p,stringsAsFactors = FALSE)}, \n      parameters$enable_variable,parameters$parameter)))\n      return(df)\n    }\n  )\n)"
  },
  {
    "path": "framework/LearnerModule/Learner.R",
    "content": "# the Learner module\nPAK.Learner<-setRefClass(\n  \"PAK.Learner\",\n  fields = list(model=\"list\",dv.name=\"character\",\n                idv.name=\"character\"),\n  methods = list(\n    #init function\n    initialize=function(){ \n    },\n    learnModel=function(training.data,idv,dv){\n      \n    }\n  )\n)\n \n\n\n"
  },
  {
    "path": "framework/OptimizerModule/Optimizer.R",
    "content": "\nPAK.Optimizer<-setRefClass(\n  \"PAK.Optimizer\",\n  fields = list(generator.name =\"character\",\n                generator= \"PAK.Generator\",\n                output.name=\"character\"),\n  methods = list(\n    #init function\n    initialize=function(generator.name=NA,output.name=\"optimized.cpp\"){\n      \n      output.name<<-output.name\n      if(is.character(generator.name))\n      {\n        generator.name<<-generator.name\n        generator<<-PAK.Generator$new(name=generator.name,output=output.name)\n      }\n    },\n    optimize=function(app,parameters){\n      generator$setPUsingSpace(parameters)\n      generator$app<<-app\n      r<-generator$transform()\n      return(r)\n    },\n    getParameters2store=function(){\n      parameters.list<-list()\n      print(generator$getParameterForDB())\n      print(generator.name)\n      parameters.list[[generator.name]]<-generator$getParameterForDB()\n      return(parameters.list)\n    }\n  )\n)"
  },
  {
    "path": "framework/ProducerModule/Producer.R",
    "content": "# a class to producer parameter\nPAK.Producer<-setRefClass(\n  \"PAK.Producer\",\n  fields = list(),\n  methods = list(\n    #     init function\n    initialize=function(){\n    },\n    getParameter=function(step,extractor.result,last.score)\n    {\n      \n    }\n  )\n)\n\n"
  },
  {
    "path": "framework/Tuning/Tuner.R",
    "content": "library(\"methods\")\nPAK.Tuner<-setRefClass(\n  \"PAK.Tuner\",\n  fields = list(app = \"character\",\n                extractor =\"PAK.Extractor\",\n                evaluator = \"PAK.Evaluator\",# list(analyser=list(name=eval.fun)): name is measurement name, and eval.fun is its evaluate function\n                producer =\"PAK.Producer\",#parameter producer\n                optimizer =\"PAK.Optimizer\",#optimizer\n                need.store =\"logical\",\n                best.score=\"numeric\",\n                best.parameters=\"data.frame\",\n                best.results=\"list\"),\n  methods = list(\n    #init function\n    initialize=function(app,extractor=PAK.Extractor$new(),evaluator,producer,optimizer,need.store=FALSE){\n      app<<-app\n      extractor<<-extractor\n      evaluator<<-evaluator\n      producer<<-producer\n      optimizer<<-optimizer\n      need.store<<-need.store\n    },\n    checkpoint=function(step,score,r.producer,r.best.score,r.best.parameters,r.best.result){\n      if(length(dir(pattern=\"stoptuning\"))!=0)\n      {\n        print(\"stop tuning!\")\n        save(step,score,r.producer,r.best.score,r.best.parameters,r.best.result,file=\"tuningRecord\")\n        return (TRUE)\n      }\n      return (FALSE)\n    },\n    tune=function(resume.file=NA){\n      step<-0\n      score<-numeric()\n      extractor$extractFeatures(app)\n      if(!is.na(resume.file))\n      {\n        print(\"load file\")\n        load(resume.file)\n        producer<<-r.producer\n        best.score<<-r.best.score\n        best.parameters<<-r.best.parameters\n        best.results<<-r.best.result\n      }\n      while(TRUE)\n      {\n        step<-step+1\n        cat(sprintf(\"step : %d\",step))\n        \n        #produce parameters\n        parameters<-producer$getParameter(step=step,\n                                          extractor.result=extractor$getFeatures2produce(),\n                                          last.score=score)\n        \n        #search is end \n        if(length(parameters)==0)\n          break\n         \n        optimized.instance<-optimizer$optimize(app,parameters)\n        print(parameters)\n        score<-evaluator$evaluate(optimized.instance)\n        \n        if(need.store)\n          store2DB()\n        \n        if(step==1||score>best.score)\n        {\n          best.score<<-score\n          best.parameters<<-parameters\n          best.results<<-evaluator$analysers.results.evaluate\n        }\n        print(score)\n        if(score==0||checkpoint(step,score,producer,best.score,best.parameters,best.results))\n          break\n        cat(\"end a step \\n\")\n      }\n    },\n    \n    store2DB=function(){\n      keyAnalyser.result<-PerformKeyAnalysis(app)\n      unkeyAnalyser.result<-extractor$getFeatures2store()\n      Analyser.result<-rbind(keyAnalyser.result,unkeyAnalyser.result)\n      main.id<-StoreAnalysis(keyAnalyser.result,override = TRUE)\n      StoreTransformation(main.id,optimizer$getParameters2store(),evaluator$getResults2store())\n    }\n  )\n)\n\n"
  },
  {
    "path": "framework/dependencies.R",
    "content": "library(\"XML\")\nlibrary(\"jsonlite\") \nlibrary(\"RODBC\")\nlibrary(\"methods\")\nprint(\"load dependencies\")"
  },
  {
    "path": "framework/lib/OptimizationSpace.R",
    "content": "GenerationParameterSpace<-function(parameter.list)\n{\n  loop.str<-\"\"\n  df.str<-\"\"\n  for(i in 1:length(parameter.list))\n  {\n    range<-unlist(strsplit(parameter.list[[i]],\";\"))[1]\n    condition<-unlist(strsplit(parameter.list[[i]],\";\"))[2]\n    parameter.name<-names(parameter.list[i])\n    if(is.na(condition))\n      tmp.str<-sprintf(\"for(%s in c(%s) )\\n\",names(parameter.list[i]),range)\n    else\n      tmp.str<-sprintf(\"for(%s in c(%s) )\\n if(%s)\\n\",names(parameter.list[i]),range,condition)\n    loop.str<-paste0(loop.str,tmp.str)\n    df.str<-paste0(df.str,sprintf(\"%s=%s\",\n                                  parameter.name,parameter.name))\n    if(i!=length(parameter.list))\n      df.str<-paste0(df.str,\",\")\n  }\n  df.str<-paste0(\"combinations.tmp<-data.frame(\",df.str,\",stringsAsFactors = FALSE)\")\n  body.str<-paste0(df.str,\"\\nif(nrow(combinations.parameter)==0)\\n\",\n                   \"combinations.parameter<-combinations.tmp\\n\",\n                   \"else\\ncombinations.parameter<-rbind(\",\n                   \"combinations.parameter,combinations.tmp)\")\n  \n  space.str<-paste0(loop.str,\"{\\n\",body.str,\"\\n}\")\n  combinations.parameter<-data.frame()\n  eval(parse(text=space.str))\n  return(combinations.parameter)\n}\n\n#combinations.parameter<-GenerationSpace(parameter.list)"
  },
  {
    "path": "framework/lib/learners.R",
    "content": "# an decision tree learner\nPAK.Learner.DecisionTree<-setRefClass(\n  \"PAK.Learner.DecisionTree\",\n  contains=\"PAK.Learner\",\n  fields = list(model=\"list\",dv.name=\"character\",\n                idv.name=\"character\"),\n  methods = list(\n    #init function\n    initialize=function(){ \n    },\n    learnModel=function(training.data,idv,dv){\n      buildstr<-sprintf(\"rpart(%s~.,training.data)\",dv)\n      model[[\"rp\"]]<<-eval(parse(text=buildstr) )    \n      model[[\"dv.name\"]]<<-dv\n      model[[\"idv.name\"]]<<-idv\n      return (model)\n    }\n  )\n)"
  },
  {
    "path": "framework/lib/producers.R",
    "content": " library(rpart)\n\nPAK.Producer.Exhaustion<-setRefClass(\n  \"PAK.Producer.Exhaustion\",\n  contains=\"PAK.Producer\",\n  fields = list(parameter.space=\"data.frame\"),\n  methods = list(\n    #init function\n    initialize=function(parameter.list){\n      parameter.space<<-GenerationParameterSpace(parameter.list)\n    },\n    getParameter=function(step,extractor.result,last.score)\n    {\n      if(step<=nrow(parameter.space))\n      {\n        if(ncol(parameter.space)==1)\n          return (eval(parse(text=sprintf(\"data.frame(%s=parameter.space[step,])\",names(parameter.space)))))\n        else\n          return(parameter.space[step,])\n      }\n    }\n  )\n)\n\n\nPAK.Producer.Greedy<-setRefClass(\n  \"PAK.Producer.Greedy\",\n  contains=\"PAK.Producer\",\n  fields = list(parameter.range=\"list\",#list(p1=c(1,2,3..),p2=c(1,2,3..)..)\n                v.idx =\"numeric\",\n                v.score =\"numeric\",\n                v.pos =\"numeric\",\n                local.optimal= \"data.frame\"),\n  methods = list(\n    #init function\n    initialize=function(parameter.range=list()){\n      parameter.range<<-parameter.range\n    },\n    \n    getParameter=function(step,extractor.result,last.score)\n    {\n      if(step==1)\n      {\n        local.optimal<<-defulat.parameters\n        v.idx<<-1\n        v.score<<-c()\n        v.pos<<-0\n      }\n      else if(v.pos<v.length)\n      {\n        v.pos<<-v.pos+1\n        v.score[v.pos]<<-last.score\n      }else{#finish local optimal search for a parameter\n        optimal.pos<-which.max(v.score)\n        local.optimal[[v.idx]]<<-parameter.range[[v.idx]][optimal.pos]\n        v.idx<<-v.idx+1\n        if(v.idx>parameter.number)\n          return (data.frame())\n        \n        v.score<<-c()\n        v.pos<<-0\n      }\n      new.parameter<-local.optimal\n      new.parameter[[v.idx]]<-parameter.range[[v.idx]][v.pos+1]\n      return (new.parameter)\n    }\n  )\n)\n\n\nPAK.Producer.OptimalSpace<-setRefClass(\n  \"PAK.Producer.OptimalSpace\",\n  contains=\"PAK.Producer\",\n  fields = list(parameter.space=\"data.frame\"),\n  methods = list(\n    #init function\n    initialize=function(tid){\n      os<-PredictOptimalSpace(tid,combine.os=c(1,3,5,8,10),os.size=25,model=os.models[[1]],cond.str=cond.str,omp.number = 16)\n      convertOS2parameterspace(os)\n      cat(\"length of os: \",nrow(parameter.space),\"\\n\")\n      print(parameter.space)\n    },\n    getParameter=function(step,extractor.result,last.score)\n    {\n      if(step<nrow(parameter.space))\n      {\n        parameter<-parameter.space[step,]\n        for(p.name in names(parameter))\n        {\n          if(is.na(parameter[[p.name]]))\n            parameter[[p.name]]<-NULL\n        }\n        return(parameter)\n      }\n    },\n    convertOS2parameterspace=function(os)\n    {\n      parameter.space<<-data.frame()\n      for(config in os)\n      {\n        if(config==\"\")\n          parameter.space<<-rbind(\n            parameter.space,data.frame(\n              Tiling_1=NA,Tiling_2=NA,Tiling_3=NA,\n              Tiling_4=NA,Tiling_5=NA,Tiling_6=NA,\n              Tiling_7=NA,Tiling_8=NA,Tiling_9=NA,\n              DoSIMD=1,Unrolling=NA))\n        else{\n          pars.strs<-unlist(strsplit(config,\",\"))\n          if(length(pars.strs)==1)\n            parameter.space<<-rbind(\n              parameter.space,data.frame(\n                Tiling_1=NA,Tiling_2=NA,Tiling_3=NA,\n                Tiling_4=NA,Tiling_5=NA,Tiling_6=NA,\n                Tiling_7=NA,Tiling_8=NA,Tiling_9=NA,\n                DoSIMD=1,Unrolling=pars.strs[1]))\n          else if(length(pars.strs==10))\n            parameter.space<<-rbind(\n              parameter.space,data.frame(\n                Tiling_1=pars.strs[2],Tiling_2=pars.strs[3],Tiling_3=pars.strs[4],\n                Tiling_4=pars.strs[5],Tiling_5=pars.strs[6],Tiling_6=pars.strs[7],\n                Tiling_7=pars.strs[8],Tiling_8=pars.strs[9],Tiling_9=pars.strs[10],\n                DoSIMD=1,Unrolling=NA))\n        }\n      }\n    }\n  )\n)\n\n\nPAK.Producer.DecisionTree<-setRefClass(\n  \"PAK.Producer.DecisionTree\",\n  contains=\"PAK.Producer\",\n  fields = list(model=\"list\",\n                dv.name=\"character\"),\n  methods = list(\n    #init function\n    initialize=function(){\n    },\n    loadModel=function(new.model){\n      model[[\"rp\"]]<<-new.model\n    },\n    trainModel=function(training.data,ivs,dv){\n      model[[\"rp\"]]<<-eval(parse(text=sprintf(\"rpart(%s~.,training.data)\",dv)) )    \n      dv.name<<-dv\n    },\n    getParameter=function(step,extractor.result,last.score)\n    {\n      inv.str<-\"\"\n      for(e in names(extractor.result))\n      {\n        one.ext<-extractor.result[[e]]\n        for(f in names(one.ext))\n        {\n          if(inv.str==\"\")\n            inv.str<-sprintf(\"%s=%s\",f,as.character(one.ext[[f]]))\n          else\n            inv.str<-sprintf(\"%s,%s=%s\",inv.str,f,as.character(one.ext[[f]]))\n        }\n      }\n      inv<-eval(parse(text=sprintf(\"data.frame(%s)\",inv.str)) )\n      \n      dv.prs<-predict(model[[\"rp\"]],inv,method=\"prob\")\n      dv.prs<-as.data.frame(t(dv.prs))\n      dv.prs$type<-row.names(dv.prs)\n      dv.prs<-dv.prs[order(dv.prs[[names(dv.prs)[1]]],decreasing=T),]\n     \n      \n      if(step>nrow(dv.prs))\n        parameter<-eval(parse(text=sprintf(\"data.frame(%s=NULL)\",dv.name)))\n      else\n        parameter<-eval(parse(text=sprintf(\"data.frame(%s='%s')\",dv.name,dv.prs$type[step])))\n      \n     \n     return (parameter)\n    }\n  )\n)\n\n\n\n\n\n\n"
  },
  {
    "path": "generator_module/optimizeCompilerFlag/transform.sh",
    "content": "#!/bin/bash\nCC=gcc\n#export ENABLE_COMPILERFLAG=\"-O3\"\nCFLAGENABLE=`env |grep ENABLE_COMPILERFLAG`\n    FNAME=${CFLAGENABLE#ENABLE_}\n    FNAME=${FNAME%%=*}\n    SUFFIX=${FNAME##*_}\n    FNAME=${FNAME%%_*}\n    \nif [ $FNAME = \"COMPILERFLAG\" ] ; then   \n    CFLAG=${CFLAGENABLE#*=} \n    $CC $CFLAG $1 -o $2\nfi\necho $2\n\n\n\n\n"
  },
  {
    "path": "generator_module/optimizeCompilerFlag/variantinfo.xml",
    "content": "<variants>\n    <variant>\n        <name>compilerflag</name>\n        <description>the compiler flag</description>\n        <enable_variable>ENABLE_COMPILERFLAG</enable_variable>\n        <datatype>string</datatype>\n    </variant>\n</variants>\n"
  },
  {
    "path": "pak.R",
    "content": "path.analysis_tools<-\"/home/liujh/PAK-master/analysis_module/\"\npath.generator_tools<-\"/home/liujh/PAK-master/generator_module/\"\nodbc.source<-\"kdb\"\ndatabase.user<-\"user\"\ndatabase.pwd<-\"pwd\"\n\n\n\nGetSourceFileDir<-function()\n{\n  frame_files <- lapply(sys.frames(), function(x) x$ofile)\n  frame_files <- Filter(Negate(is.null), frame_files)\n  path.sourcefile <- dirname(frame_files[[length(frame_files)]])\n  return(path.sourcefile)\n}\n\nSourceDir <- function(path, trace = FALSE)\n{\n  #if(missing(path)) path <- getwd()\n  for(i in 1:length(path))\n  {\n    for (nm in list.files(path, pattern = \".[Rr]\",recursive=TRUE))\n    {\n      if(trace) cat(nm,\":\")\n      source(file.path(path, nm))\n      if(trace) cat(\"\\n\")\n    }\n  }\n}\n\nsfdir<-GetSourceFileDir()\nsource(file.path(sfdir,\"framework/dependencies.R\"))\nSourceDir(file.path(sfdir,\"framework/Interface\"))\nSourceDir(file.path(sfdir,\"framework/ExtractorModule\"))\nSourceDir(file.path(sfdir,\"framework/ProducerModule\"))\nSourceDir(file.path(sfdir,\"framework/OptimizerModule\"))\nSourceDir(file.path(sfdir,\"framework/EvaluatorModule\"))\nSourceDir(file.path(sfdir,\"framework/LearnerModule\"))\nSourceDir(file.path(sfdir,\"framework/DBModule\"))\nSourceDir(file.path(sfdir,\"framework/Tuning\"))\nSourceDir(file.path(sfdir,\"framework/lib\"))\n\n\n#PerformKeyAnalysis<-function(app){\n # key.analyser.names<-c(\"appinfo\",\"envinfo\")\n  #result<-list()\n  #for(ka in key.analyser.names)\n  #{ \n   # analyser<-PAK.Analyser$new(name=ka,app)\n    #analyser$enableAllfeatures()\n    #analyser$anaylze()\n    #result[[ka]]<-analyser$getResultForDB()\n#  }\n # return (result)\n#}\n"
  },
  {
    "path": "tutorial/autotuning_compilerflag.R",
    "content": "GetSourceFileDir<-function()\n{\n  frame_files <- lapply(sys.frames(), function(x) x$ofile)\n  frame_files <- Filter(Negate(is.null), frame_files)\n  path.sourcefile <- dirname(frame_files[[length(frame_files)]])\n  return(path.sourcefile)\n}\n\nsfdir<-GetSourceFileDir()\nsource(file.path(sfdir,\"../pak.R\"))\n\n\n# Exhaustion algorithm autotuner\nif(TRUE || FALSE)\n{\n  app<-\"/home/liujh/PAK-master/applications/multiplyexample.c\"\n  \n  parameter.list<-list()\n  parameter.list[\"compilerflag\"]<-'\" -O0\" ,\" -O1\",\" -O2\",\" -O3\";'\n  \n  myproducer<-PAK.Producer.Exhaustion$new(parameter.list)\n  myoptimizer<-PAK.Optimizer$new(generator.name=\"optimizeCompilerFlag\")\n  myevaluator<-PAK.Evaluator$new(sub.evaluators=list(paktimer=list(time=function(x){if(x>0) return (0-x) else return(0)})))\n  \n  tuning<-PAK.Tuner$new(app=app,optimizer=myoptimizer,evaluator=myevaluator,producer =myproducer,need.store=FALSE)\n  tuning$tune()\n}\n\n\n"
  }
]