Question: This program is a basic attempt at finding a pair of twin primes each, before and after a given numerical value on the whole number line.The code looks good but is not giving any output and neither is it terminating post a run.I would like to know what is wrong with it.Thanks! 

```
public class twin {

    public boolean prime(int num) { // function to check for a prime number

        if (num % 2 == 1 && (num % 3 == 2 || num % 3 == 1)) {
            return true;

        } else
            return false;

    }

    public static void main(String args[]) { // main
        int inp_num = 7; // given number too check for twin primes before or
                            // after it
        twin ob = new twin();
        int arr[] = new int[5];
        for (int x = inp_num; x > 0; x--) { // checking limit [o,inpnum)
            boolean b = ob.prime(x);
            if (b = true) {
                if (ob.prime(x - 2) == true) {
                    arr[0] = x;
                    arr[1] = x - 2;
                }

            }

        }
        for (int x = inp_num; x >= inp_num; x++) { // checking limit
                                                    // [inpnum,infinity]
            boolean b = ob.prime(x);
            if (b = true) {

                if (ob.prime(x + 2) == true) {
                    arr[2] = x;
                    arr[3] = x + 2;
                }

            }

        }
        for (int i = 0; i < 4; i++) {
            System.out.println(arr[i] + "\t");

        }
    }
}

```

Answer: 
This version stores rows as temporaries thus reducing the effective amount of index lookups. By this [benchmark](https://jsbench.me/jil0i577tr/1) the achieved performance is almost 2 times faster if compared to the version withou storing rows.

```js
function multiply(a, b) {
    let aRows = a.length;
    let aCols = a[0].length;
    let bCols = b[0].length;
    let result = new Array(aRows); 
    for (let r = 0; r < aRows; ++r) {
        const row = new Array(bCols);
        result[r] = row;
        const ar = a[r];
        for (let c = 0; c < bCols; ++c) {
            let sum = 0.;     
            for (let i = 0; i < aCols; ++i) {
                sum += ar[i] * b[i][c];
            }
            row[c] = sum;  
        }
    }
    return result;
}

const m = multiply(
        [[8, 3], [2, 4], [3, 6]],
        [[1, 2, 3], [4, 6, 8]]
    );
console.log(m);
function display(m) {
    for (var r = 0; r < m.length; ++r) {
        document.write('&nbsp;&nbsp;'+m[r].join(' ')+'<br />');
    }
}

var a = [[8, 3], [2, 4], [3, 6]],
    b = [[1, 2, 3], [4, 6, 8]];
document.write('matrix a:<br />');
display(a);
document.write('matrix b:<br />');
display(b);
document.write('a * b =<br />');
display(multiply(a, b));
```
If you wanted to go the bonkers route, you could also possibly do something with the vertices transformation in WebGL facilities now available in some modern browsers.

Not really sure if this would work in the same way as one might approach vector transformation in OpenCL (\*\*in fact they're type-equivalent / interoperable), but the general idea is:

* adding your values to a buffer
* "pretending" it's an array of vertices
* transforming en-mass using the GPU engine
* retrieving the revised values from the vector

(see demo here)
<http://www.html5rocks.com/en/tutorials/webgl/webgl_transforms/>

Just an alternative to the usual loop-in-loop approach. And to be honest, a bit of a fiddle, given that OpenCL was designed for this kind of thing 

Within the OpenCL 1.2 spec vertex buffers from OpenGL can be loaded and transformed using OpenCL (see. <https://software.intel.com/en-us/articles/opencl-and-opengl-interoperability-tutorial>)