Example #1
0
        // // End zrword -- Two dimensional Boolean

        public static void zrword(double[, ][,] MatrixA)
        {
            int LocalVectorDimension0 = MatrixA[0, 0].GetLength(0);
            int LocalVectorDimension1 = MatrixA[0, 0].GetLength(1);
            int LongDimension0        = MatrixA.GetLength(0);
            int LongDimension1        = MatrixA.GetLength(1);

            if (!SALSAUtility.sequentialBLAS)
            {
                Exception e = SALSAUtility.SALSAError("zeroing a Matrix NOT defined for Decomposed Parameters");

                throw (e);
            }

            for (int LongIndex1 = 0; LongIndex1 < LongDimension0; LongIndex1++)
            {
                for (int LongIndex2 = 0; LongIndex2 < LongDimension1; LongIndex2++)
                {
                    for (int LocalVectorIndex1 = 0; LocalVectorIndex1 < LocalVectorDimension0; LocalVectorIndex1++)
                    {
                        for (int LocalVectorIndex2 = 0; LocalVectorIndex2 < LocalVectorDimension1; LocalVectorIndex2++)
                        {
                            MatrixA[LongIndex1, LongIndex2][LocalVectorIndex1, LocalVectorIndex2] = 0.0;
                        }
                    }
                }
            }
        }
Example #2
0
        public static void SetupParallelism(ref string[] args)
        {
            //  Set up MPI
            SALSAUtility.MPI_Environment  = new Environment(ref args);
            SALSAUtility.MPI_communicator = Communicator.world;                 //initializing MPI world communicator
            SALSAUtility.MPI_Rank         = SALSAUtility.MPI_communicator.Rank; // Rank of this process
            SALSAUtility.MPI_Size         = SALSAUtility.MPI_communicator.Size; // Number of MPI Processes

            // Set up MPI
            SALSAUtility.MPIperNodeCount = SALSAUtility.MPI_Size / SALSAUtility.NodeCount;

            //smbeason
            ManxcatCentral.Configuration.MPIperNodeCount = SALSAUtility.MPIperNodeCount;
            //smbeason

            if ((SALSAUtility.MPIperNodeCount * SALSAUtility.NodeCount) != SALSAUtility.MPI_Size)
            {
                Exception e = SALSAUtility.SALSAError("Inconsistent MPI counts Nodes "
                                                      + SALSAUtility.NodeCount.ToString() + " Size " +
                                                      SALSAUtility.MPI_Size.ToString());

                throw (e);
            }

            SALSAUtility.ParallelPattern = "Machine:" + Environment.ProcessorName + " " +
                                           SALSAUtility.ThreadCount.ToString() + "x" +
                                           SALSAUtility.MPIperNodeCount.ToString() + "x" +
                                           SALSAUtility.NodeCount.ToString();
            if (SALSAUtility.MPI_Rank == 0)
            {
                SALSAUtility.SALSAPrint(0, " Distance Data Type: " + typeof(TDistance));
                SALSAUtility.SALSAPrint(0, SALSAUtility.ParallelPattern);
            }
        }
Example #3
0
        // End VectorScalarProduct -- Two dimensional double

        public static void CopyMatrix(double[, ][,] MatrixC, double[, ][,] MatrixA)
        {
            int LocalVectorDimension0 = MatrixC[0, 0].GetLength(0);

            if (LocalVectorDimension0 != MatrixA[0, 0].GetLength(0))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions C" + LocalVectorDimension0.ToString() + " A " +
                                        MatrixA[0, 0].GetLength(0).ToString());
            }

            int LocalVectorDimension1 = MatrixC[0, 0].GetLength(1);

            if (LocalVectorDimension1 != MatrixA[0, 0].GetLength(1))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions C" + LocalVectorDimension1.ToString() + " A " +
                                        MatrixA[0, 0].GetLength(1).ToString());
            }
            int LongDimension0 = MatrixC.GetLength(0);

            if (LongDimension0 != MatrixA.GetLength(0))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions C" + LongDimension0.ToString() + " A " +
                                        MatrixA.GetLength(0).ToString());
            }
            int LongDimension1 = MatrixC.GetLength(1);

            if (LongDimension1 != MatrixA.GetLength(1))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions C" + LongDimension1.ToString() + " A " +
                                        MatrixA.GetLength(1).ToString());
            }

            if (!SALSAUtility.sequentialBLAS)
            {
                Exception e = SALSAUtility.SALSAError("CopyMatrix NOT defined for Decomposed Parameters");

                throw (e);
            }

            for (int LongIndex1 = 0; LongIndex1 < LongDimension0; LongIndex1++)
            {
                for (int LongIndex2 = 0; LongIndex2 < LongDimension1; LongIndex2++)
                {
                    for (int LocalVectorIndex1 = 0; LocalVectorIndex1 < LocalVectorDimension0; LocalVectorIndex1++)
                    {
                        for (int LocalVectorIndex2 = 0; LocalVectorIndex2 < LocalVectorDimension1; LocalVectorIndex2++)
                        {
                            MatrixC[LongIndex1, LongIndex2][LocalVectorIndex1, LocalVectorIndex2] =
                                MatrixA[LongIndex1, LongIndex2][LocalVectorIndex1, LocalVectorIndex2];
                        }
                    }
                }
            }
        }
