How to use pyccel - 10 common examples

To help you get started, we’ve selected a few pyccel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyccel / pyccel / tests / test_codegen.py View on Github external
def test_FunctionDef():
    from test_parser import test_FunctionDef as test
    ast = test()

    for stmt in ast.statements:
        if isinstance(stmt, FunctionDefStmt):
            code    = fcode(stmt.expr)

            prelude = ""
            for s in stmt.declarations:
                prelude += fcode(s) + "\n"
#            print prelude
            print code
# ...
github pyccel / pyccel / tests / test_codegen.py View on Github external
def test_Import():
    from test_parser import test_Import as test
    ast = test()

    for stmt in ast.statements:
        if isinstance(stmt, ImportFromStmt):
            code = fcode(stmt.expr)
            print code
# ...
github pyccel / pyccel / tests / old / scripts / mpi / core / gather.py View on Github external
from pyccel.stdlib.parallel.mpi import mpi_comm_world
from pyccel.stdlib.parallel.mpi import mpi_status_size
from pyccel.stdlib.parallel.mpi import mpi_gather
from pyccel.stdlib.parallel.mpi import MPI_INTEGER

# we need to declare these variables somehow,
# since we are calling mpi subroutines
ierr = -1
size = -1
rank = -1

mpi_init(ierr)

comm = mpi_comm_world
mpi_comm_size(comm, size, ierr)
mpi_comm_rank(comm, rank, ierr)

master    = 1
nb_values = 8

block_length = nb_values / size

# ...
values = zeros(block_length, int)
for i in range(0, block_length):
    values[i] = 1000 + rank*nb_values + i

print('I, process ', rank, 'sent my values array : ', values)
# ...

# ...
data = zeros(nb_values, int)
github pyccel / pyccel / tests / old / scripts / mpi / core / cart2d_1.py View on Github external
size = -1

# rank in comm worl
rank = -1

# rank is 2d cart
rank_in_topo = -1

# 2d cart communicator
comm_2d = -1

mpi_init(ierr)

comm = mpi_comm_world
mpi_comm_size(comm, size, ierr)
mpi_comm_rank(comm, rank, ierr)

north = 0
east  = 1
south = 2
west  = 3

ndims   = 2
steps   = [1, 1]
dims    = [2, 2]
periods = [False, True]

reorder = False

neighbor = zeros(4, int)
coords   = zeros(2, int)
github pyccel / pyccel / tests / old / scripts / mpi / core / sendrecv_replace.py View on Github external
from pyccel.stdlib.parallel.mpi import mpi_comm_world
from pyccel.stdlib.parallel.mpi import mpi_status_size
from pyccel.stdlib.parallel.mpi import mpi_sendrecv_replace
from pyccel.stdlib.parallel.mpi import MPI_INTEGER

# we need to declare these variables somehow,
# since we are calling mpi subroutines
ierr = -1
size = -1
rank = -1

mpi_init(ierr)

comm = mpi_comm_world
mpi_comm_size(comm, size, ierr)
mpi_comm_rank(comm, rank, ierr)

if rank == 0:
    partner = 1

if rank == 1:
    partner = 0

msg = rank + 1000
tag = 1234
status = zeros(mpi_status_size, int)

mpi_sendrecv_replace(msg, 1, MPI_INTEGER, partner, tag,
                     partner, tag,
                     comm, status, ierr)

print('I, process ', rank, ', I received', msg, ' from process ', partner)
github pyccel / pyccel / tests / old / scripts / mpi / core / scatter.py View on Github external
from pyccel.stdlib.parallel.mpi import mpi_comm_world
from pyccel.stdlib.parallel.mpi import mpi_status_size
from pyccel.stdlib.parallel.mpi import mpi_scatter
from pyccel.stdlib.parallel.mpi import MPI_INTEGER

# we need to declare these variables somehow,
# since we are calling mpi subroutines
ierr = -1
size = -1
rank = -1

mpi_init(ierr)

comm = mpi_comm_world
mpi_comm_size(comm, size, ierr)
mpi_comm_rank(comm, rank, ierr)

master    = 1
nb_values = 8

block_length = nb_values / size

data = zeros(block_length, int)

if rank == master:
    values = zeros(nb_values, int)
    for i in range(0, nb_values):
        values[i] = 1000 + i

    print('I, process ', rank ,' send my values array', values)

mpi_scatter (values, block_length, MPI_INTEGER,
github pyccel / pyccel / tests / old / scripts / mpi / core / alltoall.py View on Github external
from pyccel.stdlib.parallel.mpi import mpi_comm_world
from pyccel.stdlib.parallel.mpi import mpi_status_size
from pyccel.stdlib.parallel.mpi import mpi_alltoall
from pyccel.stdlib.parallel.mpi import MPI_INTEGER

# we need to declare these variables somehow,
# since we are calling mpi subroutines
ierr = -1
size = -1
rank = -1

mpi_init(ierr)

comm = mpi_comm_world
mpi_comm_size(comm, size, ierr)
mpi_comm_rank(comm, rank, ierr)

nb_values = 8

block_length = nb_values / size

# ...
values = zeros(nb_values, int)
for i in range(0, nb_values):
    values[i] = 1000 + rank*nb_values + i

print('I, process ', rank, 'sent my values array : ', values)
# ...

# ...
data = zeros(nb_values, int)
github pyccel / pyccel / tests / old / scripts / mpi / core / split.py View on Github external
from pyccel.stdlib.parallel.mpi import mpi_comm_split
from pyccel.stdlib.parallel.mpi import mpi_comm_free
from pyccel.stdlib.parallel.mpi import mpi_bcast
from pyccel.stdlib.parallel.mpi import MPI_INTEGER

# we need to declare these variables somehow,
# since we are calling mpi subroutines
ierr = -1
size = -1
rank_in_world = -1

mpi_init(ierr)

comm = mpi_comm_world
mpi_comm_size(comm, size, ierr)
mpi_comm_rank(comm, rank_in_world, ierr)

master = 0
m      = 8

a = zeros(m, int)

if rank_in_world == 1:
    a = 1
if rank_in_world == 2:
    a = 2

key = rank_in_world
if rank_in_world == 1:
    key = -1
if rank_in_world == 2:
    key = -1
github pyccel / pyccel / tests / epyccel / modules / loops.py View on Github external
@types( int )
def fibonacci( n ):
    x = 0
    y = 1
    for i in range( n ): # pylint: disable=unused-variable
        z = x+y
        x = y
        y = z
    return x
github pyccel / pyccel / tests / epyccel / recognised_functions / test_numpy_funcs.py View on Github external
    @types('int')
    def create_full_val(val):
        from numpy import full
        a = full(3,val)
        return a[0],a[1],a[2]
    @types('int')