Exemple #1
0
import mpids.MPInumpy as mpi_np
import numpy as np
from mpi4py import MPI
from operations import add, sub, mul, div

if __name__ == '__main__':
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    n_procs = comm.Get_size()
    local_size = 2**16
    size = n_procs * local_size
    iters = 1000
    mpi_np_arr = mpi_np.arange(size, dtype=np.float64)

    add_time = add(mpi_np_arr, iters=iters)
    sub_time = sub(mpi_np_arr, iters=iters)
    mul_time = mul(mpi_np_arr, iters=iters)
    div_time = div(mpi_np_arr, iters=iters)

    if rank == 0:
        print("mpi_np,add,%d,%d,%.9f" % (n_procs, local_size, add_time))
        print("mpi_np,sub,%d,%d,%.9f" % (n_procs, local_size, sub_time))
        print("mpi_np,mul,%d,%d,%.9f" % (n_procs, local_size, mul_time))
        print("mpi_np,div,%d,%d,%.9f" % (n_procs, local_size, div_time))
Exemple #2
0
import operations
operations.add(5, 6)
operations.mul(5, 6)
Exemple #3
0
import operations as op

x, y = 5, 10
print 'Using arguments:', x, y
print 'Sum:', op.add(x, y)
print 'Difference:', op.sub(arg1=x, arg2=y)
print 'Difference again:', op.sub(arg2=x, arg1=y)

x, y = 10.0, 0
print 'Using arguments:', x, y
print 'Multiplication:', op.mul(x, x)
print 'Division:', op.div(y, x)
print 'Division:', op.div(x, y)
Exemple #4
0
 choice_simcalc = input(
     "1.add\n2.sub\n3.mul\n4.div\n5.goback\nEnter your choice:")
 if choice_simcalc == 1:
     a = input("Enter first number:")
     b = input("Enter second number:")
     add = operations.add(a, b)
     print "Addition of two numbers", a, "and", b, "is", add
 elif choice_simcalc == 2:
     a = input("Enter first number:")
     b = input("Enter second number:")
     sub = operations.sub(a, b)
     print "Subtraction of two numbers", a, "and", b, "is", sub
 elif choice_simcalc == 3:
     a = input("Enter first number:")
     b = input("Enter second number:")
     mul = operations.mul(a, b)
     print "Multiplication of two numbers", a, "and", b, "is", mul
 elif choice_simcalc == 4:
     a = input("Enter first number:")
     b = input("Enter second number:")
     div = operations.div(a, b)
     print "Division of two numbers", a, "and", b, "is", div
 elif choice_simcalc == 5:
     os.system("clear")
     break
 else:
     print "Invalid Option.Please enter again."
     time.sleep(1)
     os.system("clear")
     continue
 time.sleep(1)
import operations
print(dir(operations))
print(operations.file())
print(operations.mul(4,7))
Exemple #6
0
import mpids.MPInumpy as mpi_np
import numpy as np
from operations import add, sub, mul, div

if __name__ == '__main__':
    for power in range(0, 28):
        variable_iters = 10000 if power < 18 else 10
        size = 2**power
        mpi_np_arr = mpi_np.arange(size, dtype=np.float64)
        print("mpi_np,add,%d,%.9f" %
              (size, add(mpi_np_arr, iters=variable_iters)))
        print("mpi_np,sub,%d,%.9f" %
              (size, sub(mpi_np_arr, iters=variable_iters)))
        print("mpi_np,mul,%d,%.9f" %
              (size, mul(mpi_np_arr, iters=variable_iters)))
        print("mpi_np,div,%d,%.9f" %
              (size, div(mpi_np_arr, iters=variable_iters)))
        del mpi_np_arr
Exemple #7
0
 def apply(self, grad_vars):
     a = []
     for v, g in grad_vars.items():
         a.append(op.assign(op.sub(v, op.mul(g, self.learn_rate)), v))
     return op.Group(a)
import numpy as np
from operations import add, sub, mul, div

if __name__ == '__main__':
    for power in range(0, 28):
        variable_iters = 10000 if power < 18 else 10
        size = 2**power
        np_arr = np.arange(size, dtype=np.float64)
        print("np,add,%d,%.9f" % (size, add(np_arr, iters=variable_iters)))
        print("np,sub,%d,%.9f" % (size, sub(np_arr, iters=variable_iters)))
        print("np,mul,%d,%.9f" % (size, mul(np_arr, iters=variable_iters)))
        print("np,div,%d,%.9f" % (size, div(np_arr, iters=variable_iters)))
        del np_arr
Exemple #9
0
# Approach 1:

import operations

operations.add(10, 20)
operations.mul(100, 200)  # 30 20000

# Approach 2:
from operations import add, mul

add(40, 50)
mul(5, 20)  # 90 100

# Approach 3:
from operations import *

add(10, 10)
mul(10, 10)  # 20 100
Exemple #10
0
import operations

a = operations.add(11, 22)

b = operations.sub(22, 11)

c = operations.mul(11, 2)

d = operations.div(22, 2)

print a
print b
print c
print d

print operations.PI

from my_math.geo.circle import area

result = area(12)

print result

import my_math.geo.square as sq_area

result = sq_area.area(12)

print result