Example #4
0
        // End VectorScalarProduct -- One dimensional double

        //  Form Vector Dot Product -- Two Dimensional
        public static double VectorScalarProduct(double[][] VectorA, double[][] VectorB)
        {
            int LocalVectorDimension = VectorB[0].GetLength(0);

            if (LocalVectorDimension != VectorA[0].GetLength(0))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions B" + LocalVectorDimension.ToString() + " A " +
                                        VectorA[0].GetLength(0).ToString());
            }

            if (SALSAUtility.sequentialBLAS)
            {
                int LongDimension = VectorA.GetLength(0);

                double Total = 0.0;

                for (int LongIndex = 0; LongIndex < LongDimension; LongIndex++)
                {
                    for (int LocalVectorIndex = 0; LocalVectorIndex < LocalVectorDimension; LocalVectorIndex++)
                    {
                        Total += VectorB[LongIndex][LocalVectorIndex] * VectorA[LongIndex][LocalVectorIndex];
                    }
                }
                return(Total);
            }

            // Parallel Scalar Product  = Sum(over i) VectorA[i] * VectorB[i]
            var ScalarProduct = new GlobalReductions.FindDoubleSum(SALSAUtility.ThreadCount);

            Parallel.For(0, SALSAUtility.ParallelOptions.MaxDegreeOfParallelism, SALSAUtility.ParallelOptions,
                         (ThreadNo) =>
            {
                double tmp     = 0.0;
                int indexlen   = SALSAUtility.PointsperThread[ThreadNo];
                int beginpoint = SALSAUtility.StartPointperThread[ThreadNo] -
                                 SALSAUtility.PointStart_Process;

                for (int LongIndex = beginpoint; LongIndex < indexlen + beginpoint; LongIndex++)
                {
                    for (int LocalVectorIndex = 0;
                         LocalVectorIndex < LocalVectorDimension;
                         LocalVectorIndex++)
                    {
                        tmp += VectorB[LongIndex][LocalVectorIndex] *
                               VectorA[LongIndex][LocalVectorIndex];
                    }
                }
                ScalarProduct.addapoint(ThreadNo, tmp);
            });                  // End loop over Point dependent quantities

            ScalarProduct.sumoverthreadsandmpi();
            return(ScalarProduct.Total);
        }
Example #5
0
        // End LinearCombineVector -- TWo dimensional double

        //  Copy TotalSize local vectors from VectorA to VectorC starting in position 0 of VectorC and position StartIndex of VectorA
        public static void CopyVector(double[][] VectorC, double[][] VectorA, int StartIndex, int TotalSize)
        {
            int LocalVectorDimension = VectorC[0].GetLength(0);

            if (LocalVectorDimension != VectorA[0].GetLength(0))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions C" + LocalVectorDimension.ToString() + " A " +
                                        VectorA[0].GetLength(0).ToString());
            }

            if (SALSAUtility.sequentialBLAS)
            {
                for (int LongIndex = 0; LongIndex < TotalSize; LongIndex++)
                {
                    for (int LocalVectorIndex = 0; LocalVectorIndex < LocalVectorDimension; LocalVectorIndex++)
                    {
                        VectorC[LongIndex + StartIndex][LocalVectorIndex] = VectorA[LongIndex][LocalVectorIndex];
                    }
                }
                return;
            }

            // Parallel VectorC = VectorA
            Parallel.For(0, SALSAUtility.ParallelOptions.MaxDegreeOfParallelism, SALSAUtility.ParallelOptions,
                         (ThreadNo) =>
            {
                int indexlen   = SALSAUtility.PointsperThread[ThreadNo];
                int beginpoint = SALSAUtility.StartPointperThread[ThreadNo] -
                                 SALSAUtility.PointStart_Process;
                int endpoint = indexlen + beginpoint;

                if (endpoint > TotalSize)
                {
                    endpoint = TotalSize;
                }

                if (ThreadNo == (SALSAUtility.ThreadCount - 1))
                {
                    endpoint = TotalSize;
                }

                for (int LongIndex = beginpoint; LongIndex < endpoint; LongIndex++)
                {
                    for (int LocalVectorIndex = 0;
                         LocalVectorIndex < LocalVectorDimension;
                         LocalVectorIndex++)
                    {
                        VectorC[LongIndex + StartIndex][LocalVectorIndex] =
                            VectorA[LongIndex][LocalVectorIndex];
                    }
                }
            });                  // End loop over Point dependent quantities
        }
Example #6
0
        // End ReadDataPointFile

        public static void ArrayInitializer(ref SALSADataPointProperties[] DataArray, int sizemax, int sizereadin)
        {
            if (DataArray != null)
            {
                if (DataArray.Length < sizereadin)
                {
                    Exception e =
                        SALSAUtility.SALSAError(" Data Array too small for file Length " + DataArray.Length.ToString() +
                                                " Needs " + sizereadin.ToString());
                    throw (e);
                }
                return;
            }
            int size = sizereadin;

            if (size == 0)
            {
                size = sizemax;
            }
            DataArray = new SALSADataPointProperties[size];
            return;
        }
