# How to convert a Matrix to a DistMatrix in Elemental?

I have a Matrix<double> on a single core, the result of doing an MPI_Reduce. I want to do the Cholesky, so I need to distribute over multiple cores. What's the easiest/most standard way of doing this in Elemental? Do I need to MPI_Bcast it out to all nodes first, and then move it into a DistMatrix, or is there some way of doing something like:

Matrix<double> A = doSomeStuff();
DistMatrix<double, single-node> AdistSingle( A );
DistMatrix<double> Adist(AdistSingle );


or perhaps:

Matrix<double> A = doSomeStuff();
DistMatrix<double> Adist(A );


## 1 Answer

DistMatrix<T,CIRC,CIRC> was recently created for exactly this situation and stores a fully copy of the matrix on a single process. If you have an $n \times n$ Matrix<double> stored on the root process, you can distribute it as follows:

// Construct an n x n matrix owned by process 0
DistMatrix<double,CIRC,CIRC> ARoot( n, n );
// Have the root process fill the local matrix of ARoot
if( commRank == 0 )
ARoot.Matrix() = A;
// Redistribute ARoot into the standard matrix distribution
// (via a scatter)
DistMatrix<double> ADist( ARoot );


Note that the DistMatrix<T,CIRC,CIRC> class is very new and that the syntax might be simplified in the near future.

• It might be worth allowing DistMatrix<T,CIRC,CIRC> to accept a Matrix<T> as input, and having the former attach to the latter, so that the extra (n,n) allocation does not take place here. – Michael Grant Jun 21 '13 at 10:46
• Agreed, this is planned and only should only take a handful of lines of code, but, as I warned, the distribution is very new. – Jack Poulson Jun 21 '13 at 14:30