Polycute



Chain Reversi is now available as an Android App!
Android app on Google Play

A Heterogeneous Parallel Programming Language and Compiler Architecture

Polycute is an imperative-like programming language with block structures that have parallel semantics, no requirement for a global shared memory, and data structures and types that support the resultant programming paradigm. Polycute's block structures allow programmers to compose code fragments that are parallel in nature in much the same way as they would sequential code fragments. Many of the concepts used by Polycute are also good targets for compiler optimisation.

The current version of Polycute is: 2013072501. Polycute Source and Documentation

Example Program

This program calculates an oversampled Mandelbrot set using the escape time algorithm. Note the sync and spawn keywords: these allow the iterations of the loop to be executed in parallel. In addition to the simple parallelisation that is presented here, important concepts supported by Polycute include:

int 8 [] CalculateMandelbrotPolycuteDynVect(int 32 width, int 32 height)
{
    int 8 [] data = int 8 [width * height];
    int 32 factor = 16;
    
    sync for (int 32 imgy to height) {
        for (int 32 imgx to width) spawn {
            int 32 total = 0;
            
            for (int 32 suby to factor){
                for (int 32 subx to factor){
                    float 32 x0 = (0.0 - 2.5) + (3.5 * float 32(imgx * factor + subx)/float 32(width * factor));
                    float 32 y0 = (0.0 - 1.0) + (2.0 * float 32(imgy * factor + suby)/float 32(height * factor));
                    float 32 x = 0.0;
                    float 32 y = 0.0;
                    
                    int 32 i = 0;
                    bool loop = true;
                    while ((i < 255) & ((x*x + y*y) < 4.0)){
                        float 32 xtemp = x*x - y*y + x0;
                        y = 2.0*x*y + y0;
                        x = xtemp;
                        
                        i = i + 1;
                    }
                    
                    total = total + i;
                }
            }
            
            total = total / (factor*factor);
            if (total > 255){
                total = 255;
            }
            
            data[(imgy * width) + imgx] = total;
        }
    }
    
    return data;
}

export ccall void CalculateMandelbrot(int 8 pointer data, int 32 width, int 32 height)
{
    int 8 [] dvdata = CalculateMandelbrotPolycuteDynVect(width, height);
    for (int 32 i to width * height){
        data[(i * 3) + 0] = dvdata[i];
        data[(i * 3) + 1] = dvdata[i];
        data[(i * 3) + 2] = dvdata[i];
    }
}