Mt solver pool using non-Mt solver?

Post Reply
bram
Posts: 51
Joined: Sun Nov 23, 2008 4:43 pm

Mt solver pool using non-Mt solver?

Post by bram » Fri Apr 03, 2020 6:17 pm

I am trying to hunt down a crash when I use MT solver. (In my sim I add and remove objects frequently, outside the step function, of course.)

While debugging, I noticed that Mt code calls into non-Mt code.

Specifically, btConstraintSolverPoolMt::solveGroup() calls into btSequentialImpulseConstraintSolver and not into btSequentialImpulseConstraintSolverMt.

It is all Mt versions in the higher parts of the stack trace, and then non-Mt calls in the deeper parts.

Is this switch into the scalar version expected?

Code: Select all

N__> "int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&, btScalar)") at assert.c:92
#3  0x00007ffff65e2412 in __GI___assert_fail (assertion=0x6a10d0 "solverBodyId >= 0 && solverBodyId < m_tmpSolverBodyPool.size()", file=0x6a1040 "/home/bram/src/bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp", line=755, function=0x6a1460 <btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&, float)::__PRETTY_FUNCTION__> "int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&, btScalar)") at assert.c:101
#4  0x00000000004a4b0a in btSequentialImpulseConstraintSolver::getOrInitSolverBody (this=0x44696b0, body=..., timeStep=0.00416666688) at /home/bram/src/bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp:755
#5  0x00000000004a7e29 in btSequentialImpulseConstraintSolver::convertBodies (this=0x44696b0, bodies=0x47ee1f0, numBodies=30, infoGlobal=...) at /home/bram/src/bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp:1377
#6  0x00000000004a8219 in btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup (this=0x44696b0, bodies=0x47ee1f0, numBodies=30, manifoldPtr=0x472b100, numManifolds=38, constraints=0x0, numConstraints=0, infoGlobal=..., debugDrawer=0x0) at /home/bram/src/bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp:1487
#7  0x00000000004aa03c in btSequentialImpulseConstraintSolver::solveGroup (this=0x44696b0, bodies=0x47ee1f0, numBodies=30, manifoldPtr=0x472b100, numManifolds=38, constraints=0x0, numConstraints=0, infoGlobal=..., debugDrawer=0x0) at /home/bram/src/bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp:1863
#8  0x000000000049846e in btConstraintSolverPoolMt::solveGroup (this=0x44690e0, bodies=0x47ee1f0, numBodies=30, manifolds=0x472b100, numManifolds=38, constraints=0x0, numConstraints=0, info=..., debugDrawer=0x0, dispatcher=0x4455d60) at /home/bram/src/bullet3/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorldMt.cpp:128
#9  0x000000000049b214 in btSimulationIslandManagerMt::solveIsland (solver=0x44690e0, island=..., solverParams=...) at /home/bram/src/bullet3/src/BulletDynamics/Dynamics/btSimulationIslandManagerMt.cpp:532
#10 0x000000000049bd5c in UpdateIslandDispatcher::forLoop (this=0x7fffffffd6d0, iBegin=3, iEnd=4) at /home/bram/src/bullet3/src/BulletDynamics/Dynamics/btSimulationIslandManagerMt.cpp:571
#11 0x000000000043991d in ParallelForJob::executeJob (this=0x4724bd8, threadId=1) at PI/scheduler.cpp:118
#12 0x00000000004364cd in WorkerThreadFunc (userPtr=0x427f4d8) at PI/scheduler.cpp:368
#13 0x000000000053b02c in threadFunction (argument=0x40d7ef0) at /home/bram/src/bullet3/src/LinearMath/TaskScheduler/btThreadSupportPosix.cpp:187
#14 0x00007ffff73df6db in start_thread (arg=0x7fffeeca1700) at pthread_create.c:463
#15 0x00007ffff66d388f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Without the MT, the sim is stable, by the way.

Code: Select all

#if USEMT
        dispatcher = new btCollisionDispatcherMt(collisionConfiguration);
        solver = new btSequentialImpulseConstraintSolverMt;
#else
        dispatcher = new btCollisionDispatcher(collisionConfiguration);
        solver = new btSequentialImpulseConstraintSolver;
#endif

#if USEMT
        // A pool of 4 solvers for MT operation.
        solverpool = new btConstraintSolverPoolMt( 4 );
        world = new btDiscreteDynamicsWorldMt( dispatcher, broadphase, solverpool, solver, collisionConfiguration );
#else
        world = new btDiscreteDynamicsWorld( dispatcher, broadphase, solver, collisionConfiguration );
#endif

nickak2003
Posts: 17
Joined: Thu Mar 04, 2010 10:35 pm

Re: Mt solver pool using non-Mt solver?

Post by nickak2003 » Sun Apr 12, 2020 12:29 am

This is what I use, and I am stable:

Code: Select all

	auto createSolver = [&]() -> btConstraintSolverPoolMt* {

		SolverType tmpSolverType = mSolverType;
		if (tmpSolverType == SolverType::SOLVER_TYPE_SEQUENTIAL_IMPULSE_MT) {
			// pool solvers shouldn't be parallel solvers, we don't allow that kind of
			// nested parallelism because of performance issues
			tmpSolverType = SolverType::SOLVER_TYPE_SEQUENTIAL_IMPULSE;
		}
		const int threadCount = 16;//BT_MAX_THREAD_COUNT
		btConstraintSolver* solvers[threadCount];
		for (int i = 0; i < threadCount ; ++i) {

			solvers[i] = createSolverByType(tmpSolverType);
			
		}
		return new btConstraintSolverPoolMt(solvers, threadCount);
	};

nickak2003
Posts: 17
Joined: Thu Mar 04, 2010 10:35 pm

Re: Mt solver pool using non-Mt solver?

Post by nickak2003 » Sun Apr 12, 2020 12:31 am

I think your problem may be that your not creating the individual solvers in the pool.

Post Reply