Git Product home page Git Product logo

Comments (6)

bknight1 avatar bknight1 commented on July 30, 2024

Hi @gp37,

UW has a built in function to reduce values to root. You can try the following:

import underworld.function as fn
### reduce x, y and temperatureField to  root proc
x = fn.input()[0].evaluate_global(mesh.data)
y = fn.input()[1].evaluate_global(mesh.data)
T = temperatureField.evaluate_global(mesh.data)

### print the sum of the temperatureField
if rank == 0:
    print(np.sum(T))

from underworld2.

gp37 avatar gp37 commented on July 30, 2024

Thanks Ben,

I tried to implement the code above and I don't get any errors, however, the code seems to take a long time to run or is getting stuck in a loop or something. For example, I ran the above code for 5 minutes and still, I was not able to finish evaluating for x. This is true on multiple processors and just running in serial. Is this normal for the evaluate_global function?

from underworld2.

gp37 avatar gp37 commented on July 30, 2024

Giving an update, I actually get this error when running x = fn.input()[0].evaluate_global(mesh.data)

File "/opt/venv/lib/python3.10/site-packages/underworld/function/_function.py", line 744, in evaluate_global
total_output[incoming_positions] = incoming_data
IndexError: index 6633 is out of bounds for axis 0 with size 6633
Abort(1) on node 0 (rank 0 in comm 496): application called MPI_Abort(comm=0x84000002, 1) - process 0

and I am not sure how to fix that.

from underworld2.

bknight1 avatar bknight1 commented on July 30, 2024

Hi @gp37, can you share the entire block of code? It looks like you're trying to update an array in certain locations, but the incoming data should contain the entire array (if using the code above).

The evaluate_global does take a while unfortunately, we could use MPI routines but the evaluate_global is much more straight forward to use

from underworld2.

gp37 avatar gp37 commented on July 30, 2024

Hi,
Attached is a script with a simple mantle convection model in which I cannot get evaluate_global to work.


MantleConvectionParallel.ipynb.zip

from underworld2.

bknight1 avatar bknight1 commented on July 30, 2024

Hi @gp37, I've had a look and come up with the following using MPI:

### on local nodes
x = np.ascontiguousarray(mesh.data[:,0])
y = np.ascontiguousarray(mesh.data[:,1])
T = np.ascontiguousarray(temperatureField.data[:,0])



### Collect local array sizes using the high-level mpi4py gather
sendcounts = np.array(comm.gather(len(x), root=0))

if rank == 0:
### creates dummy data on all nodes to store the data that is gathered
    x_data = np.zeros((sum(sendcounts)), dtype='float64')
    y_data = np.zeros((sum(sendcounts)), dtype='float64')
    T_data = np.zeros((sum(sendcounts)), dtype='float64')
else:
    x_data = None
    y_data = None
    T_data = None
    
comm.barrier()
    
### gather data on root proc (0)
comm.Gatherv(sendbuf=x, recvbuf=(x_data, sendcounts), root=0)
comm.Gatherv(sendbuf=y, recvbuf=(y_data, sendcounts), root=0)
comm.Gatherv(sendbuf=T, recvbuf=(T_data, sendcounts), root=0)

if rank == 0:
    '''do some stuff'''
    print(x_data.shape)

Let me know how it goes

from underworld2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.