Example #7
0
        // End LinearCombineVector -- One dimensional double

        public static void LinearCombineVector(double[][] VectorC, double CoeffAlpha, double[][] VectorA,
                                               double CoeffBeta, double[][] VectorB)
        {
            int LocalVectorDimension = VectorC[0].GetLength(0);

            if (LocalVectorDimension != VectorA[0].GetLength(0))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions C" + LocalVectorDimension.ToString() + " A " +
                                        VectorA[0].GetLength(0).ToString());
            }

            if (LocalVectorDimension != VectorB[0].GetLength(0))
            {
                SALSAUtility.SALSAError("Inconsistent Dimensions C" + LocalVectorDimension.ToString() + " B " +
                                        VectorB[0].GetLength(0).ToString());
            }

            if (SALSAUtility.sequentialBLAS)
            {
                int LongDimension = VectorC.GetLength(0);

                if (CoeffBeta != 0.0)
                {
                    for (int LongIndex = 0; LongIndex < LongDimension; LongIndex++)
                    {
                        for (int LocalVectorIndex = 0; LocalVectorIndex < LocalVectorDimension; LocalVectorIndex++)
                        {
                            VectorC[LongIndex][LocalVectorIndex] = CoeffAlpha * VectorA[LongIndex][LocalVectorIndex] +
                                                                   CoeffBeta * VectorB[LongIndex][LocalVectorIndex];
                        }
                    }
                }
                else
                {
                    for (int LongIndex = 0; LongIndex < LongDimension; LongIndex++)
                    {
                        for (int LocalVectorIndex = 0; LocalVectorIndex < LocalVectorDimension; LocalVectorIndex++)
                        {
                            VectorC[LongIndex][LocalVectorIndex] = CoeffAlpha * VectorA[LongIndex][LocalVectorIndex];
                        }
                    }
                }
                return;
            }

            // Parallel VectorC = CoeffAlpha * VectorA + CoeffBeta * VectorB
            Parallel.For(0, SALSAUtility.ParallelOptions.MaxDegreeOfParallelism, SALSAUtility.ParallelOptions,
                         (ThreadNo) =>
            {
                int indexlen   = SALSAUtility.PointsperThread[ThreadNo];
                int beginpoint = SALSAUtility.StartPointperThread[ThreadNo] -
                                 SALSAUtility.PointStart_Process;

                if (CoeffBeta != 0.0)
                {
                    for (int LongIndex = beginpoint; LongIndex < indexlen + beginpoint; LongIndex++)
                    {
                        for (int LocalVectorIndex = 0;
                             LocalVectorIndex < LocalVectorDimension;
                             LocalVectorIndex++)
                        {
                            VectorC[LongIndex][LocalVectorIndex] = CoeffAlpha *
                                                                   VectorA[LongIndex][LocalVectorIndex] +
                                                                   CoeffBeta *
                                                                   VectorB[LongIndex][LocalVectorIndex];
                        }
                    }
                }
                else
                {
                    for (int LongIndex = beginpoint; LongIndex < indexlen + beginpoint; LongIndex++)
                    {
                        for (int LocalVectorIndex = 0;
                             LocalVectorIndex < LocalVectorDimension;
                             LocalVectorIndex++)
                        {
                            VectorC[LongIndex][LocalVectorIndex] = CoeffAlpha *
                                                                   VectorA[LongIndex][LocalVectorIndex];
                        }
                    }
                }
            });                  // End loop over Point dependent quantities
        }
Example #8
0
        // End getDistanceValue

        // Input row and col are Used values
        public static void putDistanceValue(int row, int col, double value)
        {
            if (SALSAUtility.StoredDistanceOption == 2)
            {
                row = row - SALSAUtility.PointStart_Process;
            }
            if (SALSAUtility.StoredDistanceOption == 3)
            {
                int originalpoint = SALSAUtility.UsedPointtoOriginalPointMap[row];
                int variedpoint   = SALSAUtility.OriginalPointDisposition[originalpoint] - SALSAUtility.SALSASHIFT;
                if (variedpoint < 0)
                {
                    Exception e =
                        SALSAUtility.SALSAError(" Illegal Distance Put Request Used Point " + row.ToString() +
                                                " Original " + originalpoint.ToString());
                    throw (e);
                }
                row = variedpoint - SALSAUtility.VariedPointStart_Process;
            }

            TDistance Temp;

#if USE_UINT16 || USE_INT16
            if (value > 1.0)
            {
                Exception e =
                    SALSAUtility.SALSAError(" Illegal Distance value Put Request Used Point " + value.ToString("F4") +
                                            " Coordinates " + row.ToString() + " " + col.ToString());
                throw (e);
            }
            if ((value == 1.0) && (SALSAUtility.DistanceCut > 0.0) && (SALSAUtility.UndefinedDistanceValue < 0.0))
            {
                // Inconsistent value
                Exception e =
                    SALSAUtility.SALSAError(" Illegal Distance value 1.0 Put Request Used Point " + value.ToString("F4") +
                                            " Coordinates " + row.ToString() + " " + col.ToString());
                throw (e);
            }
            if (value < 0.0)
            {
                if (SALSAUtility.DistanceCut < 0.0)
                {
                    Exception e =
                        SALSAUtility.SALSAError(" Illegal Distance value < 0.0 Put Request Used Point " +
                                                value.ToString("F4") + " Coordinates " + row.ToString() + " " +
                                                col.ToString());
                    throw (e);
                }

                Temp = TDistance.MaxValue;
            }
            else
            {
#if USE_INT16
                Temp = Convert.ToInt16(value * TDistance.MaxValue);
#endif
#if USE_UINT16
                Temp = Convert.ToUInt16(value * TDistance.MaxValue);
#endif
            }
#else
            Temp = value;
#endif
            SALSAUtility.PointDistances[row][col] = Temp;
            return;
        }
