Chrono Parallel Computing

251 views
Skip to first unread message

liugua...@gmail.com

unread,
Dec 5, 2017, 9:57:52 AM12/5/17
to ProjectChrono
Hi everyone:

I make a simulation using DEM method. In my system, there are 100000 particles and one obj container. 

Only using CPU parallel is not efficient., so I want to use GPU parallel. When I run the exe file and check GPU  usage, it is very strange that the GPU usage don't change and keeps to 0%.

I run the demo (demo_PAR_ballsNSC) and the GPU usage increases to 50%.
I change my project based on the demo_PAR_ballsNSC. But why happens the strange sitution?

Here is my code. Please check!

Best Wishes,
Liu
 


void AddContainer(ChSystemParallel* sys,std::string filePosition, float cohesion, float KinectFriction, float StaticFriction, float restitution, float damping, float stifness) 
{
int binId = -200;

// Create a common material
auto mat = std::make_shared<ChMaterialSurfaceNSC>();
mat->SetCohesion(cohesion);
mat->SetSfriction(StaticFriction);
mat->SetKfriction(KinectFriction);
mat->SetRestitution(restitution);
mat->SetDampingF(damping);
mat->SetCompliance(float(1.0/stifness));

// Create the containing bin (4 x 4 x 1)
auto bin = std::make_shared<ChBody>(std::make_shared<ChCollisionModelParallel>());
bin->SetMaterialSurface(mat);

bin->SetIdentifier(binId);
bin->SetMass(1);
bin->SetDensity(2800);
bin->SetPos(ChVector<>(0, 0, 0));
bin->SetCollide(true);
bin->SetBodyFixed(true);

bin->GetCollisionModel()->ClearModel();
std::string bedFilename = filePosition + "/Slope_Bed.obj";
utils::AddTriangleMeshGeometry(bin.get(), bedFilename.data(), "Slope_Bed");
bin->GetCollisionModel()->BuildModel();

sys->AddBody(bin);


}

// -----------------------------------------------------------------------------
// Create the falling spherical objects in a uniform rectangular grid.
// -----------------------------------------------------------------------------
void AddFallingBalls(ChSystemParallel* sys,std::string filePosition, float KinectFriction, float StaticFriction, float restitution, float cohesion, float damping, float stifness) 
{
// Common material
std::string spherefile = filePosition + "/SlideBody.Spheres";
std::fstream spherein(spherefile.data(), std::ios::in);
int sphereNum;
spherein >> sphereNum;

double px, py, pz, pr;
int ballId = 0;
while (spherein >> px >> py >> pz >> pr)
{

auto ballMat = std::make_shared<ChMaterialSurfaceNSC>();
ballMat->SetSfriction(StaticFriction);
ballMat->SetKfriction(KinectFriction);
ballMat->SetRestitution(restitution);
ballMat->SetCohesion(cohesion);  // Magnitude of the adhesion in Constant adhesion model
//ballMat->SetAdhesionMultDMT(adhesion);
//ballMat->SetGt(damping);
//ballMat->SetCompliance(1000000);
ballMat->SetDampingF(damping);
ballMat->SetCompliance(float(1.0 / stifness));

// Create the falling balls
ChVector<> pos(px, py, pz);
auto ball = std::make_shared<ChBody>(std::make_shared<ChCollisionModelParallel>());
ball->SetMaterialSurface(ballMat);

ball->SetIdentifier(ballId++);
float density = 2800;
double mmass = density * 4.0*CH_C_PI*pr*pr*pr / 3.0;
ChVector<> inertia = (2.0 / 5.0) * mmass * pr * pr * ChVector<>(1, 1, 1);
ball->SetMass(mmass);
ball->SetInertiaXX(inertia);
ball->SetPos(pos);
ball->SetRot(ChQuaternion<>(1, 0, 0, 0));
ball->SetBodyFixed(false);
ball->SetCollide(true);
ball->GetCollisionModel()->ClearModel();
utils::AddSphereGeometry(ball.get(), pr*1.0);
ball->GetCollisionModel()->BuildModel();
sys->AddBody(ball);
}
spherein.close();

}


