Parallel computation method and system for multiplication of symmetric matrix and vector
By using a parallel computation method of multiplying symmetric matrices with vectors, the symmetric matrix is divided into different regions and multi-threaded parallel computation is adopted, which solves the problems of write conflicts and load imbalance, and achieves efficient and accurate computation results.
Patent Information
- Application Number
- CN202210445587.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-26
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2042-04-26
AI Technical Summary
Existing technologies suffer from write conflicts, low computational efficiency, and unbalanced thread load in parallel computation of symmetric matrix-vector multiplication, especially when dealing with the upper triangular part of the symmetric matrix, leading to redundancy and waste of resources in the computation process.
The symmetric matrix is divided into a symmetry axis region, an upper triangular region, and a lower triangular region, and further subdivided according to the number of threads. Different multiplication orders and register storage methods are used to avoid write conflicts through multi-threaded parallel computation and to allocate thread resources reasonably.
It achieves accurate and fast calculation of symmetric matrix-vector multiplication, improves computational efficiency, avoids write conflicts, ensures balanced load across threads, and ensures reasonable resource distribution.
Smart Images

Figure CN114780913B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of matrix data processing, and in particular to a parallel computation method and system for multiplying symmetric matrices and vectors. Background Technology
[0002] A real matrix A is a data block consisting of M×N real numbers. A vector x can be considered as a matrix consisting of N×1 real numbers. The product y of matrix A and vector x is an M×1 vector. The multiplication of a matrix and a vector is defined as follows:
[0003]
[0004] Parallel matrix multiplication using a processor can effectively shorten data processing time. A crucial issue in developing parallel algorithms is how to avoid write conflicts. Simply put, a write conflict occurs when multiple concurrently running threads need to write to the same memory address simultaneously. Without any handling, the results of earlier writes may be overwritten by later ones, leading to incorrect results. For example, two threads simultaneously want to increment the same memory address by 1. If the original value is 0, the correct result should be 2. However, if the thread execution order is as follows:
[0005] Thread A: Reads memory and gets 0.
[0006] Thread B: Reads memory and gets 0.
[0007] Thread A: Performs addition 0 + 1 = 1, and gets the result 1.
[0008] Thread B: Performs addition 0 + 1 = 1, and gets the result 1.
[0009] Thread A: Write the result 1 back to memory
[0010] Thread B: Write the result 1 back to memory
[0011] After the above thread executes, the result in memory is still 1 due to write conflicts.
[0012] Existing techniques, when calculating symmetric matrices, either do not take into account a. i,j =a j,i Or, it could simply ignore the upper triangular part of the matrix. It doesn't consider a. i,j =a j,i This results in the same data being read twice, leading to redundancy in the algorithm. Since the overhead of reading and writing during computation is often far greater than the actual multiplication overhead, simply ignoring the upper triangular portion of the matrix and continuing with the original algorithm would actually increase the computational load and time. Overall, the computational efficiency of this approach is lower than the aforementioned approach.
[0013] Potential write-back conflicts are a significant factor affecting the accuracy and efficiency of symmetric matrix calculations. Furthermore, during parallel computing, the load on threads is extremely uneven, severely wasting processor thread resources. Some threads become idle after processing data, while others need to process large amounts of data. Summary of the Invention
[0014] In view of this, the present invention proposes a parallel computation method and system for multiplying symmetric matrices and vectors, the specific scheme of which is as follows:
[0015] A parallel computation method for multiplying a symmetric matrix and a vector includes:
[0016] Obtain the symmetric matrix and vector to be computed, and determine the number of threads that can be computed in parallel.
[0017] The symmetric matrix is divided into a symmetry axis region, an upper triangular region, and a lower triangular region, with the symmetry axis as the boundary. The upper triangular region or the lower triangular region is further divided into multiple sub-regions based on the number of threads, with each sub-region consisting of rows. In each sub-region, a first axis and / or a second axis parallel to the symmetry axis are defined. The number of elements on the first axis is equal to the number of threads, and the number of elements on the second axis is less than the number of threads.
[0018] The product of the symmetry axis region and the vector is calculated in parallel using all or some threads to obtain a first matrix, and the first matrix is written into a first register, a second register, or a third register.
[0019] In each sub-region, a first axis is selected sequentially as the current first axis. All threads are used to perform two different first multiplication calculations on the current first axis to obtain two different sets of data, which are then written to the first register and the second register respectively.
[0020] In each sub-region, one or two second axes are selected sequentially as the current second axes. Two different second multiplication calculations are performed on the current second axes using all or part of the threads to obtain two different sets of data, which are written to the first register and the second register respectively, or four different sets of data are obtained and written to the first register, the second register and the third register respectively.
[0021] After completing the calculations for the symmetry axis region and each sub-region, a matrix is constructed based on the accumulated data in the first register, second register, and third register to obtain the calculation result of multiplying the symmetry matrix by the vector.
[0022] In one specific embodiment, when the number of threads is greater than 1, the sub-region is divided into a first sub-region and a second sub-region, wherein the number of rows in the first sub-region is equal to the number of threads, and the number of rows in the second sub-region is less than the number of threads;
[0023] There is at least one first sub-region in the upper triangular region or the lower triangular region;
[0024] In each first sub-region, define the first axis and the second axis;
[0025] In each second sub-region, a second axis is defined.
[0026] In one specific embodiment, the second axis is divided into a second axis with a complementary relationship and a second axis without a complementary relationship;
[0027] The complementary relationship is specifically manifested in the fact that, in the same sub-region, there are two second axes whose sum of the number of elements is equal to the number of threads;
[0028] When there is a complementary second axis in a certain sub-region, two complementary second axes are selected in sequence as the current second axis. After performing two multiplication calculations on the current second axis, four different sets of data are obtained.
[0029] In one specific embodiment, the first multiplication calculation includes:
[0030] The element a on the first axis i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ;
[0031] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0032] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle.
[0033] In one specific embodiment, the second multiplication calculation includes:
[0034] When a second axis is selected as the current second axis, the element 'a' on the current second axis... i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ;
[0035] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0036] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle;
[0037] When two second axes are selected as the current second axes, element a on one of the current second axes i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; another element a on the current second axis m,n , and the element x in the vector n Performing a multiplication operation yields a m,n x n , and the element x in the vector m Performing a multiplication operation yields a m,n x m ;
[0038] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0039] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle;
[0040] a m,n x n The sum is added to the m-th row of the matrix stored in the second register. m ;
[0041] a m,n x m Accumulated to the nth row s of the matrix stored in the third register n .
[0042] In one specific embodiment, the number of elements is different in two complementary second axes;
[0043] Perform two multiplications on the second axis with a larger number of elements to obtain two sets of data, and write these two sets of data into the first register and the second register respectively;
[0044] Perform two multiplications on the second axis, which has fewer elements, to obtain two sets of data. Write one set of data into the third register and the other set of data into either the first or second register.
[0045] In one specific embodiment, let the order of the symmetric matrix be M, and the number of threads be L;
[0046] When M = 2nL + 1, the upper triangular region or the lower triangular region is divided into 2n first sub-regions according to the number of threads, with each row as a unit;
[0047] Where M, L, and n are all positive integers.
[0048] A parallel computing system for multiplying symmetric matrices and vectors includes:
[0049] The input unit is used to obtain the symmetric matrix and vector to be calculated and to determine the number of threads that can be computed in parallel.
[0050] A region division unit is used to divide the symmetric matrix into a symmetry axis region, an upper triangular region, and a lower triangular region with the symmetry axis as the boundary. The upper triangular region or the lower triangular region is divided into multiple sub-regions according to the number of threads, with each sub-region being a row unit. In each sub-region, a first axis and / or a second axis parallel to the symmetry axis are defined. The number of elements on the first axis is equal to the number of threads, and the number of elements on the second axis is less than the number of threads.
[0051] The symmetry axis calculation unit is used to calculate the product of the symmetry axis region and the vector in parallel using all or part of the threads to obtain a first matrix, and write the first matrix into a first register, a second register or a third register;
[0052] The first axis calculation unit is used to sequentially select a first axis as the current first axis in each sub-region, and use all threads to perform two different first multiplication calculations on the current first axis to obtain two different sets of data and write them into the first register and the second register respectively.
[0053] The second axis calculation unit is used to sequentially select one or two second axes as the current second axis in each sub-region, and use all or part of the threads to perform two different second multiplication calculations on the current second axis to obtain two different sets of data and write them into the first register and the second register respectively, or to obtain four different sets of data and write them into the first register, the second register and the third register respectively.
[0054] The result calculation unit is used to construct a matrix based on the accumulated data in the first register, the second register, and the third register after completing the calculation of the symmetry axis region and each sub-region, and to obtain the calculation result of the multiplication of the symmetry matrix and the vector.
[0055] In one specific embodiment, the first multiplication calculation in the first axis calculation unit includes:
[0056] The element a on the first axis i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ;
[0057] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0058] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle.
[0059] In one specific embodiment, the second multiplication calculation in the second axis calculation unit includes:
[0060] When a second axis is selected as the current second axis, the element 'a' on the current second axis... i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ;
[0061] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0062] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle;
[0063] When two second axes are selected as the current second axes, element a on one of the current second axes i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i; another element a on the current second axis m,n , and the element x in the vector n Performing a multiplication operation yields a m,n x n , and the element x in the vector m Performing a multiplication operation yields a m,n x m ;
[0064] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0065] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle;
[0066] a m,n x n The sum is added to the m-th row of the matrix stored in the second register. m ;
[0067] a m,n x m Accumulated to the nth row s of the matrix stored in the third register n .
[0068] Beneficial effects:
[0069] This invention provides a parallel computing method and system for multiplying symmetric matrices and vectors. It can accurately and quickly perform multiplication of symmetric matrices and vectors. By rationally planning the order of element processing in the matrix, it enables each thread to allocate resources reasonably, effectively avoids write conflicts, realizes multi-threaded parallel computing, has high computing efficiency, and ensures balanced load and reasonable distribution of thread resources among threads. Attached Figure Description
[0070] Figure 1 This is a flowchart of the parallel computing method according to an embodiment of the present invention;
[0071] Figure 2 This is a schematic diagram of each region of the matrix in an embodiment of the present invention;
[0072] Figure 3 This is a schematic diagram of the parallel computing system structure according to an embodiment of the present invention.
[0073] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0074] Figure reference numerals: 1-Input unit; 2-Region division unit; 3-Symmetry axis calculation unit; 4-First axis calculation unit; 5-Second axis calculation unit; 6-Result calculation unit. Detailed Implementation
[0075] In the following, various embodiments of the invention will be described more fully. The invention may have various embodiments, and adjustments and changes may be made therein. However, it should be understood that there is no intention to limit the various embodiments of the invention to the specific embodiments disclosed herein, but rather the invention should be understood to cover all adjustments, equivalents, and / or alternatives falling within the spirit and scope of the various embodiments disclosed herein.
[0076] It should be noted that the multiplication operations of symmetric matrices and vectors in this invention must strictly adhere to the rules of matrix multiplication. The symmetric matrix is M×N, the vector is N×1, M=N, and satisfies a i,j =a j,i The order of a symmetric matrix generally needs to be greater than or equal to 3. Of course, the scheme of this application can also be used for a second-order symmetric matrix. The order can be odd or even.
[0077] It's important to note that the number of threads represents the maximum number of threads that can run in parallel. Different processors have different thread counts. Using all threads means running the computation in parallel with a subset of the specified number of threads, while using a subset means performing the computation in parallel with fewer than the specified number of threads. The number of threads can be either odd or even. Generally, to avoid wasting thread resources, the number of threads should be less than or equal to the order of the matrix. A higher thread count allows for the parallel processing of higher-order symmetric matrices.
[0078] It should be noted that the axis of symmetry of a symmetric matrix is the main diagonal, the axis of symmetry region is the region containing the axis of symmetry, the upper triangular region is the triangular region above the axis of symmetry in the symmetric matrix, and the lower triangular region is the triangular region below the axis of symmetry in the symmetric matrix. In this application, neither the upper nor lower triangular region includes the axis of symmetry; the axis of symmetry region is parallel to the upper and lower triangular regions.
[0079] It should be noted that the calculation of a region and a vector in this application refers to the calculation of the elements in that region and the vector. For example, parallel calculation of the product of the axis of symmetry region and the vector is to multiply each element in the axis of symmetry region with the corresponding element in the vector.
[0080] It should be noted that the first and second axes in this application are lines parallel to the axis of symmetry, used for the convenience of describing the positions of elements on the matrix. Calculations of the first and second axes refer to calculations of the elements on those axes. The second axis may have only one element or multiple elements.
[0081] The terminology used in the various embodiments disclosed herein is for the purpose of describing particular embodiments only and is not intended to limit the various embodiments disclosed herein. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which the various embodiments disclosed herein pertain. The terms (such as those defined in commonly used dictionaries) are to be interpreted as having the same meaning as in the context of the relevant technical field and are not to be interpreted as having an idealized or overly formal meaning, unless clearly defined in the various embodiments disclosed herein.
[0082] Example 1
[0083] Embodiment 1 of this invention discloses a parallel computation method for multiplying symmetric matrices and vectors. This method avoids write conflicts, achieves multi-threaded parallel computation, and ensures balanced load across threads and reasonable distribution of thread resources. The flowchart of the parallel computation method is attached to the specification. Figure 1 As shown, the specific solution is as follows:
[0084] A parallel computation method for multiplying a symmetric matrix and a vector includes the following steps:
[0085] 101. Obtain the symmetric matrix and vector to be calculated, and determine the number of threads that can be computed in parallel.
[0086] 102. Divide the symmetric matrix into a symmetry axis region, an upper triangular region, and a lower triangular region, using the symmetry axis as the boundary. Divide the upper triangular region or the lower triangular region into multiple sub-regions based on the number of threads, with each sub-region as a row unit. In each sub-region, define a first axis and / or a second axis parallel to the symmetry axis. The number of elements on the first axis is equal to the number of threads, and the number of elements on the second axis is less than the number of threads.
[0087] 103. Use all or some threads to compute the product of the symmetry axis region and the vector in parallel to obtain the first matrix, and write the first matrix into the first register, the second register, or the third register;
[0088] 104. In each sub-region, select a first axis in sequence as the current first axis, and use all threads to perform two different first multiplication calculations on the current first axis to obtain two different sets of data, which are then written to the first register and the second register respectively.
[0089] 105. In each sub-region, select one or two second axes as the current second axes in sequence, and use all or part of the threads to perform two different second multiplication calculations on the current second axes to obtain two different sets of data and write them into the first register and the second register respectively, or obtain four different sets of data and write them into the first register, the second register and the third register respectively.
[0090] 106. After completing the calculation of the symmetry axis region and each sub-region, construct a matrix based on the accumulated data in the first register, second register and third register, and obtain the calculation result of multiplying the symmetry matrix and the vector.
[0091] There is no fixed order between the calculation of the symmetry axis region and the calculation of each sub-region. The symmetry axis region can be calculated first, followed by each sub-region; or the sub-regions can be calculated first, followed by the symmetry axis region; or the calculation of the symmetry axis region can be interspersed during the calculation of each sub-region. The symmetry axis region can be calculated using all or some threads, and the results can be written to the first, second, or third register.
[0092] Preferably, the solution of this application is for symmetric matrices of order three or higher, and the number of threads is at least 2. When the number of threads is equal to 1, it is a single-threaded computation and is not applicable to the solution of this application. When the number of threads is greater than 1, the sub-region is divided into a first sub-region and a second sub-region. The number of rows in the first sub-region is equal to the number of threads, and the number of rows in the second sub-region is less than the number of threads. There is at least one first sub-region in either the upper triangular region or the lower triangular region. The parity of the order of the symmetric matrix and the parity of the number of threads will affect the delineation of the sub-regions, the first axis, and the second axis. (See attached specification) Figure 2 An 8×8 matrix is provided, the number of threads is set to 4, the first sub-region is shown as A2, and the second sub-region is shown as A1.
[0093] After removing the symmetry axis region from the matrix, the upper and lower triangular regions must have the same number of rows, and their elements must be symmetric about the symmetry axis. Therefore, processing only one of the upper and lower triangular regions is sufficient to derive the other. When defining subregions, it is necessary to ensure that the number of rows in at least one subregion equals the number of threads. For example, with 4 threads and an order of 8, removing the symmetry axis region results in both the upper and lower triangular regions having 7 rows. Within either the upper or lower triangular region, a first subregion and a second subregion are defined. The second subregion is located in the middle of the upper or lower triangular region where there is less data. It should be noted that "the middle region where there is less data" refers to a region with a small number of elements in several consecutive rows. Figure 2 In the example, there are 4 threads. In the lower triangular region of row 7, a first sub-region of row 4 and a second sub-region of row 3 can be defined. The second sub-region A1 is located in the upper three rows, and there is less data in the upper three rows. The first sub-region A2 is located in the lower three rows of the lower triangular region.
[0094] Within each first sub-region, a first axis and a second axis are defined; within each second sub-region, a second axis is defined. The primary difference between the first and second axes is the number of elements. Both axes are formed by lines connecting elements within the matrix. A single element at the bottom left or top right corner of the matrix can also be considered a second axis. The first and second axes are shown in the appendix to the instruction manual. Figure 2 As shown. In Figure 2 In the diagram, each line (c1, c2, c3, c4) has 4 elements, which is equal to the number of threads. Therefore, c1, c2, c3, c4 form the first axis. Each line (b1, b2, b3) has fewer than 4 elements. Therefore, b1, b2, b form the second axis.
[0095] The number of elements on each first axis equals the number of threads. The processor can run at maximum thread count when processing the first axis. When each thread processes (non-diagonal elements, i.e., elements on non-symmetric axes) a... i,j When this happens, two products will be calculated: a i,j x i With a i,j x j Because of a i,j x j The corresponding value is y. i Add it to the thread's own register r i Inside. And a i,j x i Corresponding y j Directly add it to the memory y j Since the threads are located in staggered positions, writing back to y at this time... j No write conflicts will occur.
[0096] The first multiplication calculation includes: the element 'a' on the current first axis.i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; will a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i In the middle; will a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle.
[0097] The second axis is divided into complementary second axes and non-complementary second axes. Complementarity is specifically manifested when, within the same sub-region, there exist two second axes whose sum of element counts equals the number of threads. Figure 2 In the diagram, c is the first axis, b is the second axis, and b1 has 1 element, b3 has 3 elements, and the sum of the number of elements in b1 and b3 is 4, corresponding to the number of threads. Therefore, b1 and b3 have a complementary relationship.
[0098] When a sub-region contains complementary second axes, two complementary second axes are selected sequentially as the current second axis. After performing two multiplications on each current second axis, four different sets of data are obtained. For complementary second axes, the processor simultaneously calculates the elements on both axes, ensuring that the processor always operates at maximum thread capacity, fully utilizing thread resources and minimizing thread idle time. When processing two second axes, the storage method needs to be modified to avoid write conflicts between new and old threads.
[0099] The second multiplication calculation includes:
[0100] When a second axis is selected as the current second axis, the element 'a' on the current second axis... i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; will a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i In the middle; will a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. jIn this context, selecting a second axis as the current second axis means that this second axis has no complementary relationship; no other second axis can be found in the same region whose sum of the number of elements equals the number of threads. Therefore, this second axis can only be processed separately using a portion of the threads. Generally, only one second axis without a complementary relationship will exist. When the number of threads and the matrix order meet specific conditions, no second axis without a complementary relationship will exist.
[0101] When two secondary axes are selected as the current secondary axes, these two secondary axes are complementary. One of the elements 'a' on the current secondary axis... i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; another element a on the current second axis m,n , and the element x in the vector n Performing a multiplication operation yields a m,n x n , and the element x in the vector m Perform a multiplication operation to get am m,n x m ;
[0102] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0103] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle;
[0104] a m,n x n The sum is added to the m-th row of the matrix stored in the second register. m ;
[0105] a m,n x m Accumulated to the nth row s of the matrix stored in the third register n .
[0106] Let the order of the symmetric matrix be M, and the number of threads be L. When M = 2nL + 1, the upper or lower triangular region is divided into 2n first sub-regions, each row-wise, according to the number of threads; where M, L, and n are all positive integers. In this case, there is no second sub-region. For example, to calculate a 97×97 matrix, the number of concurrent threads (one warp) is 32. Therefore, the entire multiplication calculation is divided into three steps, corresponding to the top 32 rows, the middle 32 rows, and the bottom 32 rows.
[0107] Taking an 8x8 matrix as an example, the lower triangular region is processed by dividing it into three upper rows and four lower rows. Taking the four lower rows as an example, four threads are assigned to process each of the four rows. However, the processing order starts from the first axis closest to the axis of symmetry, proceeding from right to left. A register r is pre-defined. i and memory y i Initially, r i and y i The value is 0. After each set of data is calculated, the data will be stored in the corresponding location and gradually accumulated.
[0108] In the first phase, elements on the first axis are processed. When each thread processes (non-diagonal) a... i,j At that time, it will calculate two products: a i,j x i With a i,j x j Because of a i,j x j The corresponding value is y. i Add it to the thread's own register r i Inside. And a i,j x i Corresponding y j Directly add it to the memory y j Since the threads are located in staggered positions, writing back to y at this time... j No write conflicts will occur.
[0109]
[0110] Here, - indicates repeated and omitted data (taking only the lower triangular region as an example), indicates data that has been processed, and bold data indicates data that is being processed.
[0111] In the second phase, some of the upper threads touch the left side of the matrix, meaning the first axis has been processed and processing of the complementary second axis begins. At this point, it is moved to the bottom left corner, and its processing order is changed to bottom-to-top:
[0112]
[0113] In the matrix above, the thread that was originally at the top starts processing 'a'.7,0 At the same time, these threads modified the write-back method: a i,j x j Accumulated memory y i , and a i,j x i Accumulated into a brand new register s j Note that at this point, there is still no write to memory between the old and new threads. i Conflict.
[0114] In the third stage, the second axis, which lacks a complementary relationship, is processed. In the final stage, only half of the diagonal data remains. Simply shut down the modified thread and let the thread below continue processing.
[0115]
[0116] After all stages are completed, all threads can simultaneously transfer their held registers (r) i and s i Add back the y held in memory i There are no conflicts in this process either. It should be noted that if the thread processes the first four lines, then r... i and s i In fact, all of them will be held by the i-th thread. In this way, there is no conflict.
[0117] This embodiment provides a parallel computing method for multiplying symmetric matrices and vectors. It can accurately and quickly perform multiplication of symmetric matrices and vectors. By rationally planning the order of element processing in the matrix, resources are reasonably allocated to each thread, effectively avoiding write conflicts, realizing multi-threaded parallel computing, with high computing efficiency, balanced load of each thread, and reasonable distribution of thread resources.
[0118] Example 2
[0119] Embodiment 2 of this invention discloses a parallel computing system for multiplying symmetric matrices and vectors. Based on Embodiment 1, the method of Embodiment 1 is systematized, and the specific structure is shown in the appendix to the specification. Figure 3 As shown, the specific solution is as follows:
[0120] A parallel computing system for multiplying symmetric matrices and vectors includes:
[0121] Input unit 1 is used to obtain the symmetric matrix and vector to be calculated and to determine the number of threads that can be computed in parallel.
[0122] Region division unit 2 is used to divide the symmetric matrix into a symmetry axis region, an upper triangular region, and a lower triangular region with the symmetry axis as the boundary. The upper triangular region or the lower triangular region is divided into multiple sub-regions according to the number of threads, with each sub-region as a row unit. In each sub-region, a first axis and / or a second axis parallel to the symmetry axis are defined. The number of elements on the first axis is equal to the number of threads, and the number of elements on the second axis is less than the number of threads.
[0123] Symmetry axis calculation unit 3 is used to calculate the product of the symmetry axis region and the vector in parallel using all or part of the threads to obtain the first matrix, and write the first matrix into the first register, the second register or the third register;
[0124] The first axis calculation unit 4 is used to sequentially select a first axis as the current first axis in each sub-region, and use all threads to perform two different first multiplication calculations on the current first axis to obtain two different sets of data and write them into the first register and the second register respectively.
[0125] The second axis calculation unit 5 is used to sequentially select one or two second axes as the current second axis in each sub-region, and use all or part of the threads to perform two different second multiplication calculations on the current second axis to obtain two different sets of data and write them into the first register and the second register respectively, or to obtain four different sets of data and write them into the first register, the second register and the third register respectively.
[0126] The result calculation unit 6 is used to construct a matrix based on the accumulated data in the first register, the second register, and the third register after completing the calculation of the symmetry axis region and each sub-region, and obtain the calculation result of the multiplication of the symmetry matrix and the vector.
[0127] In the first axis calculation unit 4, the number of elements on each first axis is equal to the number of threads. The processor can run at maximum thread count when processing the first axis. When each thread processes (non-diagonal elements, i.e., elements on non-symmetric axes) a i,j When this happens, two products will be calculated: a i,j x i With a i,j x j Because of a i,j x j The corresponding value is y. i Add it to the thread's own register r i Inside. And a i,j x i Corresponding y j Directly add it to the memory y j Since the threads are located in staggered positions, writing back to y at this time... j No write conflicts will occur.
[0128] The first multiplication calculation includes:
[0129] The element a on the first axis i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ;
[0130] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0131] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle.
[0132] In the second axis calculation unit 5, the second axis is divided into second axes with complementary relationships and second axes without complementary relationships; the complementary relationship is specifically manifested in that, within the same sub-region, there exist two second axes whose sum of the number of elements equals the number of threads. Figure 2 In the diagram, c is the first axis, b is the second axis, and b1 has 1 element, b3 has 3 elements, and the sum of the number of elements in b1 and b3 is 4, corresponding to the number of threads. Therefore, b1 and b3 have a complementary relationship.
[0133] When a sub-region contains complementary second axes, two complementary second axes are selected sequentially as the current second axis. After performing two multiplications on each current second axis, four different sets of data are obtained. For complementary second axes, the processor simultaneously calculates the elements on both axes, ensuring that the processor always operates at maximum thread capacity, fully utilizing thread resources and minimizing thread idle time. When processing two second axes, the storage method needs to be modified to avoid write conflicts between new and old threads.
[0134] The second multiplication calculation includes:
[0135] When a second axis is selected as the current second axis, the element 'a' on the current second axis... i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ;
[0136] a i,j xj Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0137] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle;
[0138] When two second axes are selected as the current second axes, element a on one of the current second axes i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; another element a on the current second axis m,n , and the element x in the vector n Performing a multiplication operation yields a m,n x n , and the element x in the vector m Performing a multiplication operation yields a m,n x m ;
[0139] a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle;
[0140] a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle;
[0141] a m,n x n The sum is added to the m-th row of the matrix stored in the second register. m ;
[0142] a m,n x m Accumulated to the nth row s of the matrix stored in the third register n .
[0143] This embodiment provides a parallel computing system for multiplying symmetric matrices and vectors, systematizing the method of Embodiment 1 and making it more practical.
[0144] This invention provides a parallel computing method and system for multiplying symmetric matrices and vectors. It can accurately and quickly perform multiplication of symmetric matrices and vectors. By rationally planning the order of element processing in the matrix, it enables each thread to allocate resources reasonably, effectively avoids write conflicts, realizes multi-threaded parallel computing, has high computing efficiency, and ensures balanced load and reasonable distribution of thread resources among threads.
[0145] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of a preferred embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing the present invention. Those skilled in the art will understand that the modules in the apparatus of the embodiment can be distributed within the apparatus of the embodiment as described, or can be located in one or more apparatuses different from this embodiment, with corresponding changes. The modules of the above-described embodiment can be combined into one module, or further divided into multiple sub-modules. The above-described serial numbers are for descriptive purposes only and do not represent the superiority or inferiority of the embodiment. The above disclosures are only a few specific embodiments of the present invention; however, the present invention is not limited thereto, and any variations conceived by those skilled in the art should fall within the protection scope of the present invention.
Claims
1. A parallel computation method for multiplying a symmetric matrix and a vector, characterized in that, include: Obtain the symmetric matrix and vector to be computed, and determine the number of threads that can be computed in parallel. The symmetric matrix is divided into a symmetry axis region, an upper triangular region, and a lower triangular region, with the symmetry axis as the boundary. The upper triangular region or the lower triangular region is further divided into multiple sub-regions based on the number of threads, with each sub-region consisting of rows. In each sub-region, a first axis and / or a second axis parallel to the symmetry axis are defined. The number of elements on the first axis is equal to the number of threads, and the number of elements on the second axis is less than the number of threads. The product of the symmetry axis region and the vector is calculated in parallel using all or some threads to obtain a first matrix, and the first matrix is written into a first register, a second register, or a third register. In each sub-region, a first axis is selected sequentially as the current first axis. All threads are used to perform the first multiplication calculation on the current first axis to obtain two different sets of data, which are then written to the first register and the second register respectively. In each sub-region, one or two second axes are selected sequentially as the current second axes. The second multiplication is performed on the current second axes using all or part of the threads to obtain two different sets of data and write them into the first register and the second register respectively, or to obtain four different sets of data and write them into the first register, the second register and the third register respectively. After completing the calculations for the symmetry axis region and each sub-region, a matrix is constructed based on the accumulated data in the first register, second register, and third register to obtain the calculation result of multiplying the symmetry matrix by the vector.
2. The parallel computing method according to claim 1, characterized in that, When the number of threads is greater than 1, the sub-region is divided into a first sub-region and a second sub-region, where the number of rows in the first sub-region is equal to the number of threads, and the number of rows in the second sub-region is less than the number of threads. There is at least one first sub-region in the upper triangular region or the lower triangular region; In each first sub-region, define the first axis and the second axis; In each second sub-region, a second axis is defined.
3. The parallel computing method according to claim 1, characterized in that, The second axis is divided into second axes with complementary relationships and second axes without complementary relationships; The complementary relationship is specifically manifested in the fact that, in the same sub-region, there are two second axes whose sum of the number of elements is equal to the number of threads; When there is a complementary second axis in a certain sub-region, two complementary second axes are selected in sequence as the current second axis. After performing two multiplication calculations on the current second axis, four different sets of data are obtained.
4. The parallel computing method according to claim 1, characterized in that, The first multiplication calculation includes: The element a on the first axis i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle; a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle.
5. The parallel computing method according to claim 1, characterized in that, The second multiplication calculation includes: When a second axis is selected as the current second axis, the element 'a' on the current second axis... i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle; a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle; When two second axes are selected as the current second axes, element a on one of the current second axes i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; another element a on the current second axis m,n , and the element x in the vector n Performing a multiplication operation yields a m,n x n , and the element x in the vector m Performing a multiplication operation yields a m,n x m ; a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle; a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle; a m,n x n The sum is added to the m-th row of the matrix stored in the second register. m ; a m,n x m Accumulated to the nth row s of the matrix stored in the third register n .
6. The parallel computing method according to claim 3, characterized in that, The number of elements differs in the two complementary second axes. Perform two multiplications on the second axis with a larger number of elements to obtain two sets of data, and write these two sets of data into the first register and the second register respectively; Perform two multiplications on the second axis, which has fewer elements, to obtain two sets of data. Write one set of data into the third register and the other set of data into either the first or second register.
7. The parallel computing method according to claim 2, characterized in that, Let the order of the symmetric matrix be M, and the number of threads be L; When M = 2nL + 1, the upper triangular region or the lower triangular region is divided into 2n first sub-regions according to the number of threads, with each row as a unit; Where M, L, and n are all positive integers.
8. A parallel computing system for multiplying symmetric matrices and vectors, characterized in that, include: The input unit is used to obtain the symmetric matrix and vector to be calculated and to determine the number of threads that can be computed in parallel. A region division unit is used to divide the symmetric matrix into a symmetry axis region, an upper triangular region, and a lower triangular region with the symmetry axis as the boundary. The upper triangular region or the lower triangular region is divided into multiple sub-regions according to the number of threads, with each sub-region being a row unit. In each sub-region, a first axis and / or a second axis parallel to the symmetry axis are defined. The number of elements on the first axis is equal to the number of threads, and the number of elements on the second axis is less than the number of threads. The symmetry axis calculation unit is used to calculate the product of the symmetry axis region and the vector in parallel using all or part of the threads to obtain a first matrix, and write the first matrix into a first register, a second register or a third register; The first axis calculation unit is used to sequentially select a first axis as the current first axis in each sub-region, use all threads to perform the first multiplication calculation on the current first axis, obtain two different sets of data, and write them into the first register and the second register respectively. The second axis calculation unit is used to sequentially select one or two second axes as the current second axis in each sub-region, and use all or part of the threads to perform the second multiplication calculation on the current second axis to obtain two different sets of data and write them into the first register and the second register respectively, or to obtain four different sets of data and write them into the first register, the second register and the third register respectively. The result calculation unit is used to construct a matrix based on the accumulated data in the first register, the second register, and the third register after completing the calculation of the symmetry axis region and each sub-region, and to obtain the calculation result of the multiplication of the symmetry matrix and the vector.
9. The parallel computing system according to claim 8, characterized in that, In the first axis calculation unit, the first multiplication calculation includes: The element a on the first axis i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle; a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle.
10. The parallel computing system according to claim 8, characterized in that, In the second axis calculation unit, the second multiplication calculation includes: When a second axis is selected as the current second axis, the element 'a' on the current second axis... i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle; a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle; When two second axes are selected as the current second axes, element a on one of the current second axes i,j , and the element x in the vector j Performing a multiplication operation yields a i,j x j , and the element x in the vector i Performing a multiplication operation yields a i,j x i ; another element a on the current second axis m,n , and the element x in the vector n Performing a multiplication operation yields a m,n x n , and the element x in the vector m Performing a multiplication operation yields a m,n x m ; a i,j x j Accumulated into the i-th row r of the matrix stored in the first register i middle; a i,j x i The sum is added to the j-th row y of the matrix stored in the second register. j middle; a m,n x n The sum is added to the m-th row of the matrix stored in the second register. m ; a m,n x m Accumulated to the nth row s of the matrix stored in the third register n .
Citation Information
Patent Citations
Data processing method, device, equipment and storage medium
CN110377877A
Data processing method and device
CN111859035A