/// <summary> /// Test if the matrix is symmetric positive definite /// </summary> /// <returns>bool array res=[symmetry, positive definit]</returns> public bool[] Symmetry() { bool[] res = new bool[2]; //extract submatrix for selected dependent variables int[] DepVars = this.VarGroup; double[] DepVars_subvec = this.m_map.GetSubvectorIndices(true, DepVars).Select(i => i + 1.0).ToArray(); //MsrMatrix OpMtxMSR = m_OpMtx.ToMsrMatrix(); int[] SubMatrixIdx_Row = m_map.GetSubvectorIndices(false, DepVars); int[] SubMatrixIdx_Cols = m_map.GetSubvectorIndices(false, DepVars); int L = SubMatrixIdx_Row.Length; MsrMatrix SubOpMtx = new MsrMatrix(L, L, 1, 1); m_OpMtx.WriteSubMatrixTo(SubOpMtx, SubMatrixIdx_Row, default(int[]), SubMatrixIdx_Cols, default(int[])); // symmetry test by calculation of symmetry deviation bool sym = false; double SymmDev = m_OpMtx.SymmetryDeviation(); if (SymmDev < 1e-5) { sym = true; } res[0] = sym; // positive definite test by Cholesky decomposition var FullyPopulatedMatrix = m_OpMtx.ToFullMatrixOnProc0(); bool posDef = true; // only proc 0 gets info so the following is executed exclusively on rank 0 if (ilPSP.Environment.MPIEnv.MPI_Rank == 0) { try { FullyPopulatedMatrix.Cholesky(); } catch (ArithmeticException) { posDef = false; } } res[1] = MPIEnviroment.Broadcast <bool>(posDef, 0, ilPSP.Environment.MPIEnv.Mpi_comm); Debug.Assert(res[0].MPIEquals(), "value does not match on procs"); Debug.Assert(res[1].MPIEquals(), "value does not match on procs"); return(res); }
/// <summary> /// Creates OpenCL environment on this process /// </summary> /// <param name="_MpiEnv">MPI environment of this process</param> public clEnvironment(MPIEnviroment _MpiEnv) { MpiEnv = _MpiEnv; cl_platform_id[] platforms = cl.GetPlatformIDs(); cl_platform_info_return pinfo = cl.GetPlatformInfo(platforms[0]); string vnd = pinfo.vendor; switch (vnd) { case "NVIDIA Corporation": _vendor = Vendor.NVIDIA; break; case "Advanced Micro Devices, Inc.": _vendor = Vendor.AMD; break; default: _vendor = Vendor.Other; break; } Console.WriteLine(vnd + " : " + _vendor.ToString()); Console.WriteLine(pinfo.version); if (_vendor == Vendor.AMD) { clVectorSource.source[0] = clVectorSource.source[0].Replace("cl_khr_fp64", "cl_amd_fp64"); clMatrixSource.source[0] = clMatrixSource.source[0].Replace("cl_khr_fp64", "cl_amd_fp64"); Console.WriteLine("Adjusted AMD fp64 extenstion"); } cl_device_id[] devices = cl.GetDeviceIDs(platforms[0], cl_device_type.CL_DEVICE_TYPE_GPU); int numDevices = devices.Length; if (numDevices < _MpiEnv.ProcessesOnMySMP) { throw new ApplicationException("not enougth OpenCL devices; There must be at least one OpenCL device for each MPI process;"); } device = devices[0]; context = cl.CreateContext(platforms[0], devices); //cl_device_info_return dinfo = cl.GetDeviceInfo(device); //Console.WriteLine("Max work group size: " + dinfo.max_work_group_size); //Console.WriteLine("Process " + _MpiEnv.ProcessRankOnSMP + " running on device " + dinfo.name + ", " + dinfo.version); //Console.WriteLine(dinfo.extensions); }
/// <summary> /// ctor /// </summary> public CudaEnviroment(MPIEnviroment _MpiEnv) { m_MpiEnv = _MpiEnv; if (!CudaAvailable) { throw new ApplicationException("No CUDA driver on this machine."); } int NoOfDev; cu.DeviceGetCount(out NoOfDev); if (NoOfDev < _MpiEnv.ProcessesOnMySMP) { throw new ApplicationException("not enough CUDA devices; There must be at least one CUDA device for each MPI process;"); } //cu.DeviceGet(out m_CUDAdev, 0); // provisorisch //Console.WriteLine("Cuda: prowisoischä dev-allok."); cu.DeviceGet(out m_CUDAdev, _MpiEnv.ProcessRankOnSMP); // korrekt int major, minor; cu.DeviceComputeCapability(out major, out minor, m_CUDAdev); if ((major < 1) || (major <= 1 && minor <= 2)) { throw new ApplicationException("requiring at least compute capability 1.3 - got " + major + "." + minor + " for device #" + _MpiEnv.ProcessRankOnSMP + " on host '" + MpiEnv.Hostname + "';"); } cu.CtxCreate(out m_context, CUDAdev, CUctx_flags_enum.CU_CTX_MAP_HOST); disposed = false; String name; cu.DeviceGetName(out name, CUDAdev); //uint membytes; //cu.DeviceTotalMem(out membytes, m_Env.CUDAdev); //membytes /= 1024 * 1024; Logger.Info("Process " + MpiEnv.MPI_Rank + " on " + MpiEnv.Hostname + " using " + name + "."); }
/// <summary> /// creates a new instance of the MATLAB connector. /// </summary> /// <param name="Flav"> /// octave or MATLAB /// </param> /// <param name="ExecutablePath"> /// Where to find the executable on the current system. /// If NULL, the standard installation path is assumed. /// In the case of Cygwin/octave, the path to the Cygwin bash.exe; /// </param> /// <param name="WorkingPath"> /// working directory of the MATLAB instance; /// if NULL, a temporary directory is created. /// </param> public BatchmodeConnector(string WorkingPath = null) { ilPSP.MPICollectiveWatchDog.Watch(csMPI.Raw._COMM.WORLD); csMPI.Raw.Comm_Rank(csMPI.Raw._COMM.WORLD, out Rank); this.m_Flav = Flav; // create/check working path // ========================= if (Rank == 0) { if (WorkingPath == null) { var rnd = new Random(); bool Exists = false; do { var tempPath = Path.GetTempPath(); var tempDir = rnd.Next().ToString(); WorkingDirectory = new DirectoryInfo(Path.Combine(tempPath, tempDir)); Exists = WorkingDirectory.Exists; if (!Exists) { WorkingDirectory.Create(); DelWorkingDir = true; } } while (Exists == true); } else { WorkingDirectory = new DirectoryInfo(WorkingPath); if (!WorkingDirectory.Exists) { throw new ArgumentException("Given working directory is inexistent."); } } } MPIEnviroment.Broadcast(this.WorkingDirectory, 0, csMPI.Raw._COMM.WORLD); // more checks // =========== if (MatlabExecuteable != null) { if (!File.Exists(MatlabExecuteable)) { throw new ArgumentException("Unable to find file '" + MatlabExecuteable + "' on this system."); } } // setup MATLAB process // ==================== if (Rank == 0) { psi = new ProcessStartInfo(); psi.WorkingDirectory = WorkingDirectory.FullName; psi.UseShellExecute = false; //psi.RedirectStandardOutput = true; //psi.RedirectStandardError = true; //psi.RedirectStandardInput = true; PlatformID CurrentSys = System.Environment.OSVersion.Platform; switch (CurrentSys) { case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: { if (m_Flav == Flavor.Matlab) { if (MatlabExecuteable == null) { MatlabExecuteable = get_program_path("matlab.exe"); if (MatlabExecuteable == null) { throw new ApplicationException("Unable to find 'matlab.exe' in your PATH environment; please provide path to 'matlab.exe'."); } } psi.FileName = MatlabExecuteable; psi.Arguments = "-nosplash -nodesktop -minimize -wait -r " + CMDFILE + " -logfile " + LOGFILE; } else if (m_Flav == Flavor.Octave) { this.Cygwin = true; // octave and windows must be cygwin! if (MatlabExecuteable == null) { if (File.Exists("c:\\cygwin64\\bin\\octave")) { psi.FileName = "c:\\cygwin64\\bin\\bash.exe"; } else if (File.Exists("c:\\cygwin\\bin\\octave")) { psi.FileName = "c:\\cygwin\\bin\\bash.exe"; } else { throw new NotSupportedException("Cygwin/Octave are expected to be in the default path: C:\\cygwin or c:\\cygwin64"); } } else { //throw new NotSupportedException("Cygwin/Octave are expected to be in the default path: C:\\cygwin or c:\\cygwin64"); if (!MatlabExecuteable.EndsWith("bash.exe")) { throw new NotSupportedException("For Cygwin/Octave, the 'MatlabExecuteable' is expected to point to 'bash.exe'."); } psi.FileName = MatlabExecuteable; } psi.Arguments = "--login -c \"cd " + TranslatePath(WorkingDirectory.FullName) + " " + "&& octave --no-gui " + CMDFILE + ".m" + " > " + LOGFILE + " \""; //+ "pwd && ls - l && pwd"; } else { throw new NotImplementedException(); } break; } case PlatformID.Unix: case PlatformID.MacOSX: { throw new NotImplementedException("will implement on request"); } default: throw new NotSupportedException("unable to use MATLAB on " + CurrentSys.ToString()); } CreatedFiles.Add(Path.Combine(WorkingDirectory.FullName, LOGFILE)); var ScriptsToWrite = new List <Tuple <string, string> >(); ScriptsToWrite.Add(new Tuple <string, string>("ReadMsr.m", Resource1.ReadMsr)); ScriptsToWrite.Add(new Tuple <string, string>("SaveVoronoi.m", Resource1.SaveVoronoi)); foreach (var t in ScriptsToWrite) { string name = t.Item1; string script = t.Item2; var rmPath = Path.Combine(WorkingDirectory.FullName, name); CreatedFiles.Add(rmPath); File.WriteAllText(rmPath, script); } } // create command file // =================== if (Rank == 0) { var p = Path.Combine(WorkingDirectory.FullName, CMDFILE + ".m"); CommandFile = new StreamWriter(p, false); CreatedFiles.Add(p); } }