// -----------------------------------------------------------------------------
// Create the system, specify simulation parameters, and run simulation loop.
// -----------------------------------------------------------------------------
int main(int argc, char* argv[]) {
int threads = 32;
std::cout << "Start slope slide simulation... Please waiting and watch the tmp file..." << endl;
// Simulation parameters (I delete that for your reading)
// ---------------------

// Create system
// -------------

ChSystemParallelNSC msystem;

// Set number of threads.
int max_threads = CHOMPfunctions::GetNumProcs();
//std::cout << "Max threads: " << max_threads << std::endl;
if (threads > max_threads)
threads = max_threads;
msystem.SetParallelThreadNumber(threads);
CHOMPfunctions::SetNumThreads(threads);

// Set gravitational acceleration
msystem.Set_G_acc(ChVector<>(gravityX, gravityY, gravityZ));

// Set solver parameters
msystem.GetSettings()->solver.solver_mode = SolverMode::SLIDING;
msystem.GetSettings()->solver.max_iteration_bilateral = max_iteration;
msystem.GetSettings()->solver.tolerance = tolerance;
msystem.GetSettings()->solver.contact_recovery_speed = 10000;
msystem.GetSettings()->solver.use_full_inertia_tensor = false;

msystem.GetSettings()->collision.narrowphase_algorithm = NarrowPhaseType::NARROWPHASE_HYBRID_MPR;
msystem.GetSettings()->collision.bins_per_axis = vec3(100, 100, 100);
msystem.GetSettings()->collision.collision_envelope = dvi_evelope;


// Create the fixed and moving bodies
// ----------------------------------

AddFallingBalls(&msystem, filePosition, Kmu, Smu, restitution, cohesion1, dampCoe, stifness1);
AddContainer(&msystem, filePosition, cohesion2, Kmu, Smu, restitution, dampCoe, stifness2);
// Perform the simulation
// ----------------------

for (int i = 0; i < num_steps; i++) {
msystem.DoStepDynamics(timestep);
if (i%out_steps == 0)
{
SaveData(&msystem, out_frame,filePosition);
out_frame++;
}
if (i % change_step == 0)
{
for (int i = 0; i < msystem.data_manager->host_data.contact_pairs.size(); i++)
{
if (msystem.data_manager->host_data.dpth_rigid_rigid[i] >= 2 * dvi_evelope*0.75)
{
msystem.Get_bodylist()->at(msystem.data_manager->host_data.bids_rigid_rigid[i].x)->GetMaterialSurfaceNSC()->SetCohesion(0);
msystem.Get_bodylist()->at(msystem.data_manager->host_data.bids_rigid_rigid[i].y)->GetMaterialSurfaceNSC()->SetCohesion(0);
}
}
}
time += timestep;
}

return 0;
}

Radu Serban

unread,
Dec 5, 2017, 10:35:00 AM12/5/17
to projec...@googlegroups.com

Liu,

Chrono::Parallel does not use the GPU for granular dynamics.  The GPU usage you see while running demo_PAR_ballsNSC is likely due to rendering (using the Chrono::OpenGL module).  You should be able to check this by disabling rendering (simply undef CHRONO_OPENGL at the top).  As for why you don't see any GPU usage while running your code that's either because you do not do any rendering or because the simulation is so slow that the GPU doesn't have much work to do in rendering.

What hardware do you use to run this simulation?

Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To post to this group, send email to projec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

liugua...@gmail.com

unread,
Dec 7, 2017, 12:58:31 AM12/7/17
to ProjectChrono
Dear Radu,

Thanks so much! You solved my questions.

You are right. In my code, I don't use rendering so GPU usage would not change.

My hardware is:
GPU: GTX 1060
CPU: i7-6700 CPU @3.40GHz

Best Wishes,
Liu

在 2017年12月5日星期二 UTC+8下午11:35:00,Radu Serban写道:
Reply all
Reply to author
Forward
0 new messages