Running Opensim parallel
- Paulien Roos
- Posts: 5
- Joined: Thu Aug 12, 2010 3:02 am
Running Opensim parallel
Hi,
Could anyone tell me if OpenSim can run parallel using threads (i.e. OpenMP or MPI), or if this will be possible in the near future?
Thanks,
Paulien
Could anyone tell me if OpenSim can run parallel using threads (i.e. OpenMP or MPI), or if this will be possible in the near future?
Thanks,
Paulien
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
RE: Running Opensim parallel
Hi Paulien,
There's currently nothing in the works in this regard primarily because the nature of our time consuming calculations is not parallelizable (e.g. CMC which integrates forward in time). What's your specific use case?
Best regards,
-Ayman
There's currently nothing in the works in this regard primarily because the nature of our time consuming calculations is not parallelizable (e.g. CMC which integrates forward in time). What's your specific use case?
Best regards,
-Ayman
- Paulien Roos
- Posts: 5
- Joined: Thu Aug 12, 2010 3:02 am
RE: Running Opensim parallel
Hi Ayman,
Thank you for your reply.
It's mainly a question out of interest. I'm planning a study where we'll optimize an Opensim model together with a different model, and was wondering if this could be done faster by running opensim parallel, as we can run our other model parallel. However I do understand now that the CMC cannot be run parallel.
Thank you,
Paulien
Thank you for your reply.
It's mainly a question out of interest. I'm planning a study where we'll optimize an Opensim model together with a different model, and was wondering if this could be done faster by running opensim parallel, as we can run our other model parallel. However I do understand now that the CMC cannot be run parallel.
Thank you,
Paulien
- Sina Porsa
- Posts: 99
- Joined: Thu Feb 03, 2011 7:21 pm
Re: Running Opensim parallel
Hi Ayman,
I have the same question. I was wondering if I can use OpenMP to perform independent forward dynamics in parallel.
I want to find the optimum excitation pattern in muscles which minimizes/maximizes my cost function.
here is a brief description of my algorithm:
// load osim model
// while (flag = false)
// generate random excitation pattern
// perform FD using the generated excitation pattern
// calculate the cost and evaluate the flag
// end of while
the iterations in the while loop are completely independent. But when I want to use OpenMP, it ends up with errors. I was wondering if sth is wrong in my code or maybe opensim cannot run on parallel threads.
Thanks,
Sina
I have the same question. I was wondering if I can use OpenMP to perform independent forward dynamics in parallel.
I want to find the optimum excitation pattern in muscles which minimizes/maximizes my cost function.
here is a brief description of my algorithm:
// load osim model
// while (flag = false)
// generate random excitation pattern
// perform FD using the generated excitation pattern
// calculate the cost and evaluate the flag
// end of while
the iterations in the while loop are completely independent. But when I want to use OpenMP, it ends up with errors. I was wondering if sth is wrong in my code or maybe opensim cannot run on parallel threads.
Thanks,
Sina
- Michael Sherman
- Posts: 807
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Running Opensim parallel
Hi, Sina.
For your application you might be able to use Simbody's SimTK::ParallelExecutor class, which is available when using the OpenSim API (if that's what you're doing). Have a look at the doxygen description here:
https://simtk.org/api_docs/simbody/api_ ... cutor.html
Regards,
Sherm
For your application you might be able to use Simbody's SimTK::ParallelExecutor class, which is available when using the OpenSim API (if that's what you're doing). Have a look at the doxygen description here:
https://simtk.org/api_docs/simbody/api_ ... cutor.html
Regards,
Sherm
- Sina Porsa
- Posts: 99
- Joined: Thu Feb 03, 2011 7:21 pm
Re: Running Opensim parallel
Hi Sherm and thanks for your reply;
It seems that this ParallelExecuter can help me. But I do have some problems, maybe because I am not an expert of C++ and API.
It is not clear for me how can I define a new Task class. To be more clear, if I let's consider this:
i know I should have sth like this:
But it is not clear for me how can I define the initialize, finish and execute functions of the task class (calculateTheCost). It would be great if you could help me to solve this problem.
Thanks,
Sina
It seems that this ParallelExecuter can help me. But I do have some problems, maybe because I am not an expert of C++ and API.
It is not clear for me how can I define a new Task class. To be more clear, if I let's consider this:
i know I should have sth like this:
Code: Select all
ParallelExecutor executor;
SimTK::ParallelExecutor::Task & calculateTheCost();
executor.execute(calculateTheCost, times);
Thanks,
Sina
- Michael Sherman
- Posts: 807
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Running Opensim parallel
Hi, Sina.
You have to make a concrete class that derives from the abstract base class ParallelExecutor::Task. Your concrete class then implements the virtual methods defined by the base class.
Below is an example I grabbed from a Simbody unit test for ParallelExecutor. Your class would have the same three methods, but everything else you see here is just specific to "SetFlagTask".
Sherm
You have to make a concrete class that derives from the abstract base class ParallelExecutor::Task. Your concrete class then implements the virtual methods defined by the base class.
Below is an example I grabbed from a Simbody unit test for ParallelExecutor. Your class would have the same three methods, but everything else you see here is just specific to "SetFlagTask".
Sherm
Code: Select all
class SetFlagTask : public ParallelExecutor::Task {
public:
SetFlagTask(Array_<int>& flags, int& count) : flags(flags), count(count) {
}
void execute(int index) {
flags[index]++;
localCount.upd()++;
ASSERT(ParallelExecutor::isWorkerThread() == isParallel);
}
void initialize() {
localCount.upd() = 0;
ASSERT(ParallelExecutor::isWorkerThread() == isParallel);
}
void finish() {
count += localCount.get();
ASSERT(ParallelExecutor::isWorkerThread() == isParallel);
}
private:
Array_<int>& flags;
int& count;
ThreadLocal<int> localCount;
};
- Sina Porsa
- Posts: 99
- Joined: Thu Feb 03, 2011 7:21 pm
Re: Running Opensim parallel
Hi Sherm,
I have another problem with this parallel executor. Memory leakage!
Here is what I do in the execute function:
any idea how should I solve this problem?
Thanks,
Sina
I have another problem with this parallel executor. Memory leakage!
Here is what I do in the execute function:
Code: Select all
void execute(int index) {
Model myModel = loadedModel; // loaded model is a global variable. I want to load the model from an *.OSIM file just once.
//creat a controller
PrescribedController *muscleController= new PrescribedController();
muscleController->setActuators(osimModel.updActuators());
try {
double muscle1ExcVec[numOfNodes];
double muscle2ExcVec[numOfNodes];
for (int n=0; n<numOfNodes; n++){
muscle1ExcVec[n] = input[whichPage][0][n];// excitation[0][n];
muscle2ExcVec[n] = input[whichPage][1][n];// excitation[1][n];
}
// Set the indiviudal muscle control functions for the prescribed muscle controller
muscleController->prescribeControlForActuator("muscle1", new PiecewiseLinearFunction(numOfNodes, timeVec, muscle1ExcVec));
muscleController->prescribeControlForActuator("muscle2", new PiecewiseLinearFunction(numOfNodes, timeVec, muscle2ExcVec));
//add the controller to myModel
...
// Perform forward dynamics (define system, integrator and manager and integrate the equations)
...
}//end of try
} // end of execute
Thanks,
Sina
- Michael Sherman
- Posts: 807
- Joined: Fri Apr 01, 2005 6:05 pm
Re: Running Opensim parallel
Hi, Sina. You're making a copy of the Model and then a bunch of changes to it every time you execute. I believe OpenSim does have a Model memory leak that we noticed recently. Can you arrange to build the model only once and then treat it as read-only during execution?
Regards,
Sherm
Regards,
Sherm