How to Run OpenSees in the Background

With the OpenSees AMI, it's likely you'll run long sequences of OpenSees analyses. It's even more likely you don't want to sit and wait for those analyses to finish.

It's also possible that your connection to EC2 is terminated due to local network issues or your local ssh client times out due to inactivity.

So what should you do on your OpenSees AMI instances to avoid sitting and waiting and to be resilient in the face of interruptions?

Use the screen command, which is pre-installed on every OpenSees AMI instance

This command allows you to run processes on a server, then push and pull those processes between the foreground and background whenever you like.

You can even disconnect from the server and the process will continue to run!

Let's demonstrate with a simple Python script that will take a long time to run on an OpenSees AMI instance-or any machine for that matter.

You can also use a Jupyter Notebook to run analyses and interact with your OpenSees AMI instance.


import openseespy.opensees as ops

i = 0; N = int(1e9)
while i < N:
    ops.wipe()
    ops.model('basic','-ndm',1,'-ndf',1)
    if i % 1000000 == 0:
       print(f'{i} of {N}')
    i += 1
                    

First, connect to your OpenSees AMI instance on EC2. But, before you run any scripts, issue the screen command and give your screen a name, e.g., myscreen, with the -S option. You can give whatever name you like.

screen -S myscreen
Screen

You are now in a detached screen, separate from where you started although nothing seems all that different. From here, run your OpenSees analysis using python3 or mpiexec.

Screen

To return back to your original terminal, press Ctrl+A, then D on your keyboard. You are now back where you started and you should see a [detached from xxxx.myscreen] message where xxxx is the screen id and myscreen is the screen name you assigned.

You can have multiple screens running in the background. To see them all, type screen -ls.

Screen

You can return to the background screen with the -r option and the screen name you assigned.

screen -r myscreen

You should see the analysis running.

Screen

Use Ctrl+A, then D again to go back to the original terminal.

Go back and forth at will. When you return to the background screen and see your analysis is complete, you can type exit or Ctrl+A, then K to kill the screen and return to the original terminal.

You can even log out of your instance and log back in. What's in the background screen will have kept running while you were logged out!

Try it out for yourself. Just don't stop or terminate your instance when you log out.

You can find more details on the screen command here.

Back to OpenSees AMI