Example #9
0
        // End ReadDataFromFile(string fname)

        // Input row and col are Used values
        // Return -1 if distance undefined
        public static double getDistanceValue(int row, int col)
        {
            if (SALSAUtility.StoredDistanceOption == 2)
            {
                row = row - SALSAUtility.PointStart_Process;
            }
            if (SALSAUtility.StoredDistanceOption == 3)
            {
                int originalpoint = SALSAUtility.UsedPointtoOriginalPointMap[row];
                int variedpoint   = SALSAUtility.OriginalPointDisposition[originalpoint] - SALSAUtility.SALSASHIFT;
                if (variedpoint < 0)
                {
                    Exception e =
                        SALSAUtility.SALSAError(" Illegal Distance Request Used Point " + row.ToString() + " Original " +
                                                originalpoint.ToString());
                    throw (e);
                }
                row = variedpoint - SALSAUtility.VariedPointStart_Process;
            }

            TDistance Temp = SALSAUtility.PointDistances[row][col];

            // Return -1.0 if input distance < 0 or if equals TDistance.MaxValue
            if (Temp == TDistance.MaxValue)
            {
                if (SALSAUtility.DistanceCut > 0.0)
                {
                    if (SALSAUtility.UndefinedDistanceValue < 0.0)
                    {
                        return(-1.0);
                    }
                    if (SALSAUtility.DistanceProcessingOption == 2)
                    {
                        return(SALSAUtility.UndefinedDistanceValue * SALSAUtility.UndefinedDistanceValue);
                    }
                    else
                    {
                        return(SALSAUtility.UndefinedDistanceValue);
                    }
                }
                else
                {
                    return(1.0);
                }
            }


#if USE_UINT16
#endif
#if USE_INT16
            if (Temp < 0)
            {
                if (SALSAUtility.UndefinedDistanceValue < 0.0)
                {
                    return(-1.0);
                }
                if (SALSAUtility.DistanceProcessingOption == 2)
                {
                    return(SALSAUtility.UndefinedDistanceValue * SALSAUtility.UndefinedDistanceValue);
                }
                else
                {
                    return(SALSAUtility.UndefinedDistanceValue);
                }
            }
#endif

#if USE_UINT16 || USE_INT16
            double distancevalue = (Temp / (TDistance.MaxValue * 1.0));
#else
            if (Temp < 0)
            {
                return(-1.0);
            }
            distancevalue = Temp;
#endif

            if (SALSAUtility.DistanceProcessingOption == 2)
            {
                distancevalue = distancevalue * distancevalue;
            }
            return(distancevalue);
        }
