val context = new Context
val indexMap = iterationInfo.getIndexMappings
+ val lhsFragment = lhs.getFragment(indexMap)
val rhsFragment = rhs.getFragment(indexMap)
rhsFragment.setup(context)
+ lhsFragment.setValue(context, rhsFragment.getValue)
rhsFragment.teardown(context)
val generator = new FortranGenerator
import ofc.codegen._
class InnerProduct(left: Field, right: Field) extends Scalar {
-
- class LocalFragment(left: FieldFragment, right: FieldFragment) extends ScalarFragment {
+ class LocalFragment(left: FieldFragment, right: FieldFragment) extends ScalarFragment with NonAssignableScalarFragment {
val result = new DeclaredVarSymbol[FloatType]("inner_product_result")
val leftDense = left.toDensePsinc
val rightDense = right.toDensePsinc
Seq(("elem", new IntType),
("mat", OnetepTypes.SPAM3),
("rowcol", new CharType)))
+
+ val sparse_put_element_real = new FortranSubroutineSignature("sparse_put_element_real",
+ Seq(("el", new FloatType),
+ ("mat", OnetepTypes.SPAM3),
+ ("jrow", new IntType),
+ ("jcol", new IntType)))
+
}
package ofc.generators.onetep
import ofc.codegen._
-class SPAM3(name : String, indices: Seq[NamedIndex]) extends Scalar {
+class SPAM3(name : String, position: Seq[NamedIndex]) extends Scalar {
val mat = new NamedUnboundVarSymbol[StructType](name, OnetepTypes.SPAM3)
- class LocalFragment extends ScalarFragment {
+ class LocalFragment(row: Expression[IntType], col: Expression[IntType]) extends ScalarFragment {
def setup(context: GenerationContext) {
}
- def getValue = throw new ofc.UnimplementedException("rargh!")
+ def getValue = throw new ofc.UnimplementedException("get unimplemented for SPAM3")
+
+ def setValue(context: GenerationContext, value: Expression[FloatType]) {
+ val functionCall = new FunctionCall(OnetepFunctions.sparse_put_element_real,
+ Seq(value, mat, row, col))
+ context += new FunctionCallStatement(functionCall)
+ }
def teardown(context: GenerationContext) {
}
}
def getFragment(indices: Map[NamedIndex, Expression[IntType]]) : ScalarFragment =
- new LocalFragment
+ new LocalFragment(indices.get(position(0)).get, indices.get(position(1)).get)
def getIterationInfo : IterationInfo = {
val context = new IterationContext
context.addPredicate(index.at(rowIdx) |==| rowAtom)
var indexMappings : Map[NamedIndex, Expression[IntType]] = Map.empty
- indexMappings += indices(0) -> row
- indexMappings += indices(1) -> col
+ indexMappings += position(0) -> row
+ indexMappings += position(1) -> col
new IterationInfo(context, indexMappings)
}
trait ScalarFragment extends Fragment {
def getValue : Expression[FloatType]
+ def setValue(context: GenerationContext, value: Expression[FloatType])
+}
+
+trait NonAssignableScalarFragment {
+ def setValue(context: GenerationContext, value: Expression[FloatType]) {
+ throw new ofc.LogicError("Expression: "+this+" is not assignable.")
+ }
}