Commit 9ee53698 authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Merge remote-tracking branch 'origin/master' into devel/par_io

# Conflicts:
#	Compiler/src/exastencils/app/ir/IR_LayerHandler.scala
#	Compiler/src/exastencils/config/Knowledge.scala
#	Compiler/src/exastencils/visualization/ir/vtk/IR_PrintVtkTriangles.scala
parents 9a18019a c75d550d
......@@ -52,7 +52,9 @@ import exastencils.stencil.ir._
import exastencils.timing.ir._
import exastencils.util._
import exastencils.util.ir._
import exastencils.visualization.ir._
import exastencils.visualization.ir.cimg.IR_ResolveCImgFunctions
import exastencils.visualization.ir.visit.IR_SetupVisit
import exastencils.visualization.ir.vtk.IR_ResolveVtkPrinters
/// IR_LayerHandler
......@@ -169,6 +171,9 @@ object IR_DefaultLayerHandler extends IR_LayerHandler {
// simplify indices modified just now, otherwise equality checks will not work later on
IR_GeneralSimplify.apply()
if (Knowledge.visit_enable)
IR_SetupVisit.apply()
var convChanged = false
do {
IR_FindStencilConvolutions.changed = false
......@@ -185,9 +190,6 @@ object IR_DefaultLayerHandler extends IR_LayerHandler {
IR_ResolveStencilFunction.apply()
if (Knowledge.experimental_visit_enable)
IR_SetupVisit.apply()
// resolve new virtual field accesses
IR_ResolveIntegrateOnGrid.apply()
IR_ResolveEvaluateOnGrid.apply()
......
......@@ -21,7 +21,8 @@ package exastencils.applications.ir
import scala.collection.mutable.ListBuffer
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir.{ IR_Native, _ }
import exastencils.base.ir.IR_Native
import exastencils.base.ir._
import exastencils.config.Knowledge
import exastencils.datastructures._
import exastencils.logger.Logger
......
......@@ -754,10 +754,10 @@ object Knowledge {
var experimental_grid_randomMaxOffset : Double = 0.1
/// student project - Richard / visit
// in-situ visualization with VisIt
var visit_enable : Boolean = false
var experimental_visit_addCurveMesh : Boolean = false
// TODO
var experimental_visit_enable : Boolean = false
/// === constraints and resolutions ===
def update() : Unit = {
......
......@@ -205,6 +205,10 @@ object IR_SimplifyExpression {
res = new mutable.HashMap[IR_Expression, Long]()
res(m) = 1L
case m : IR_MemberFunctionCall =>
res = new mutable.HashMap[IR_Expression, Long]()
res(m) = 1L
case IR_StringLiteral(varName) =>
res = new HashMap[IR_Expression, Long]()
res(IR_VariableAccess(varName, IR_IntegerDatatype)) = 1L // ONLY VariableAccess in res keys, NO StringLiteral
......
//=============================================================================
//
// This file is part of the ExaStencils code generation framework. ExaStencils
// is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// ExaStencils is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with ExaStencils. If not, see <http://www.gnu.org/licenses/>.
//
//=============================================================================
package exastencils.visualization.ir
import scala.collection.mutable.ListBuffer
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir.{ IR_Native, _ }
import exastencils.baseExt.ir.IR_UserFunctions
import exastencils.datastructures._
import exastencils.field.ir.IR_FieldCollection
object IR_SetupVisit extends DefaultStrategy("Setup Visit functions") {
def setupFct_SimGetVariable() : IR_Function = {
val fctBody = ListBuffer[IR_Statement]()
fctBody += IR_Native("sim_data* s = (sim_data*) cbdata;")
fctBody += IR_Native("visit_handle h = VISIT_INVALID_HANDLE;")
// n-way loop IR_LoopOverDimensions
// IR_Assignment
// IR_FieldAccess
for (field <- IR_FieldCollection.objects) {
val numDims = field.layout.numDimsGrid
val numPointsTmp = (0 until numDims).map(d => field.layout.defIdxDupRightEnd(d) - field.layout.defIdxDupLeftBegin(d)).sum
fctBody += IR_IfCondition(
IR_Native("(strcmp(name, \"" + field.name + "\") == 0 && " + field.level + " == s->curLevel)"),
IR_Native(
s""" double tmp[$numPointsTmp];
| for(int i2 = 0; i2 < 128; i2++) {
| for(int i1 = 0; i1 < 128; i1++) {
| for(int i0 = 0; i0 < 128; i0++) {
| tmp[(n*n*i2) + (n*i1) + i0] = fieldData_Solution[s->curLevel-2][(130*134*i2) + (134*i1) + i0 + (np2*np2 + np2 + 1)]; //take the interior nodes to get the correct visualization
| }
| }
| }
| if (VisIt_VariableData_alloc(&h) == VISIT_OKAY) {
| VisIt_VariableData_setDataD(h, VISIT_OWNER_SIM, 1, n*n*n, tmp);
| }
|""".stripMargin)
)
}
IR_PlainFunction(
"SimGetVariable",
IR_SpecialDatatype("visit_handle"),
ListBuffer(IR_FunctionArgument("domain", IR_IntegerDatatype)), // TODO: others (int domain, const char* name, void* cbdata)
fctBody)
}
this += Transformation("..", {
case fctCollection : IR_UserFunctions => // TODO: replace with VisFunctions
fctCollection += setupFct_SimGetVariable()
//Settings.pathsInc = (Settings.pathsInc :+ "$VISIT_PATH/include").distinct
//fctCollection.externalDependencies += "visit.h"
// TODO: other functions
fctCollection
})
}
......@@ -16,7 +16,7 @@
//
//=============================================================================
package exastencils.visualization.ir
package exastencils.visualization.ir.cimg
import scala.collection.mutable.ListBuffer
......
package exastencils.visualization.ir.visit
import exastencils.base.ir.IR_VariableDeclaration
import exastencils.baseExt.ir._
import exastencils.config._
import exastencils.datastructures._
import exastencils.field.ir.IR_FieldCollection
import exastencils.globals.ir.IR_GlobalCollection
import exastencils.grid.ir._
import exastencils.logger.Logger
import exastencils.visualization.ir.visit.IR_VisItGlobals._
object IR_SetupVisit extends DefaultStrategy("Setup Visit functions") {
/* TODO:
* Utilize virtual fields for node/cell positions
* too many copies -> read docs for ghost layer mechanism from VisIt
* assumes rectangular domains -> generally blockstructured grids not supported
* Higher-order datatypes unsupported
*/
import IR_VisItUtil._
override def apply(applyAtNode : Option[Node]) : Unit = {
// check if innerPoints were set manually in layout
for (field <- IR_FieldCollection.objects) {
for (d <- 0 until field.numDimsGrid) {
val numDupOrInner = field.layout.defIdxDupRightEnd(d) - field.layout.defIdxDupLeftBegin(d)
field.layout.localization match {
case IR_AtNode | IR_AtFaceCenter(`d`) =>
if (numDupOrInner != Knowledge.domain_fragmentLengthAsVec(d) * (1 << field.level) + 1)
Logger.error("VisIt interface currently only supports fields bound to a mesh with \"fragmentLength(d) * 2^level +1\" grid nodes.")
case IR_AtCellCenter | IR_AtFaceCenter(_) =>
if (numDupOrInner != Knowledge.domain_fragmentLengthAsVec(d) * (1 << field.level) + 0)
Logger.error("VisIt interface currently only supports fields bound to a mesh with \"fragmentLength(d) * 2^level +0\" cells.")
}
}
}
super.apply(applyAtNode)
}
this += Transformation("Add dependencies, new user functions and globals", {
case fctCollection : IR_UserFunctions =>
if (Knowledge.dimensionality > 1)
fctCollection += IR_VisItSimGetVariable()
fctCollection += IR_VisItSimGetMesh()
fctCollection += IR_VisItSimGetMetaData()
fctCollection += IR_VisItControlCommandCallback()
fctCollection += IR_VisItInitialization()
fctCollection += IR_VisItDestroy()
fctCollection += IR_VisItMainloop()
if (Knowledge.mpi_enabled) {
fctCollection += IR_VisItProcessVisItCommand()
fctCollection += IR_VisItSimGetDomainList()
fctCollection += IR_VisItBroadcastIntCallback()
fctCollection += IR_VisItBroadcastStringCallback()
fctCollection += IR_VisItSlaveProcessCallback()
}
Settings.pathsInc = (Settings.pathsInc :+ "$(SIMV2DIR)/include").distinct
Settings.pathsLib = (Settings.pathsLib :+ "$(SIMV2DIR)/lib").distinct
Settings.additionalLibs += "simV2"
Settings.additionalLibs += "dl"
fctCollection.externalDependencies += "string.h"
fctCollection.externalDependencies += "stdlib.h"
if (Knowledge.dimensionality == 1 || Knowledge.dimensionality == 2) fctCollection.externalDependencies += "stdexcept"
if (Knowledge.mpi_enabled) {
fctCollection.externalDependencies += "stdio.h"
}
fctCollection.externalDependencies += "VisItControlInterface_V2.h"
fctCollection.externalDependencies += "VisItDataInterface_V2.h"
if (Platform.targetCompiler == "MSVC") {
fctCollection.externalDependencies += "direct.h"
} else {
fctCollection.externalDependencies += "unistd.h"
}
fctCollection
case globalCollection : IR_GlobalCollection =>
globalCollection.variables += curLevelDecl
globalCollection.variables += curSlotDecl
globalCollection.variables += runModeDecl
globalCollection.variables += updatePlotsDecl
if (Knowledge.dimensionality == 1 || Knowledge.dimensionality == 2) globalCollection.variables += scaleCurvemeshDecl
// coordinate arrays for 2 and 3 dim. rectilinear meshes
if (Knowledge.dimensionality > 1) {
for (coords <- coordsArrays.distinct) globalCollection.variables += IR_VariableDeclaration(coords)
}
// coordinate arrays for 2 and 3 dim. curvilinear meshes (partially consisting of 1d or 2d variables)
if (Knowledge.dimensionality < 3) {
for (curveCoords <- curveCoordsArrays.distinct) globalCollection.variables += IR_VariableDeclaration(curveCoords)
}
globalCollection.variables += commandNamesDecl
globalCollection
})
}
package exastencils.visualization.ir.visit
import scala.collection.mutable.ListBuffer
import exastencils.base.ir._
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.config.Knowledge
import exastencils.datastructures.Transformation.OutputType
import exastencils.field.ir.IR_FieldCollection
import exastencils.visualization.ir.visit.IR_VisItGlobals._
import exastencils.visualization.ir.visit.IR_VisItUtil._
case class IR_VisItCommandHandling(cmd : IR_Expression) extends IR_Statement with IR_Expandable {
def step() = {
IR_IfCondition(
stringEquals(cmd, "step"),
ListBuffer[IR_Statement](
IR_FunctionCall(IR_LeveledInternalFunctionReference("simulate_timestep", Knowledge.maxLevel, IR_UnitDatatype)),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
IR_IfCondition(
updatePlots,
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots"))))))
)
}
def stop() = {
IR_IfCondition(stringEquals(cmd, "stop"),
IR_Assignment(runMode, IR_BooleanConstant(false)))
}
def run() = {
IR_IfCondition(stringEquals(cmd, "run"),
IR_Assignment(runMode, IR_BooleanConstant(true)))
}
def toggleUpdates() = {
IR_IfCondition(stringEquals(cmd, "toggle updates"),
IR_Assignment(updatePlots, IR_Negation(updatePlots)))
}
def toggleLevel() = {
IR_IfCondition(
stringEquals(cmd, "toggle level"),
ListBuffer[IR_Statement](
IR_Assignment(curLevel, modulo(curLevel - Knowledge.minLevel - 1, Knowledge.numLevels) + Knowledge.minLevel),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots")))))
}
def toggleSlot() = {
IR_IfCondition(
stringEquals(cmd, "toggle slot"),
ListBuffer[IR_Statement](
IR_Assignment(curSlot, (curSlot + 1) Mod IR_FieldCollection.objects.map(_.numSlots).max),
IR_IfCondition(
callExtFunction("VisItIsConnected"),
ListBuffer[IR_Statement](
callExtFunction("VisItTimeStepChanged"),
callExtFunction("VisItUpdatePlots")))))
}
override def expand() : OutputType = {
var stmts = ListBuffer[IR_Statement](step(), stop(), run(), toggleUpdates())
// only register level switches when necessary
if (isMultiLeveled)
stmts += toggleLevel()
// only register slot switch when necessary
if (isMultiSlotted)
stmts += toggleSlot()
stmts
}
}
package exastencils.visualization.ir.visit
import scala.collection.mutable.ListBuffer
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir._
import exastencils.visualization.ir.visit.IR_VisItUtil._
import exastencils.config._
case class IR_VisItBroadcastIntCallback() extends IR_VisItFuturePlainFunction {
val intValue = IR_FunctionArgument("value", IR_PointerDatatype(IR_IntegerDatatype))
val sender = IR_FunctionArgument("sender", IR_IntegerDatatype)
override def generateFct() : IR_PlainFunction = {
val fctBody = ListBuffer[IR_Statement]()
fctBody += IR_Return(callExtFunction("MPI_Bcast",
intValue.access, IR_IntegerConstant(1), IR_Native("MPI_INT"), sender.access, Knowledge.mpi_defaultCommunicator))
IR_PlainFunction(
name,
IR_IntegerDatatype,
ListBuffer(intValue, sender),
fctBody
)
}
override def name : String = "visit_broadcast_int_callback"
}
case class IR_VisItBroadcastStringCallback() extends IR_VisItFuturePlainFunction {
val str = IR_FunctionArgument("str", IR_PointerDatatype(IR_CharDatatype))
val len = IR_FunctionArgument("len", IR_IntegerDatatype)
val sender = IR_FunctionArgument("sender", IR_IntegerDatatype)
override def generateFct() : IR_PlainFunction = {
val fctBody = ListBuffer[IR_Statement]()
fctBody += IR_Return(callExtFunction("MPI_Bcast",
str.access, len.access, IR_Native("MPI_CHAR"), sender.access, Knowledge.mpi_defaultCommunicator))
IR_PlainFunction(
name,
IR_IntegerDatatype,
ListBuffer(str, len, sender),
fctBody
)
}
override def name : String = "visit_broadcast_string_callback"
}
case class IR_VisItSlaveProcessCallback() extends IR_VisItFuturePlainFunction {
override def generateFct() : IR_PlainFunction = {
val fctBody = ListBuffer[IR_Statement]()
val cmdDecl = IR_VariableDeclaration(IR_IntegerDatatype, "command", IR_IntegerConstant(0))
fctBody += cmdDecl
fctBody += callExtFunction("MPI_Bcast",
IR_AddressOf(IR_VariableAccess(cmdDecl)), IR_IntegerConstant(1), IR_Native("MPI_INT"), IR_IntegerConstant(0), Knowledge.mpi_defaultCommunicator)
IR_PlainFunction(
name,
IR_UnitDatatype,
fctBody
)
}
override def name : String = "slave_process_callback"
}
\ No newline at end of file
package exastencils.visualization.ir.visit
import scala.collection.mutable.ListBuffer
import exastencils.base.ir._
/// IR_VisItControlCommandCallback
// implement functionality for the control buttons on the GUI
case class IR_VisItControlCommandCallback() extends IR_VisItFuturePlainFunction {
override def generateFct() : IR_PlainFunction = {
val fctBody = ListBuffer[IR_Statement]()
val cmd = IR_VariableAccess("cmd", IR_SpecialDatatype("const char*"))
fctBody += IR_VisItCommandHandling(cmd)
IR_PlainFunction(
name,
IR_UnitDatatype,
ListBuffer(IR_FunctionArgument(cmd), IR_FunctionArgument("args", IR_SpecialDatatype("const char*")), IR_FunctionArgument("cbdata", IR_PointerDatatype(IR_UnitDatatype))),
fctBody
)
}
override def name : String = "ControlCommandCallback"
}
package exastencils.visualization.ir.visit
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ListBuffer
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir._
import exastencils.baseExt.ir._
import exastencils.config._
case class IR_VisItDestroy() extends IR_VisItFuturePlainFunction {
import exastencils.visualization.ir.visit.IR_VisItUtil._
override def generateFct() : IR_PlainFunction = {
val fctBody = ListBuffer[IR_Statement]()
fctBody += callExtFunction("VisItCloseTraceFile")
// free coords array
if (useRectMesh()) {
for (coords <- coordsArrays.distinct) {
for (dim <- 0 until Knowledge.dimensionality) {
val arrayIndices = ArrayBuffer[IR_Expression]()
if (Knowledge.dimensionality > 1) arrayIndices += IR_IntegerConstant(dim)
if (Knowledge.numLevels > 1) arrayIndices += IR_LoopOverLevels.defIt - Knowledge.minLevel
val coordsAccess = if (arrayIndices.isEmpty) {
coords
} else if (arrayIndices.length == 1) {
IR_ArrayAccess(coords, arrayIndices.head)
} else {
IR_MultiDimArrayAccess(coords, IR_ExpressionIndex(arrayIndices.toArray))
}
fctBody += IR_LoopOverLevels(
IR_IfCondition(
coordsAccess,
ListBuffer[IR_Statement](
IR_ArrayFree(coordsAccess),
IR_Assignment(coordsAccess, IR_IntegerConstant(0)))))
}
}
}
// free curve coords
if (useCurveMesh()) {
for (curveCoords <- curveCoordsArrays.distinct) {
for (dim <- 0 until Knowledge.dimensionality) {
val arrayIndices = ArrayBuffer[IR_Expression]()
if (Knowledge.dimensionality > 1) arrayIndices += IR_IntegerConstant(dim)
if (Knowledge.numLevels > 1) arrayIndices += IR_LoopOverLevels.defIt - Knowledge.minLevel
val curveCoordsAccess = if (arrayIndices.isEmpty) {
curveCoords
} else if (arrayIndices.length == 1) {
IR_ArrayAccess(curveCoords, arrayIndices.head)
} else {
IR_MultiDimArrayAccess(curveCoords, IR_ExpressionIndex(arrayIndices.toArray))
}
fctBody += IR_LoopOverLevels(
IR_IfCondition(
curveCoordsAccess,
ListBuffer[IR_Statement](
IR_ArrayFree(curveCoordsAccess),
IR_Assignment(curveCoordsAccess, IR_IntegerConstant(0))))
)
}
}
}
IR_PlainFunction(
name,
IR_UnitDatatype,
fctBody
)
}
override def name : String = "visit_destroy"
}
package exastencils.visualization.ir.visit
import exastencils.base.ir.IR_FuturePlainFunction
trait IR_VisItFuturePlainFunction extends IR_FuturePlainFunction {
allowInlining = false
override def name_=(newName : String) : Unit = name = newName
override def prettyprint_decl() : String = prettyprint()
}
package exastencils.visualization.ir.visit
import scala.collection.mutable.ListBuffer
import exastencils.base.ir._
import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.baseExt.ir.IR_ArrayDatatype
import exastencils.config.Knowledge
import exastencils.field.ir.IR_FieldCollection
object IR_VisItGlobals {
val simDoneDecl = IR_VariableDeclaration(IR_BooleanDatatype, "sim_done", IR_BooleanConstant(false))
val simDone = IR_VariableAccess(simDoneDecl)
val curSlotDecl = IR_VariableDeclaration(IR_IntegerDatatype, "cur_slot", 0)
val curSlot = IR_VariableAccess(curSlotDecl)
val curLevelDecl = IR_VariableDeclaration(IR_IntegerDatatype, "cur_level", Knowledge.maxLevel)
val curLevel = IR_VariableAccess(curLevelDecl)
val simTimeDecl = IR_VariableDeclaration(IR_DoubleDatatype, "sim_time", IR_DoubleConstant(0.0))
val simTime = IR_VariableAccess(simTimeDecl)
val simCycleDecl = IR_VariableDeclaration(IR_IntegerDatatype, "sim_cycle", IR_IntegerConstant(0))
val simCycle = IR_VariableAccess(simCycleDecl)
val runModeDecl = IR_VariableDeclaration(IR_BooleanDatatype, "visit_runMode", IR_BooleanConstant(false))
val runMode = IR_VariableAccess(runModeDecl)
val updatePlotsDecl = IR_VariableDeclaration(IR_BooleanDatatype, "visit_updatePlots", IR_BooleanConstant(true))
val updatePlots = IR_VariableAccess(updatePlotsDecl)