Example #10
0
        //  Read Distance Data
        public static void ReadDataFromFile(string fname)
        {
            if ((SALSAUtility.DebugPrintOption > 0) && (SALSAUtility.MPI_Rank == 0))
            {
                SALSAUtility.SALSAPrint(1, "Starting to read data: " +
                                        " Distance Cut " + SALSAUtility.DistanceCut.ToString("F3"));
            }
            double countremoveddistances = 0.0;
            double counttotaldistances   = 0.0;

            SALSAUtility.StoredDistanceOption = Math.Max(2, SALSAUtility.StoredDistanceOption);
            if (SALSAUtility.PointCount_Global == SALSAUtility.NumberOriginalPoints)
            {
                SALSAUtility.DiskDistanceOption = Math.Max(2, SALSAUtility.DiskDistanceOption);
            }

            // Remove unsupported options
            if (SALSAUtility.DiskDistanceOption == 3)
            {
                SALSAUtility.StoredDistanceOption = 3;
            }
            if (SALSAUtility.StoredDistanceOption == 3)
            {
                SALSAUtility.CalcFixedCrossFixed = false;
            }

// Set sizes of matrix on disk
            int rowcount = SALSAUtility.PointCount_Global;
            int colcount = SALSAUtility.PointCount_Global;

            if (SALSAUtility.DiskDistanceOption == 1)
            {
                rowcount = SALSAUtility.NumberOriginalPoints;
                colcount = SALSAUtility.NumberOriginalPoints;
            }
            if (SALSAUtility.DiskDistanceOption == 3)
            {
                rowcount = SALSAUtility.NumberVariedPoints;
            }

            //          MatrixTextReader reader = new MatrixTextReader(rowcount,colcount);
            var reader = new MatrixBinaryReader(rowcount, colcount);


            bool Oneread = true;

            if (SALSAUtility.StoredDistanceOption != SALSAUtility.DiskDistanceOption)
            {
                Oneread = false;
            }
            if (SALSAUtility.Usedreordered)
            {
                Oneread = false;
            }

            if (Oneread)
            {
#if USE_UINT16
                SALSAUtility.PointDistances = reader.ReadUInt16(fname, SALSAUtility.PointStart_Process, SALSAUtility.PointCount_Process);
#elif USE_INT16
                SALSAUtility.PointDistances = reader.ReadInt16(fname, SALSAUtility.PointStart_Process,
                                                               SALSAUtility.PointCount_Process);
#else
                SALSAUtility.PointDistances = reader.ReadDouble(fname, SALSAUtility.PointStart_Process, SALSAUtility.PointCount_Process);
#endif
                int numberofcolumns = SALSAUtility.PointCount_Global;
                for (int GlobalPointIndex = SALSAUtility.PointStart_Process;
                     GlobalPointIndex < SALSAUtility.PointStart_Process + SALSAUtility.PointCount_Process;
                     GlobalPointIndex++)
                {
                    int rowindex = GlobalPointIndex;
                    if (SALSAUtility.StoredDistanceOption == 2)
                    {
                        rowindex = rowindex - SALSAUtility.PointStart_Process;
                    }
                    if (SALSAUtility.StoredDistanceOption == 3)
                    {
                        int originalpoint = SALSAUtility.UsedPointtoOriginalPointMap[rowindex];
                        int variedpoint   = SALSAUtility.OriginalPointDisposition[originalpoint] - SALSAUtility.SALSASHIFT;
                        if (variedpoint < 0)
                        {
                            Exception e =
                                SALSAUtility.SALSAError(" Illegal Distance Request Used Point " + rowindex.ToString() +
                                                        " Original " + originalpoint.ToString());
                            throw (e);
                        }
                        rowindex = variedpoint - SALSAUtility.VariedPointStart_Process;
                    }
                    for (int columnindex = 0; columnindex < numberofcolumns; columnindex++)
                    {
                        TDistance Temp = SALSAUtility.PointDistances[rowindex][columnindex];
                        counttotaldistances = counttotaldistances + 1.0;

                        if (SALSAUtility.DistanceCut > 0.0)
                        {
                            double distancevalue = (SALSAUtility.PointDistances[rowindex][columnindex] /
                                                    (TDistance.MaxValue * 1.0));
                            if (distancevalue > SALSAUtility.DistanceCut)
                            {
                                SALSAUtility.PointDistances[rowindex][columnindex] = TDistance.MaxValue;
                                countremoveddistances = countremoveddistances + 1.0;
                            }
                        }
                    }
                }
            }
            else
            {
                int colsread = SALSAUtility.PointCount_Global;
                if (SALSAUtility.DiskDistanceOption == 1)
                {
                    colsread = SALSAUtility.NumberOriginalPoints;
                }

                if (SALSAUtility.StoredDistanceOption == 2)
                {
                    SALSAUtility.PointDistances = new TDistance[SALSAUtility.PointCount_Process][];
                }
                if (SALSAUtility.StoredDistanceOption == 3)
                {
                    SALSAUtility.PointDistances = new TDistance[SALSAUtility.VariedPointCount_Process][];
                }

                for (int GlobalPointIndex = SALSAUtility.PointStart_Process;
                     GlobalPointIndex < SALSAUtility.PointStart_Process + SALSAUtility.PointCount_Process;
                     GlobalPointIndex++)
                {
                    int rowtostore = GlobalPointIndex;
                    if (SALSAUtility.StoredDistanceOption == 2)
                    {
                        rowtostore = GlobalPointIndex - SALSAUtility.PointStart_Process;
                    }
                    if (SALSAUtility.StoredDistanceOption == 3)
                    {
                        int OriginalIndex = SALSAUtility.UsedPointtoOriginalPointMap[GlobalPointIndex];
                        rowtostore = SALSAUtility.OriginalPointDisposition[OriginalIndex] - SALSAUtility.SALSASHIFT;
                        if (rowtostore < 0)
                        {
                            continue;
                        }
                        rowtostore = rowtostore - SALSAUtility.VariedPointStart_Process;
                    }


                    int rowtoread = -1;
                    if (SALSAUtility.DiskDistanceOption == 1)
                    {
                        rowtoread = SALSAUtility.UsedPointtoOriginalPointMap[GlobalPointIndex];
                    }
                    if (SALSAUtility.DiskDistanceOption == 2)
                    {
                        rowtoread = SALSAUtility.ActualtoNaiveUsedOrder[GlobalPointIndex];
                    }
                    if (SALSAUtility.DiskDistanceOption == 3)
                    {
                        int OriginalIndex = SALSAUtility.UsedPointtoOriginalPointMap[GlobalPointIndex];
                        rowtoread = SALSAUtility.OriginalPointDisposition[OriginalIndex] - SALSAUtility.SALSASHIFT;
                        if (rowtoread < 0)
                        {
                            continue;
                        }
                        rowtoread = SALSAUtility.ActualtoNaiveUsedOrder[rowtoread];
                    }
                    SALSAUtility.PointDistances[rowtostore] = new TDistance[colcount];
#if USE_UINT16
                    buffer = reader.ReadUInt16(fname, rowtoread, 1);
#elif USE_INT16
                    buffer = reader.ReadInt16(fname, rowtoread, 1);
#else
                    buffer = reader.ReadDouble(fname, rowtoread, 1);
#endif
                    // Store buffer in PointDistances
                    for (int colIndex = 0; colIndex < colsread; colIndex++)
                    {
                        int coltostore = colIndex;
                        if (SALSAUtility.DiskDistanceOption == 1)
                        {
                            coltostore = SALSAUtility.OriginalPointtoUsedPointMap[colIndex];
                            if (coltostore < 0)
                            {
                                continue;
                            }
                        }
                        else if (SALSAUtility.DiskDistanceOption > 1)
                        {
                            coltostore = SALSAUtility.NaivetoActualUsedOrder[colIndex];
                        }
                        SALSAUtility.PointDistances[rowtostore][coltostore] = buffer[0][colIndex];
                        counttotaldistances = counttotaldistances + 1.0;

                        if (SALSAUtility.DistanceCut > 0.0)
                        {
                            double distancevalue = (SALSAUtility.PointDistances[rowtostore][coltostore] /
                                                    (TDistance.MaxValue * 1.0));
                            if (distancevalue > SALSAUtility.DistanceCut)
                            {
                                SALSAUtility.PointDistances[rowtostore][coltostore] = TDistance.MaxValue;
                                countremoveddistances = countremoveddistances + 1.0;
                            }
                        }
                    }
                }
            }
            SALSAUtility.StartSubTimer(SALSAUtility.MPIREDUCETiming);
            counttotaldistances   = SALSAUtility.MPI_communicator.Allreduce(counttotaldistances, Operation <double> .Add);
            countremoveddistances = SALSAUtility.MPI_communicator.Allreduce(countremoveddistances, Operation <double> .Add);
            SALSAUtility.StopSubTimer(SALSAUtility.MPIREDUCETiming);
            double fractionleft = 1.0 - countremoveddistances / counttotaldistances;
            if ((SALSAUtility.DebugPrintOption > 0) && (SALSAUtility.MPI_Rank == 0))
            {
                SALSAUtility.SALSAPrint(1,
                                        "Total Distances " + counttotaldistances.ToString("F0") +
                                        " Distances Removed on Input " + countremoveddistances.ToString("F0") +
                                        " Fraction Left " + fractionleft.ToString("F5"));
            }
        }
