These are chat archives for allwinpb/poop

Mar 2015
Mar 27 2015 02:06

Global variable i remembers the available free slots in the CarPark. It can hold up to M cars.

define M 4;

var i=M;

Car1() = [i>0 && i<=M] arrive { i=i-1 } -> Car1()
[] [i>=0 && i<M] depart { i=i+1 } -> Car1();
Car2() = [i>0 && i<=M] arrive { i=i-1 } -> Car2()
[] [i>=0 && i<M] depart { i=i+1 } -> Car2();
CarPark() = Car1() || Car2();

Mar 27 2015 02:16
public class MatrixMultiply{
    // Matrix A and B are multiplied to give C.
    // We define both matrix A and B to be a square matrix
    // to make our lives easier
    val matrixA: Rail[Long](2);
    val matrixB: Rail[Long](2);
    val matrixC: Rail[Long](2);

    public def this(matrixSize: Int){
        matrixA = new Rail[Long]((0..matrixSize)*(0..matrixSize), 1);
        matrixB = new Rail[Long]((0..matrixSize)*(0..matrixSize), 1);
        matrixC = new Rail[Long]((0..matrixSize)*(0..matrixSize), 1);

        // Init all matrix values to 0, we don't really care
        // about the value of the multiplication here, just the
        // order.
        for(i in 0..(matrixSize-1)){
            for(j in 0..(matrixSize-1)){
                matrixA(i,j) = 0;
                matrixB(i,j) = 0;
                matrixC(i,j) = 0;

    // This represents calculating one slot in
    // matrixC or 1 task as defined in the assignment
    def runTask(a: Int, b:Int, matrixSize: Int){
        for(i in a..(b-1)){
            for(j in 0..(matrixSize-1)){
                matrixC(i,j) += matrixA(i,j) * matrixB(i,j);

    def multiply(matrixSize: Int, fork: Int){
        var border = matrixSize / fork;
        finish for (t in 0..(fork-1)) async{
            val a = t * border;
            val b = (t == (fork-1)) ? matrixSize : (t+1) * border;
            runTask(a, b, matrixSize);

    public static def main(args:Rail[String]){
        if(args.size == 0){
            Console.OUT.println("Define size of matrix");
            val matrixSize = Int.parse(args(0));
            val matrix = new MatrixMultiply(matrixSize);
            // Set it to 2 threads. Play around with
            // value to tweak parallelism
            matrix.multiply(matrixSize, 2);

The maximum degree of parallelism that can be obtained for multiplying to $n X n$ matrices is $n^2$ \

This is the maximum degree of parallelism that can be obtained for matrix multiplication as it would not be possible to break the steps even further into sub problems as it would now introduce dependencies between tasks.

Mar 27 2015 02:28

CS3243 Tutorial 6
Allwin Baby

No. KB consists of P(a) and P(b). KB entails the sentence (for all x, P(x)) if KB implies the same. However KB only consists of a subset of the truth table for (for all x, P(x)). Hence KB does not entail this sentence.
The given sentence is not valid. Validity implies the statement is true in all models. The model x = {0,1} and y = {2,3} does not confirm to this rule. Hence it is not valid.
Let W(i,j) be true if there is a Wumpus in i,j.
Let A(i,j) be true if there is player in i,j.
Let G be true if player is dead.
Let Gr(i,j) be true if there is glitter in i,j.
Let Gd(i,j) be true if there is gold in i,j.
Let Pt(i,j) be true if there is a pit in i,j.
W(i,j) ^ P(i,j) ==> G
Gr(i,j) ==> Gd(i,j)
Pt(i,j) V ~Pt(i,j)