Beispiel #1
0
def gendos( comm, amp, sig, inp_grid, inp_comp_grid, python = False ):
  if not python:
    import kernel.vsueig_mpi as kernel
    inp_grid_cont = c_cont( inp_grid )
    inp_comp_grid_cont = c_cont( inp_comp_grid )
    kernel.gendos( comm, amp, sig, inp_grid_cont, inp_comp_grid_cont )
    return
  # end if

  print "Python Kernel"

  rank = comm.Get_rank()
  size = comm.Get_size()

  from pypak.Math import gauss,dgauss
  # from cython.math import gauss,dgauss
  from time import clock

  i_range=len(inp_grid)
  j_range=len(inp_comp_grid[0])

  start = clock()
  # inp_grid 2d float
  # inp_comp_grid 2 float
  for i in range(0,i_range):
    mu = inp_grid[i,0]
    A  = inp_grid[i,1] * amp
    # print mu,A
    for j in range(0,j_range):
      x = inp_comp_grid[0,j]
      if abs(x-mu) > 3*sig:
        continue
      # print x
      # fx
      if( size == 1 ):
        inp_comp_grid[1,j] += gauss( x, A , mu, sig )
        inp_comp_grid[2,j] += dgauss( x, A, mu, sig )
      else:
        if( rank == 0 ):
          inp_comp_grid[1,j] += gauss( x, A , mu, sig )
        # d/dx fx
        if( rank == 1 ):
          inp_comp_grid[2,j] += dgauss( x, A, mu, sig )
      # end if
    # end for
  # end for
  elapsed = (clock() - start)
  print "%d Elapsed time: %9.6lf s" % ( rank, elapsed )
Beispiel #2
0
def gendos( amp, sig, inp_grid, inp_comp_grid, python = False ):
  if not python:
    import kernel.vsueig_omp as kernel
    inp_grid_cont = c_cont( inp_grid )
    inp_comp_grid_cont = c_cont( inp_comp_grid )
    kernel.gendos( amp, sig, inp_grid_cont, inp_comp_grid_cont )
    return
  # end if

  print "Python Kernel"

  from pypak.Math import gauss,dgauss
  # from cython.math import gauss,dgauss
  from time import clock

  i_range=len(inp_grid)
  j_range=len(inp_comp_grid[0])

  print i_range, j_range

  start = clock()
  # inp_grid 2d float
  # inp_comp_grid 2 float
  for i in range(0,i_range):
    mu = inp_grid[i,0]
    A  = inp_grid[i,1] * amp
    # print mu,A
    for j in range(0,j_range):
      x = inp_comp_grid[0,j]
      if abs(x-mu) > 3*sig:
        continue
      # print x
      # fx
      inp_comp_grid[1,j] += gauss( x, A , mu, sig )
      # d/dx fx
      inp_comp_grid[2,j] += dgauss( x, A, mu, sig )
    # end for
  # end for
  elapsed = (clock() - start)
  print "Elapsed time: %9.6lf s" % elapsed