Example #11
0
        // End ArrayInitializer

        // Write label-cluster results into a file
        public static void WriteDataPointFile(string CoreOutputFileName, bool write2Das3D, string OutputStyles,
                                              SALSAFileProperties FileProperties, SALSADataPointProperties[] DataPoints,
                                              int NumberofDataPoints)
        {
            var DothisOutputStyle = new bool[5];

            for (int StyleIndex = 0; StyleIndex < 5; StyleIndex++)
            {
                DothisOutputStyle[StyleIndex] = false;
                if (OutputStyles.Contains("all"))
                {
                    DothisOutputStyle[StyleIndex] = true;
                }
            }
            if (OutputStyles.Contains("colon"))
            {
                DothisOutputStyle[0] = true;
            }
            if (OutputStyles.Contains("family1"))
            {
                DothisOutputStyle[1] = true;
            }
            if (OutputStyles.Contains("family2"))
            {
                DothisOutputStyle[2] = true;
            }
            if (OutputStyles.Contains("cluster"))
            {
                DothisOutputStyle[3] = true;
            }
            if (OutputStyles.Contains("group"))
            {
                DothisOutputStyle[4] = true;
            }

            bool setgroup     = false;
            bool OutputValues = false;

            SALSADataPointProperties FirstOne = DataPoints[0];

            if (FirstOne.family1 < 0)
            {
                DothisOutputStyle[1] = false;
            }
            if (FirstOne.family2 < 0)
            {
                DothisOutputStyle[2] = false;
            }
            if (FirstOne.cluster < 0)
            {
                DothisOutputStyle[3] = false;
            }
            if (FirstOne.group < 0)
            {
                DothisOutputStyle[4] = false;
            }
            if ((FirstOne.family1 < 0) && (FirstOne.family2 < 0) && (FirstOne.cluster < 0) && (FirstOne.group < 0))
            {
                DothisOutputStyle[4] = true;
                setgroup             = true;
            }
            if (FirstOne.valuesset)
            {
                OutputValues = true;
            }
            int LocalVectorDimension = FileProperties.LocalVectorDimension;
            int LocalPointIncrement  = FileProperties.LocalPointStartIndex;

            int numberoffiles = 0;

            for (int StyleIndex = 0; StyleIndex < 5; StyleIndex++)
            {
                if (DothisOutputStyle[StyleIndex])
                {
                    ++numberoffiles;
                }
            }
            if (numberoffiles == 0)
            {
                SALSAUtility.SALSAError("No files output for core name " + CoreOutputFileName);
                return;
            }
            if (numberoffiles > 1)
            {
                if (OutputStyles.Contains("SameFileName"))
                {
                    Exception e =
                        SALSAUtility.SALSAError("Attempt to generate multiple outputs to same file " +
                                                CoreOutputFileName);
                    throw (e);
                }
            }
            for (int StyleIndex = 0; StyleIndex < 5; StyleIndex++)
            {
                if (!DothisOutputStyle[StyleIndex])
                {
                    continue;
                }
                string OutputFileName = "";
                if (!OutputStyles.Contains("SameFileName"))
                {
                    if (StyleIndex == 0)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Colon.txt");
                    }
                    if (StyleIndex == 1)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Family1.txt");
                    }
                    if (StyleIndex == 2)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Family2.txt");
                    }
                    if (StyleIndex == 3)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Cluster.txt");
                    }
                    if (StyleIndex == 4)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Group.txt");
                    }
                }
                else
                {
                    OutputFileName = CoreOutputFileName;
                }

                try
                {
                    StreamWriter sw = null;
                    if (!string.IsNullOrEmpty(OutputFileName))
                    {
                        sw = new StreamWriter(OutputFileName, false, Encoding.UTF8);
                    }
                    if (sw != null)
                    {
                        if (StyleIndex == 0)
                        {
                            WriteFileProperties(FileProperties, sw); // Write Header of a Colon File
                        }
                        for (int GlobalDataPoint = 0; GlobalDataPoint < NumberofDataPoints; GlobalDataPoint++)
                        {
                            SALSADataPointProperties ThesePointProperties = DataPoints[GlobalDataPoint];
                            if ((LocalVectorDimension == 2) && write2Das3D && OutputValues)
                            {
                                ThesePointProperties.z    = 0.0;
                                ThesePointProperties.zerr = 0.0;
                            }
                            if (StyleIndex == 0)
                            {
                                string OutputLine = "";
                                AppendDataPointProperties(ThesePointProperties, ref OutputLine);
                                sw.WriteLine(OutputLine);
                                continue;
                            }
                            int IntegerIndex = 0;
                            if (StyleIndex == 1)
                            {
                                IntegerIndex = ThesePointProperties.family1;
                            }
                            if (StyleIndex == 2)
                            {
                                IntegerIndex = ThesePointProperties.family2;
                            }
                            if (StyleIndex == 3)
                            {
                                IntegerIndex = ThesePointProperties.cluster;
                            }
                            if (StyleIndex == 4)
                            {
                                IntegerIndex = ThesePointProperties.group;
                                if (setgroup)
                                {
                                    IntegerIndex = 1;
                                }
                            }
                            string Coordinates = "";
                            if (OutputValues)
                            {
                                Coordinates = ThesePointProperties.x.ToString("E4") + "\t" +
                                              ThesePointProperties.y.ToString("E4") + "\t";
                                if ((LocalVectorDimension == 3) || write2Das3D)
                                {
                                    Coordinates += ThesePointProperties.z.ToString("E4") + "\t";
                                }
                            }
                            sw.WriteLine(
                                String.Format((GlobalDataPoint + LocalPointIncrement).ToString() + "\t" + Coordinates +
                                              IntegerIndex.ToString()));
                        }

                        sw.Flush();
                        sw.Close();
                    }
                }
                catch
                {
                    Exception e = SALSAUtility.SALSAError(" Failed to Write Properties File " + CoreOutputFileName);
                    throw (e);
                }
            } // End Loop over File Types
            return;
        }
Example #12
0
        public static bool ReadDataPointFile(string MDSClusterFileName, ref int FileType,
                                             SALSAFileProperties FileProperties,
                                             ref SALSADataPointProperties[] DataPoints, ref int NumberofPoints)
        {
            // FileType = 0 simple integers and positions:  PointNumber x y z LABEL or Group Number (LABEL if file name contains label)
            // FileType = 1 Just integers -- Point Number and Group Number: PointNumber  Group Number
            // File Type = 2 Integer and Label: Point LABEL (LABEL if file name contains label)
            // File Type = 3 Pure colon style -- with  positions
            // File Type = 4 Pure Colon Style -- no    positions
            // File Type = 5 Pure Colon Style --    Labels
            // File Type = 6 Hybrid Style --     with positions
            // File Type = 7 Hybrid Style --     no positions
            // File Type = 8 Hybrid Style --     Labels


            bool   positionsset   = false;
            bool   colonsinput    = false;
            bool   NonColonsInput = false;
            bool   labelfile      = false;
            string LowerFileName  = MDSClusterFileName.ToLower();

            if (LowerFileName.Contains("label"))
            {
                labelfile = true;
            }

            NumberofPoints = 0;

            try
            {
                // Check if file exists
                if (!File.Exists(MDSClusterFileName))
                {
                    Exception e = SALSAUtility.SALSAError("File " + MDSClusterFileName + " does not exists");
                    throw (e);
                }

                // Create a new stream to read from a file
                using (StreamReader sr = File.OpenText(MDSClusterFileName))
                {
                    // Read contents of a file
                    String inputLineStr;
                    int    newlabelnumber = -1;
                    int    LocalStart     = FileProperties.LocalPointStartIndex;
                    int    OriginalStart  = FileProperties.OriginalPointStartIndex;
                    while ((inputLineStr = sr.ReadLine()) != null)
                    {
                        if (inputLineStr.Length < 2)
                        {
                            continue; //replace empty line
                        }

                        inputLineStr = inputLineStr.Trim(new[] { ' ', '\t' });
                        try
                        {
                            // Parse each record string
                            inputLineStr = inputLineStr.Replace("\t\t", "\t");

                            if (inputLineStr.Contains("FileProperties"))
                            {
                                // Not a Data Point
                                string EndofInput = inputLineStr.Replace("FileProperties", "");
                                ReadFileProperties(FileProperties, EndofInput);
                                colonsinput   = true;
                                LocalStart    = FileProperties.LocalPointStartIndex;
                                OriginalStart = FileProperties.OriginalPointStartIndex;
                            }
                            else
                            {
                                // Must be a Data Point
                                ArrayInitializer(ref DataPoints, SALSAUtility.NumberOriginalPoints,
                                                 FileProperties.NumberPointsinFile);
                                DataPoints[NumberofPoints] = new SALSADataPointProperties();
                                bool incrementcount  = false;
                                int  PointDataStarts = inputLineStr.IndexOf("PointProperties");
                                if (PointDataStarts >= 0)
                                {
                                    // Some Colon Information
                                    string EndofInput = inputLineStr.Substring(PointDataStarts);
                                    EndofInput = EndofInput.Replace("PointProperties", "");
                                    ReadDataPointProperties(DataPoints[NumberofPoints], EndofInput);
                                    colonsinput = true;
                                    if (DataPoints[NumberofPoints].valuesset)
                                    {
                                        positionsset = true;
                                    }
                                    incrementcount = true;
                                    DataPoints[NumberofPoints].LocalPointNumber = NumberofPoints +
                                                                                  FileProperties.LocalPointStartIndex;
                                } //  End Processing Colon Point Information

                                if (PointDataStarts < 0)
                                {
                                    // traditional bare line
                                    PointDataStarts = inputLineStr.Length;
                                }
                                if (PointDataStarts > 0)
                                {
                                    // Process number information
                                    string StartofString = inputLineStr.Substring(0, PointDataStarts);
                                    StartofString = StartofString.Trim(new[] { ' ', '\t' });

                                    if (StartofString.Length > 0)
                                    {
                                        // You come here only for traditional bare line of x,y,z coordinates.

                                        string[] split = StartofString.Split(new[] { ' ', '\t' },
                                                                             StringSplitOptions.RemoveEmptyEntries);

                                        if ((split.Length != 5) && (split.Length != 2) && (split.Length != 4))
                                        {
                                            Exception e =
                                                SALSAUtility.SALSAError(" Bad Line " + split.Length.ToString() + " "
                                                                        + NumberofPoints.ToString() + " " + inputLineStr);
                                            throw (e);
                                        }
                                        newlabelnumber = Convert.ToInt32(split[0]);

                                        if ((NumberofPoints + LocalStart) != newlabelnumber)
                                        {
                                            Exception e =
                                                SALSAUtility.SALSAError("Unexpected Label Number " + newlabelnumber +
                                                                        " Expected "
                                                                        + NumberofPoints.ToString() + " + " +
                                                                        LocalStart.ToString());
                                            throw (e);
                                        }
                                        if (DataPoints[NumberofPoints].LocalPointNumber >= 0)
                                        {
                                            if ((DataPoints[NumberofPoints].LocalPointNumber - LocalStart) !=
                                                NumberofPoints)
                                            {
                                                Exception e =
                                                    SALSAUtility.SALSAError("Unexpected Local Number " +
                                                                            DataPoints[NumberofPoints].LocalPointNumber +
                                                                            " Expected "
                                                                            + NumberofPoints.ToString() + " + " +
                                                                            LocalStart.ToString());
                                                throw (e);
                                            }
                                        }
                                        DataPoints[NumberofPoints].LocalPointNumber = NumberofPoints;
                                        if (DataPoints[NumberofPoints].OriginalPointNumber >= 0)
                                        {
                                            if ((DataPoints[NumberofPoints].OriginalPointNumber - OriginalStart) < 0)
                                            {
                                                Exception e =
                                                    SALSAUtility.SALSAError("Unexpected Original Number " +
                                                                            DataPoints[NumberofPoints].
                                                                            OriginalPointNumber + " Local Point "
                                                                            + NumberofPoints.ToString() +
                                                                            " Original Increment " +
                                                                            OriginalStart.ToString());
                                                throw (e);
                                            }
                                            DataPoints[NumberofPoints].OriginalPointNumber -= OriginalStart;
                                        }
                                        else
                                        {
                                            DataPoints[NumberofPoints].OriginalPointNumber = newlabelnumber;
                                        }

                                        if (labelfile)
                                        {
                                            DataPoints[NumberofPoints].pointlabel = split[split.Length - 1];
                                        }
                                        else
                                        {
                                            DataPoints[NumberofPoints].group = Convert.ToInt32(split[split.Length - 1]);
                                        }

                                        if (split.Length >= 4)
                                        {
                                            DataPoints[NumberofPoints].valuesset = true;
                                            DataPoints[NumberofPoints].x         = Convert.ToDouble(split[1]);
                                            DataPoints[NumberofPoints].y         = Convert.ToDouble(split[2]);
                                            positionsset = true;
                                        }
                                        if (split.Length == 5)
                                        {
                                            DataPoints[NumberofPoints].z = Convert.ToDouble(split[3]);
                                        }
                                        incrementcount = true;
                                        NonColonsInput = true;
                                    } // End Processing non colon Point information
                                }
                                if (incrementcount)
                                {
                                    ++NumberofPoints;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            SALSAUtility.SALSAError("Failed to load data array " + inputLineStr + " "
                                                    + " " + NumberofPoints.ToString() + " " + newlabelnumber.ToString() +
                                                    " " + e);
                            throw (e);
                        }
                    }

                    FileType = 1;
                    if (positionsset)
                    {
                        FileType = 0;
                    }
                    if (labelfile)
                    {
                        FileType = 2;
                    }
                    if (colonsinput)
                    {
                        if (NonColonsInput)
                        {
                            FileType += 6;
                        }
                        else
                        {
                            FileType += 3;
                        }
                    }
                    if (FileProperties.NumberOriginalPoints == 0)
                    {
                        FileProperties.NumberOriginalPoints = NumberofPoints;
                    }

                    if (FileProperties.NumberPointsinFile == 0)
                    {
                        FileProperties.NumberPointsinFile = NumberofPoints;
                    }

                    if (FileProperties.NumberPointsinFile != NumberofPoints)
                    {
                        Exception e =
                            SALSAUtility.SALSAError("Unexpected Number of Points in File " + NumberofPoints.ToString() +
                                                    " Read but Expected "
                                                    + FileProperties.NumberPointsinFile.ToString());
                        throw (e);
                    }
                    sr.Close();
                }
            }
            catch (Exception e)
            {
                SALSAUtility.SALSAError("Failed to read data from " + MDSClusterFileName + " " + e);
                throw (e);
            }
            return(true);
        }