Example #1
0
        /// <summary>
        /// Transfers a sparse matrix to MATLAB.
        /// </summary>
        /// <param name="M">
        /// Matrix to transfer;
        /// If the matrix lives only on a sub-communicator of <see cref="IMPI_CommConstants.WORLD"/>,
        /// this should be null on those processors which do not belong to the world-communicator.
        /// </param>
        /// <param name="MatlabName">the name which <paramref name="M"/> should have in the MATLAB session</param>
        public void PutSparseMatrix(IMutableMatrixEx M, string MatlabName)
        {
            var comm = csMPI.Raw._COMM.WORLD;

            ilPSP.MPICollectiveWatchDog.Watch(comm);
            if (Executed == true)
            {
                throw new InvalidOperationException("No Data can be put after Execute() has been called..");
            }

            string filepath;

            if (Rank == 0)
            {
                filepath = Path.Combine(WorkingDirectory.FullName, MatlabName);
            }
            else
            {
                filepath = null;
            }
            filepath = filepath.MPIBroadcast(0);
            if (M != null) // if M is on a sub-communicator of WORLD, this should be null
            {
                M.SaveToTextFileSparse(filepath);
            }

            if (Rank == 0)
            {
                CreatedFiles.Add(filepath);
            }

            Cmd(MatlabName + " = ReadMsr('" + TranslatePath(filepath) + "');");
        }
Example #2
0
        /// <summary>
        /// Transfers a sparse matrix to MATLAB.
        /// </summary>
        /// <param name="M">matrix to transfer</param>
        /// <param name="MatlabName">the name which <paramref name="M"/> should have in the MATLAB session</param>
        public void PutSparseMatrix(IMutableMatrixEx M, string MatlabName)
        {
            ilPSP.MPICollectiveWatchDog.Watch(csMPI.Raw._COMM.WORLD);
            if (Executed == true)
            {
                throw new InvalidOperationException("No Data can be put after Execute() has been called..");
            }

            string filepath;

            if (Rank == 0)
            {
                filepath = Path.Combine(WorkingDirectory.FullName, MatlabName);
            }
            else
            {
                filepath = null;
            }
            M.SaveToTextFileSparse(filepath);
            if (Rank == 0)
            {
                CreatedFiles.Add(filepath);
            }

            Cmd(MatlabName + " = ReadMsr('" + TranslatePath(filepath) + "');");
        }
Example #3
0
        unsafe public static void SaveToTextFileSparseF(ref int _ref, byte *termchar, byte *path, out int ierr)
        {
            ierr = 0;
            try {
                string _path = Infrastructure.FortranToDotNET(path, *termchar);

                IMutableMatrixEx M = (IMutableMatrixEx)Infrastructure.GetObject(_ref);
                M.SaveToTextFileSparse(_path);
            } catch (Exception e) {
                ierr = Infrastructure.ErrorHandler(e);
            }
        }
Example #4
0
 unsafe public static void SaveToTextFileSparse(ref int _ref, byte *path, out int ierr)
 {
     ierr = 0;
     try {
         string           _paht = Marshal.PtrToStringAnsi((IntPtr)path);
         IMutableMatrixEx M     = (IMutableMatrixEx)Infrastructure.GetObject(_ref);
         //Console.WriteLine("saving: >" + _paht + "<");
         M.SaveToTextFileSparse(_paht);
     } catch (Exception e) {
         ierr = Infrastructure.ErrorHandler(e);
     }
 }
Example #5
0
        /// <summary>
        /// transfers multiple matrices <paramref name="M"/> to MATLAB.
        /// note: <paramref name="MatlabName"/>is extended with "_rank",
        /// which is the MPIrank
        /// </summary>
        /// <param name="M"></param>
        /// <param name="MatlabName"></param>
        public void PutSparseMatrixRankExclusive(IMutableMatrixEx M, string MatlabName)
        {
            int rank;
            var comm = csMPI.Raw._COMM.WORLD;

            csMPI.Raw.Comm_Rank(comm, out rank);
            ilPSP.MPICollectiveWatchDog.Watch(comm);
            if (Executed == true)
            {
                throw new InvalidOperationException("No Data can be put after Execute() has been called..");
            }
            if (comm == M.MPI_Comm || M == null)
            {
                throw new NotSupportedException("has to be on sub comm of world and not empty");
            }

            string Mname = String.Concat(MatlabName + "_" + rank);
            string workdir;

            if (Rank == 0)
            {
                workdir = WorkingDirectory.FullName;
            }
            else
            {
                workdir = null;
            }
            workdir = workdir.MPIBroadcast(0);
            string filepath = Path.Combine(workdir, Mname);

            if (M != null)
            {
                M.SaveToTextFileSparse(filepath);
            }

            string[] Mnames = Mname.MPIGatherO(0);
            if (Rank == 0)
            {
                foreach (string Mn in Mnames)
                {
                    CreatedFiles.Add(Path.Combine(workdir, Mn));
                }
            }
            Mnames = Mnames.MPIBroadcast(0);
            foreach (string Mn in Mnames)
            {
                Cmd(Mn + " = ReadMsr('" + TranslatePath(Path.Combine(workdir, Mn)) + "');");
            }
        }