Exemplo n.º 1
0
    def test2(self):
        kmax = 32
        M = N = 5

        real_min = -2.0
        real_max = 1.0
        imag_min = -1.5
        imag_max = 1.5
        A = calculate_region(real_min, real_max, imag_min, imag_max, kmax, M,
                             N)

        assert numpy.allclose(
            A, [[1, 1, 1, 1, 1], [1, 3, 5, 5, 3], [2, 4, 9, 9, 4],
                [2, 9, 32, 32, 9], [2, 3, 15, 15, 3]])
Exemplo n.º 2
0
    def test2(self):
        kmax = 32
        M = N = 5

        real_min = -2.0
        real_max = 1.0
        imag_min = -1.5
        imag_max = 1.5
        A = calculate_region(real_min, real_max,
                imag_min, imag_max, kmax, M, N)

        assert numpy.allclose(A,
                              [[1,  1,  1,  1,  1],
                               [1,  3,  5,  5,  3],
                               [2,  4,  9,  9,  4],
                               [2,  9, 32, 32,  9],
                               [2,  3, 15, 15,  3]])
Exemplo n.º 3
0
    def test3(self):
        kmax = 32
        M = N = 100

        real_min = -2.0
        real_max = 1.0
        imag_min = -1.5
        imag_max = 1.5
        A = calculate_region(real_min, real_max, imag_min, imag_max, kmax, M,
                             N)

        assert numpy.allclose(A[:, 50], [
            32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32, 16, 11, 9, 7, 7, 6, 5, 5, 5, 4, 4,
            4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
        ])
Exemplo n.º 4
0
    def test3(self):
        kmax = 32
        M = N = 100

        real_min = -2.0
        real_max = 1.0
        imag_min = -1.5
        imag_max = 1.5
        A = calculate_region(real_min, real_max,
                imag_min, imag_max, kmax, M, N)

        assert numpy.allclose(A[:, 50],
        [32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
         32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
         32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
         32, 32, 32, 32, 32, 32, 32, 32,
         32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
         32, 32, 32, 32, 32, 32, 32, 32,
         32, 32, 16, 11,  9,  7,  7,  6,  5,  5,  5,  4,  4,  4,  4,  4,
         3, 3,  3,  3,  3,  3,  3,  3, 3,  3])
Exemplo n.º 5
0
"""Sequential program computing the Mandelbrot set.

Ole Nielsen, SUT 2003
"""

from mandelbrot import calculate_region
from mandelplot import plot
import time

# User definable parameters
kmax = 2**15  # Maximal number of iterations (=number of colors)
M = N = 700  # width = height = N (200, 400, 600, 700 are good)
#M = N = 400   # width = height = N (200, 400, 600, 700 are good)

# Region in complex plane
real_min = -2.0
real_max = 1.0
imag_min = -1.5
imag_max = 1.5

# Compute Mandelbrot set
t0 = time.time()
A = calculate_region(real_min, real_max, imag_min, imag_max, kmax, M, N)
print 'Computed region in %.2f seconds' % (time.time() - t0)

# Plot result
try:
    plot(A, kmax)
except:
    pass
Exemplo n.º 6
0
            # Send new work to slave d
            pypar.send(workpool[w], destination=d, tag=work_tag)
            w += 1
        else:
            # Tell slave d to terminate
            pypar.send(None, destination=d, tag=work_tag)
            terminated += 1

    print 'Computed region in %.2f seconds' % (pypar.time() - t)
    try:
        plot(A, kmax)
    except:
        pass
else:
    while(True):
        # Receive work (or None)
        W = pypar.receive(source=0, tag=work_tag)

        if W is None:
            print 'Slave p%d finished: time = %.2f' % (p, pypar.time() - t)
            break

        # Compute allocated work
        A = calculate_region(real_min, real_max, imag_min, imag_max, kmax,
                             M, N, Mlo=W[0], Mhi=W[1])

        # Return result
        pypar.send(A, destination=0, tag=result_tag)

pypar.finalize()
Exemplo n.º 7
0
    print 'Computed region in %.2f seconds' % (pypar.time() - t)
    try:
        plot(A, kmax)
    except:
        pass
else:
    while (True):
        # Receive work (or None)
        W = pypar.receive(source=0, tag=work_tag)

        if W is None:
            print 'Slave p%d finished: time = %.2f' % (p, pypar.time() - t)
            break

        # Compute allocated work
        A = calculate_region(real_min,
                             real_max,
                             imag_min,
                             imag_max,
                             kmax,
                             M,
                             N,
                             Mlo=W[0],
                             Mhi=W[1])

        # Return result
        pypar.send(A, destination=0, tag=result_tag)

pypar.finalize()
Exemplo n.º 8
0
#Initialise
t = pypar.time()
P = pypar.size()
p = pypar.rank()
processor_name = pypar.get_processor_name()

print 'Processor %d initialised on node %s' %(p,processor_name)


# Balanced work partitioning (row wise)
Mlo, Mhi = pypar.balance(M, P, p)
print 'p%d: [%d, %d], Interval length=%d' %(p, Mlo, Mhi, Mhi-Mlo)

# Parallel computation 
A = calculate_region(real_min, real_max, imag_min, imag_max, kmax,
                     M, N, Mlo = Mlo, Mhi = Mhi)

print 'Processor %d: time = %.2f' %(p, pypar.time() - t)


# Communication phase
if p == 0:
    for d in range(1, P):
        A += pypar.receive(source=d)

    print 'Computed region in %.2f seconds' %(pypar.time()-t)
    try:
        plot(A, kmax)
    except:
        pass    
else:
Exemplo n.º 9
0
Ole Nielsen, SUT 2003
"""

from mandelbrot import calculate_region
from mandelplot import plot
import time

# User definable parameters
kmax = 2**15  # Maximal number of iterations (=number of colors)
M = N = 700   # width = height = N (200, 400, 600, 700 are good)
#M = N = 400   # width = height = N (200, 400, 600, 700 are good)

# Region in complex plane
real_min = -2.0
real_max =  1.0
imag_min = -1.5
imag_max =  1.5

# Compute Mandelbrot set
t0 = time.time()
A = calculate_region(real_min, real_max, imag_min, imag_max, kmax, M, N)
print 'Computed region in %.2f seconds' %(time.time()-t0)

# Plot result
try:
    plot(A, kmax)
except:
    pass    


Exemplo n.º 10
0
# Initialise
t = pypar.time()
P = pypar.size()
p = pypar.rank()
processor_name = pypar.get_processor_name()

print 'Processor %d initialised on node %s' % (p, processor_name)


# Balanced work partitioning (row wise)
Mlo, Mhi = pypar.balance(M, P, p)
print 'p%d: [%d, %d], Interval length=%d' % (p, Mlo, Mhi, Mhi - Mlo)

# Parallel computation
A = calculate_region(real_min, real_max, imag_min, imag_max, kmax,
                     M, N, Mlo=Mlo, Mhi=Mhi)

print 'Processor %d: time = %.2f' % (p, pypar.time() - t)


# Communication phase
if p == 0:
    for d in range(1, P):
        A += pypar.receive(source=d)

    print 'Computed region in %.2f seconds' % (pypar.time() - t)
    try:
        plot(A, kmax)
    except:
        pass
else: