Fixes #4217: Move r30539, 30540, r30695 to v1.7 branch

Conflict on dims_create.c, so copied it from trunk as this was likely caused by a missing changeset

---svn-pre-commit-ignore-below---

r30539 [[BR]]
Suggestion from Andreas Schafer: we really only need sqrt(freeprocs)
primes.  This considerably reduces the computational load when
freeprocs is large.

cmr=v1.7.5:reviewer=hjelmn:subject=MPI_Dims_create optimization

r30540 [[BR]]
Gah; I missed the #include in r30539.

cmr=v1.7.5:ticket=#4217

r30606 [[BR]]
Revert r30539 and r30540; using the sqrt() to limit the computation is
just plain wrong (i.e., it gives wrong answers).  

When time permits, perhaps we can put in a better algorithm for
MPI_DIMS_CREATE (Andreas Schafer mentioned that nnodes can now be on
the order of millions, and the current algorithm is... inefficient, at
best).

r30695 [[BR]]
Omit usage of pre calculated prime numbers and factorize directly.

Optimization of the MPI_Dims_create function which omits the usage of pre
calculated prime numbers and factorize directly as discussed at the developer
list.

cmr=v1.7.5:ticket=4217:reviewer=jsquyres
Fixes #4244: Move fix for distance computation to 1.7

---svn-pre-commit-ignore-below---

r30287 [[BR]]
Fix bug in distance computation code when deciding which devices to use on a NUMA node.
Also add a verbose flag so one can see what devices are selected as well as another flag to override
locality information and use all devices on the node.
Fixes #4260: Move r30694 to v1.7 branch (move parameter check to begin)

---svn-pre-commit-ignore-below---

r30694 [[BR]]
Move parameter check into appropriate code section at the begin.

Freeprocs variable was obtained from nnodes, so check the value of nnodes at
the begin in the MPI_PARAM_CHECK code section instead as discussed at the
developer list.

cmr=v1.7.5:reviewer=jsquyres:subject=move parameter check to begin


jsquyres, please review this CMR. Thanks.
Fixes #4259: Move r30693 to v1.7 branch (treat caches as something different yet again)

---svn-pre-commit-ignore-below---

r30693 [[BR]]
Okay, once again be caught by the blasted hwloc inability to cleanly handle caches. Protect the calls to get_depth by first checking to see if it is a "cache", then use a cache-specific function to get the stupid data. Very, very irritating.

cmr=v1.7.5:reviewer=jsquyres:subject=treat caches as something different yet again