Array computing expression language conversion method, device, equipment and storage medium
By obtaining and defining array identification relationships, generating concise predefined code snippets and adding them to the old version of code, the error and readability problems in array computing expression language conversion is solved, and programming efficiency and accuracy is improved.
Patent Information
- Application Number
- CN202111304753.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-05
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2041-11-05
AI Technical Summary
The existing array calculation expression language conversion methods are prone to errors during the language conversion process and have poor readability, resulting in low programming efficiency.
By obtaining the array identification relationship between the first and second languages, setting the function to define a predefined array code snippet, and adding it to the old version code snippet in the second language, generating a new version code snippet, and marking it with the array identifier. , simplify expressions and verify code accuracy.
It improves the readability and programming efficiency of the program, ensures the accuracy of the conversion of array computing expression languages, and avoids the problems of lengthy code and poor readability.
Smart Images

Figure CN114047926B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a method, device, equipment and storage medium for converting an array computing expression language. Background Art
[0002] With the rapid development of science and technology, technicians in the computer field gradually use multiple processors to solve the same problem in parallel, that is, to decompose the problem to be solved into several parts, each part is calculated in parallel by an independent processor, thereby greatly improving the calculation speed. Therefore, it is necessary to uniformly convert the previously written multiple programs into an expression language that is easy for technicians to use.
[0003] However, considering the uncertainty of array dimensions in the program's expression language and the readability of language conversion, the conversion method of array computing expression language has become a research difficulty. At present, some studies have proposed conversion methods for array computing expression language, but these methods are prone to errors in the transcoding process during language conversion, and some methods usually require adding additional code, resulting in poor readability of the converted language and reducing the programming efficiency of staff. Summary of the invention
[0004] The embodiments of the present invention provide a method, device, equipment and storage medium for converting an array computing expression language, which can increase the readability of a program and improve the programming efficiency of a staff member.
[0005] In a first aspect, an embodiment of the present invention provides a method for converting an array computing expression language, comprising:
[0006] Get the relationship between the array identifier of the first language and the array identifier of the second language;
[0007] The relationship is defined by setting a function to form a predefined array code snippet;
[0008] Convert the array calculation expression code snippet of the first language into the old version of the array calculation expression code snippet of the second language;
[0009] The predefined array code snippet is added to an old version of an array calculation expression code snippet in a second language to generate a new version of an array calculation expression code snippet in the second language; wherein the array elements contained in the array calculation expression code snippet are marked with array identifiers.
[0010] Optionally, obtaining the relationship between the array identifier of the first language and the array identifier of the second language includes:
[0011] If the array in the first language is a multidimensional array, determining a value range of the array subscript in the first language and the array subscript in the second language in each dimension;
[0012] The relationship between the array subscript of the first language and the array subscript of the second language is determined based on the value range.
[0013] The above technical solution can intuitively represent the relationship between the array subscript of the first language and the array subscript of the second language by determining the relationship between the array subscript of the first language and the array subscript of the second language according to the value range of the array subscript of the first language and the array subscript of the second language in each dimension when the array in the first language is a multidimensional array, thereby providing a basis for the subsequent conversion of the array calculation expression language.
[0014] Optionally, defining the relationship by setting a function includes:
[0015] If the array in the first language is a multi-dimensional array, a relationship between the array subscript in the first language and the array subscript in the second language in each dimension is defined by setting a function.
[0016] The above technical solution can make the expression of the array more concise by defining the relationship between the array subscript of the first language and the array subscript of the second language in each dimension when the array in the first language is a multidimensional array, thereby providing a basis for the subsequent conversion of the array calculation expression language.
[0017] Optionally, the setting function includes a macro definition function.
[0018] The above technical solution can make the expression of array more concise by specifying the type of the setting function as a macro definition function, thereby providing a basis for the subsequent conversion of the array calculation expression language.
[0019] Optionally, the method further includes: running the array calculation expression code snippet in the first language to determine a numerical value corresponding to the array calculation expression as the first numerical value;
[0020] Run the calculation expression code snippet of the new version of the array in the second language, and determine a numerical value corresponding to the calculation expression of the array as a second numerical value;
[0021] If the first value is the same as the second value, it is determined that the calculation expression code snippet of the array in the second language is correct.
[0022] The above technical solution uses the situation that the first value is the same as the second value as the basis for judging whether the calculation expression code fragment of the array in the second language is correct, thereby realizing reasonable verification of the conversion method of the array calculation expression language and ensuring the accuracy of the method.
[0023] Optionally, the method further includes: if the first value and the second value are different, determining that a calculation expression code snippet of the new version array of the second language is wrong;
[0024] Returns an operation that gets the relationship of an array identifier of a first language to an array identifier of a second language.
[0025] The above technical solution uses the difference between the first value and the second value as the basis for judging the error of the calculation expression code fragment of the array in the second language, and proposes a reasonable solution, so as to make the conversion method of the array calculation expression language more perfect.
[0026] Optionally, the first language includes Fortran language, and the second language includes C language.
[0027] The above technical solution can provide a more specific usage scenario for the conversion method of the array calculation expression language by specifying the first language as Fortran language and the second language as C language, thereby ensuring the executability of the conversion method of the array calculation expression language.
[0028] In a second aspect, an embodiment of the present invention further provides a device for converting an array computing expression language, the device comprising:
[0029] An acquisition module, used for acquiring the relationship between the array identifier of the first language and the array identifier of the second language;
[0030] A definition module, used for defining the relationship by setting a function to form a predefined array code snippet;
[0031] A code conversion module, used for converting an array calculation expression code snippet in a first language into an old version of an array calculation expression code snippet in a second language;
[0032] An adding module is used to add the predefined array code snippet to an old version of an array calculation expression code snippet in a second language to generate a new version of an array calculation expression code snippet in the second language; wherein the array elements contained in the array calculation expression code snippet are marked with array identifiers.
[0033] In a third aspect, an embodiment of the present invention further provides an electronic device, including:
[0034] one or more processors;
[0035] a storage device for storing one or more programs,
[0036] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any embodiment of the present invention.
[0037] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements a method as described in any embodiment of the present invention.
[0038] The technical solution of the embodiment of the present invention defines the relationship between the array identifier of the first language and the array identifier of the second language by using a setting function, generates a predefined array code snippet, then converts the array calculation expression code snippet of the first language into an old version of the array calculation expression code snippet of the second language, and adds the predefined array code snippet to the old version of the array calculation expression code snippet of the second language to generate a new version of the array calculation expression code snippet of the second language, thereby increasing the readability of the program and improving the programming efficiency of the staff. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1a It is a flow chart of a method for converting an array computing expression language provided by an embodiment of the present invention;
[0040] Figure 1b It is a schematic diagram of the storage of a Fortran language array and a C language array in a memory applicable to an embodiment of the present invention;
[0041] Figure 1c It is a schematic diagram of the logical storage state of a Fortran language array and a C language array in a memory applicable to an embodiment of the present invention;
[0042] Figure 1d It is a schematic diagram of the difference between the declaration of a Fortran language array and a C language array applicable to an embodiment of the present invention;
[0043] Figure 2 It is a flow chart of a method for converting an array computing expression language provided by an embodiment of the present invention;
[0044] Figure 3 It is a structural schematic diagram of a conversion device for an array computing expression language provided by an embodiment of the present invention;
[0045] Figure 4 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0047] With the rapid development of science and technology, technicians in the computer field have gradually used multiple processors to solve the same problem in parallel, thereby greatly improving the computing speed. Therefore, it is necessary to convert the previously written multiple programs into an expression language that is easy for technicians to use.
[0048] Formula Translation (Fortran) language has become the preferred expression language for parallel computing on an open software platform (ROCm, Platform for GPU-Enabled HPC and Ultrascale Computing) due to its advantages such as simplicity and intuitiveness, powerful matrix operation function, and strict syntax. Among them, Fortran language can be designed for scientific, engineering problems or problems in enterprise management that can be expressed in mathematical formulas, and has strong numerical computing functions; Among them, the ROCm platform is an open source, high-performance and ultra-large-scale cluster GPU general computing platform (programming framework) developed by AMD, which is similar to NVIDIA's unified computing device architecture platform (CUDA, Compute Unified Device Architecture); Among them, parallel computing can refer to the process of using multiple computing resources at the same time to solve computing problems. It is an effective means to improve the computing speed and processing power of computer systems. Multiple processors can be used to collaboratively solve the same problem, that is, the problem to be solved is decomposed into several parts, and each part is calculated in parallel by an independent processor.
[0049] However, parallel computing of Fortran programs on the ROCm platform must be heterogeneously transplanted, that is, Fortran must be transcoded into CUDAFortran, then converted into CUDA C, and then the CUDA C program must be automatically transcoded into HIP C using the ROCm built-in tool hipify, so that parallel computing can be performed on the ROCm platform.
[0050] In the case of converting CUDAFortran to CUDA C, due to the difference in the expression of arrays in C language, for example, for a 10*10*10 three-dimensional array, the marking position of a certain element in Fortran language is a(2,3,4), and the corresponding expression of the element in C language should be a(2+3*10+4*10*10). Therefore, the array subscript needs to be calculated during the transcoding process, which is prone to errors, and the converted language is long and has poor readability. In addition, the conversion method of the array calculation expression language usually uses a class to define the array subscript of the array variable or uses the template class method to abstract the attributes and parameters of the class, thereby simplifying the conversion code snippet of the array calculation expression language. However, due to the uncertainty of the Fortran array dimension, sometimes there are three-dimensional arrays and two-dimensional arrays at the same time. If a class is used to define the array subscript of the array variable, multiple classes need to be defined. If the template class method is used, additional code is usually required, so that the readability of the program is reduced. Therefore, an embodiment of the present invention proposes a conversion method of an array calculation expression language, which achieves the effect of increasing the readability of the program and improving the programming efficiency of the staff.
[0051] Figure 1a A flowchart of a method for converting an array computing expression language provided in an embodiment of the present invention. The embodiment of the present invention is applicable to the case where an array computing expression language is converted. The method can be executed by a conversion device for an array computing expression language. The device can be implemented in hardware and / or software and can generally be integrated in an electronic device, which can be a terminal device, a server, etc.
[0052] like Figure 1a As shown, a method for converting an array computing expression language provided by an embodiment of the present invention includes the following specific steps:
[0053] S110: Obtaining the relationship between the array identifier of the first language and the array identifier of the second language.
[0054] The first language may refer to a language that needs to be converted into an array calculation expression language; the second language may refer to a language that is displayed after the array calculation expression language conversion. In an embodiment of the present invention, the first language includes Fortran language, and the second language includes C language.
[0055] Among them, the array identifier can be an array subscript; since there is no concept of rows and columns in the memory, both two-dimensional arrays and three-dimensional arrays are stored in the memory in the form of "a line"; and high-level languages usually do not directly access memory addresses, so Fortran and C use arrays to "name" these memory addresses, and use the array name combined with the array subscript to achieve random access to these memory addresses. Therefore, the relationship between the array identifier of the first language and the array identifier of the second language can refer to the relationship between the array subscript of the first language and the array subscript of the second language. Specifically, such as Figure 1b The following is a schematic diagram of the storage of Fortran language arrays and C language arrays in memory. Figure 1c The figure shows the logical storage state of Fortran language arrays and C language arrays in memory, where the two columns on the left represent the logical storage state of Fortran language arrays in memory, and the two rows on the right represent the logical storage state of C language arrays in memory. Taking the memory address 0x0041F100-0x0041F1001C as an example, Fortran language array a(1,1) and C language array a[0][0] both represent the value 1 stored at 0x0041F100; Fortran language array a(2,1) and C language array a[0][1] both represent the value 2 stored at 0x0041F100; the values stored in the remaining Fortran language arrays and C language arrays are taken as an example. Therefore, there is a corresponding relationship between the Fortran language array subscript (1,1) and the C language array subscript [0][0]; there is a corresponding relationship between the Fortran language array subscript (2,1) and the C language array subscript [0][1]; and the corresponding relationships between the remaining Fortran language array subscripts and C language array subscripts are similar.
[0056] In one implementation of the embodiment of the present invention, optionally, obtaining the relationship between the array identifier in the first language and the array identifier in the second language includes: if the array in the first language is a multidimensional array, determining the value range of the array subscript in the first language and the array subscript in the second language in each dimension; and determining the relationship between the array subscript in the first language and the array subscript in the second language based on the value range. For example, Figure 1dThe following is a schematic diagram showing the difference between the declaration of Fortran arrays and C arrays. For example, the array dimension is one-dimensional, the value range of the Fortran array is from a(-2) to a(3), and the value range of the C array is from a[0] to a[5]. When converting from Fortran to C, if a certain Fortran array is a(n), then the corresponding C array can be obtained as a(n-(-2)) based on the value ranges of the Fortran array and the C array; and so on. When it comes to three-dimensional arrays, the calculation is more complicated. If the Fortran array is defined as array(x1:x2,y1:y2,z1:z2), where x1:x2 is the value range of the Fortran array in the first dimension, y1:y2 is the value range of the Fortran array in the second dimension, and z1:z2 is the value range of the Fortran array in the third dimension, take a specific Fortran array element array(3,4,5), then the corresponding C array element is:
[0057] array((3-x1)+(4-y1)*(x2-x1+1)+(5-z1)*(x2-x1+1)*(y1-y2+1))
[0058] The above technical solution can intuitively represent the relationship between the array subscript of the first language and the array subscript of the second language by determining the relationship between the array subscript of the first language and the array subscript of the second language according to the value range of the array subscript of the first language and the array subscript of the second language in each dimension when the array in the first language is a multidimensional array, and can simplify the subsequent conversion of the array calculation expression language.
[0059] S120: defining the relationship by setting a function to form a predefined array code snippet.
[0060] Optionally, the setting function includes a macro definition function, or may be a function having the same function as the macro definition function.
[0061] In an optional implementation of the embodiment of the present invention, defining the relationship by setting a function includes: if the array of the first language is a multidimensional array, defining the relationship between the array subscript of the first language and the array subscript of the second language in each dimension by setting a function.
[0062] Specifically, when the array in the first language is a multidimensional array, the relationship between the array subscript in the first language and the array subscript in the second language on each dimension is defined respectively, and all the defined codes together constitute a predefined array code snippet.
[0063] Exemplarily, the first language is Fortran and the second language is C. If the Fortran array definition is array(x1:x2,y1:y2,z1:z2), and a specific Fortran array element is array(a,b,c), the corresponding C array element is: array+(a-x1)+(b-y1)*(x2-x1+1)+(c-z1)*(x2-x1+1)*(y1-y2+1). The relationship between the array identifiers of Fortran and C languages defined by macro definition functions can be referred to as follows:
[0064] #define array(a,b,c)((array+(a-x1)+(b-y1)*(x2-x1+1)+(c-z1)*(x2-x1+1)*(y1-y2+1))). If there are multiple arrays in the Fortran language, the array identification relationship can be defined through a macro definition function.
[0065] Therefore, by specifying the type of the setting function as a macro-defined function, the expression of the array can be made more concise, providing a basis for the subsequent conversion of the array calculation expression language.
[0066] S130: Converting the array calculation expression code snippet in the first language into an old version of the array calculation expression code snippet in the second language.
[0067] The old version array calculation expression code snippet in the second language may refer to an array calculation expression code snippet in the second language generated according to a conventional method.
[0068] For example, taking a three-dimensional array u(i, j, k) as an example, if the first language is Fortran and the second language is C, part of the array calculation expression code snippet of the second language generated according to the conventional method can be referred to as follows:
[0069]
[0070]
[0071] S140: Add the predefined array code snippet to an old version of an array calculation expression code snippet in a second language to generate a new version of an array calculation expression code snippet in the second language; wherein the array elements included in the array calculation expression code snippet are marked with array identifiers.
[0072] The new version of the array calculation expression code snippet in the second language may refer to the array calculation expression code snippet in the second language generated according to the technical solution of the embodiment of the present invention.
[0073] In an embodiment of the present invention, an array calculation expression code snippet may include a calculation expression of an array element, wherein the array is marked with an array identifier, and illustratively, the calculation expression of the array element may be u(i, j, k) = a + b + c. The predefined array code snippet may be added to an old version of the array calculation expression code snippet in the second language to form a new version of the array calculation expression code snippet in the second language, thereby avoiding the problem of lengthy code and poor readability caused by using conventional methods to generate the array calculation expression code snippet in the second language.
[0074] For example, taking a three-dimensional array u(i, j, k) as an example, if the first language is Fortran and the second language is C, part of the Fortran array calculation expression code snippet can be referred to as follows:
[0075] CUDAFortran
[0076] if……
[0077] …
[0078] u(i,j,k)=rdx(i,j)*(u(i,j,k)+dt / (delpc(i,j,k)+delpc(i+1,j,k))*\((gz(i,j,k+1)-gz(i+1, j,k))*(pf(i+1,j,k+1)-pf(i,j,k))\+(gz(i,j,k)-gz(i+1,j,k+1)*(pf(i,j,k+1)-pf(i+1,j,k);
[0079] …
[0080] After defining through macro definition function, part of the C language array calculation expression code snippet can be shown as follows:
[0081] #define u(i,j,k)(*(u+(i-isd)+(j-jsd)*(ied-isd+1)+(k-1)*(ied-isd+1)*(jed+1-jsd+1)))
[0082] #define pf(i,j,k)(*(pf+(i-isd)+(j-jsd)*(ied-isd+1)+(k-1)*(ied-isd+1)*(jed+1-jsd+1)))
[0083] #define gz(i,j,k)(*(gz+(i-isd)+(j-jsd)*(ied-isd+1)+(k-1)*(ied-isd+1)*(jed+1-jsd+1)))
[0084] #define delp(i,j,k)(*(delp+(i-isd)+(j-jsd)*(ied-isd+1)+(k-1)*(ied-isd+1)*(jed+1-jsd+1)))
[0085] #define rdx(i,j)(*(rdx+(i-isd)+(j-jsd)*(ied-isd+1)))
[0086] If……
[0087] …
[0088] u(i,j,k)=rdx(i,j)*(u(i,j,k)+dt / (delpc(i,j,k)+delpc(i+1,j,k))*\((gz(i,j,k+1)-gz(i+1, j,k))*(pf(i+1,j,k+1)-pf(i,j,k))\+(gz(i,j,k)-gz(i+1,j,k+1)*(pf(i,j,k+1)-pf(i+1,j,k);
[0089] …
[0090] It can be seen that by converting the computational expression language in the above manner, the converted code snippet has a high degree of similarity with the code snippet before the conversion, which can simplify the cumbersome array expression, increase the readability of the program, and improve the programming efficiency of the staff.
[0091] The CUDA C code snippet in the related art usually directly uses the "(i-isd)+(j-jsd)*(ied-isd+1)+(k-1)*(ied-isd+1)*(jed+1-jsd+1)" in the predefined array code snippet to express i, j, k in the u(i,j,k) calculation expression. The code snippet is long and has poor readability. The related art uses a class to define an array identifier, that is, a code snippet is formed through a class definition, and the class code snippet needs to be called to complete the calculation. For a three-dimensional array or a two-dimensional array, multiple classes need to be defined, which is inefficient. The method of using a template class to define an array subscript still requires additional code, and the calculation efficiency is low. The methods provided by the embodiments of the present invention can overcome the defects in the related art, increase the readability and accuracy of the program, improve the calculation speed, and improve the programming efficiency.
[0092] The technical solution of the embodiment of the present invention defines the relationship between the array identifier of the first language and the array identifier of the second language by using a setting function, generates a predefined array code snippet, then converts the array calculation expression code snippet of the first language into an old version of the array calculation expression code snippet of the second language, and adds the predefined array code snippet to the old version of the array calculation expression code snippet of the second language to generate a new version of the array calculation expression code snippet of the second language, thereby increasing the readability of the program and improving the programming efficiency of the staff.
[0093] Figure 2 A flowchart of a method for converting an array calculation expression language provided in an embodiment of the present invention. In this embodiment, optionally, it also includes: running the array calculation expression code snippet of the first language, determining the numerical value corresponding to the calculation expression of the array as the first numerical value; running the array calculation expression code snippet of the second language, determining the numerical value corresponding to the calculation expression of the array as the second numerical value; if the first numerical value and the second numerical value are the same, judging that the array calculation expression code snippet of the second language is correct.
[0094] Optionally, the method further includes: if the first value and the second value are different, determining that the calculation expression code snippet of the array in the second language is wrong; and returning an operation of obtaining the relationship between the array identifier in the first language and the array identifier in the second language.
[0095] like Figure 2 As shown, a method for converting an array computing expression language provided by an embodiment of the present invention includes the following specific steps:
[0096] S210: Obtain the relationship between the array identifier of the first language and the array identifier of the second language.
[0097] S220: Define the relationship by setting a function to form a predefined array code snippet.
[0098] S230: Converting the array calculation expression code snippet in the first language into an old version of the array calculation expression code snippet in the second language.
[0099] S240: Add the predefined array code snippet to the old version array calculation expression code snippet in the second language to generate a new version array calculation expression code snippet in the second language; wherein the array elements included in the array calculation expression code snippet are marked with array identifiers.
[0100] S250: Run the array calculation expression code fragment of the first language to determine a numerical value corresponding to the array calculation expression as a first numerical value.
[0101] The first value may refer to a value obtained by running the array calculation expression code snippet of the first language. For example, after running the array calculation expression code snippet of the first language, u(i, j, k)=6 is obtained, and 6 is the first value.
[0102] S260: Run the calculation expression code snippet of the new version array of the second language, and determine the numerical value corresponding to the calculation expression of the array as the second numerical value.
[0103] The second value may refer to a value obtained by running the new version array calculation expression code snippet of the second language. For example, after running the new version array calculation expression code snippet of the second language, u(i,j,k)=6 is obtained, and 6 is the second value.
[0104] S260: Determine whether the first value and the second value are the same. If yes, execute S270; if no, execute S280.
[0105] S270: Determine whether the calculation expression code snippet of the new version array of the second language is correct.
[0106] Specifically, if the first numerical value and the second numerical value are the same, it proves that the numerical value corresponding to the second language array obtained by running the calculation expression code snippet of the new version array of the second language is the same as the numerical value corresponding to the first language array obtained by running the calculation expression code snippet of the array of the first language, that is, the calculation expression code snippet of the new version array of the second language is correct.
[0107] S280: Determine whether the calculation expression code snippet of the new version array of the second language is wrong, and return to execute S210.
[0108] Specifically, if the first value and the second value are not the same, it proves that the value corresponding to the second language array obtained by running the calculation expression code snippet of the new version array of the second language is different from the value corresponding to the first language array obtained by running the calculation expression code snippet of the array of the first language, that is, the calculation expression code snippet of the new version array of the second language is wrong. It is necessary to re-acquire the relationship between the array identifier of the first language and the array identifier of the second language, and continue to execute the remaining steps until the first value and the second value are the same.
[0109] The technical solution of the embodiment of the present invention defines the relationship between the array identifier of the first language and the array identifier of the second language by using a setting function to generate a predefined array code snippet, then converts the array calculation expression code snippet of the first language into an old version of the array calculation expression code snippet of the second language, and adds the predefined array code snippet to the old version of the array calculation expression code snippet of the second language to generate a new version of the array calculation expression code snippet of the second language, and uses the case where the first value and the second value are the same as the basis for judging whether the calculation expression code snippet of the new version of the second language is correct, and uses the case where the first value and the second value are different as the basis for judging whether the calculation expression code snippet of the new version of the second language is wrong, so that the conversion method of the array calculation expression language is more perfect, solves the problem that the converted language readability is poor and the calculation speed is reduced due to the need for additional code in the prior art during the transcoding process, and achieves the effect of increasing the readability of the program and improving programming efficiency.
[0110] Figure 3 The schematic diagram of the structure of a device for converting an array computing expression language provided in an embodiment of the present invention is a device that can execute the method for converting an array computing expression language involved in the above embodiments. The device can be implemented in software and / or hardware, such as Figure 3 As shown, the array computing expression language conversion device specifically includes: an acquisition module 310, a definition module 320, a code conversion module 330, and an addition module 340.
[0111] The acquisition module 310 is used to acquire the relationship between the array identifier of the first language and the array identifier of the second language;
[0112] A definition module 320, configured to define the relationship by setting a function to form a predefined array code snippet;
[0113] A code conversion module 330, used to convert the array calculation expression code snippet in the first language into an old version of the array calculation expression code snippet in the second language;
[0114] The adding module 340 is used to add the predefined array code snippet to the old version array calculation expression code snippet in the second language to generate a new version array calculation expression code snippet in the second language; wherein the array elements contained in the array calculation expression code snippet are marked with array identifiers.
[0115] The technical solution of the embodiment of the present invention defines the relationship between the array identifier of the first language and the array identifier of the second language by using a setting function, generates a predefined array code snippet, then converts the array calculation expression code snippet of the first language into an old version of the array calculation expression code snippet of the second language, and adds the predefined array code snippet to the old version of the array calculation expression code snippet of the second language to generate a new version of the array calculation expression code snippet of the second language, thereby solving the problems of poor readability of the converted language and reduced computing speed due to the need for additional code that are prone to occur during the transcoding process in the prior art, thereby achieving the effect of increasing the readability of the program and improving programming efficiency.
[0116] Optionally, the acquisition module 310 can be specifically used to, if the array in the first language is a multidimensional array, determine the value range of the array subscript in the first language and the array subscript in the second language in each dimension; and determine the relationship between the array subscript in the first language and the array subscript in the second language based on the value range.
[0117] Optionally, the definition module 320 may be specifically configured to define the relationship between the array subscript of the first language and the array subscript of the second language in each dimension by setting a function if the array of the first language is a multi-dimensional array.
[0118] Optionally, the setting function includes a macro definition function.
[0119] Optionally, the conversion device for the array calculation expression language may also include a first judgment module, which is specifically used to run the array calculation expression code snippet of the first language to determine the numerical value corresponding to the array calculation expression as the first numerical value; run the array calculation expression code snippet of the second language to determine the numerical value corresponding to the array calculation expression as the second numerical value; if the first numerical value and the second numerical value are the same, it is judged that the array calculation expression code snippet of the second language is correct.
[0120] Optionally, the conversion device for the array calculation expression language may also include a second judgment module, which is specifically used to judge that the calculation expression code snippet of the new version of the array in the second language is wrong if the first value and the second value are different; and return an operation of obtaining the relationship between the array identifier of the first language and the array identifier of the second language.
[0121] Optionally, the first language includes Fortran language, and the second language includes C language.
[0122] The array computing expression language conversion device provided in the embodiment of the present invention can execute the array computing expression language conversion method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0123] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention is shown in FIG. Figure 4 As shown, the electronic device includes a processor 410, a memory 420, an input device 430, and an output device 440; the number of the processor 410 in the electronic device can be one or more. Figure 4 A processor 410 is taken as an example; the processor 410, the memory 420, the input device 430 and the output device 440 in the electronic device can be connected via a bus or other means. Figure 4 The example of connecting through bus is taken in the following.
[0124] The memory 420, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the conversion method of the array computing expression language in the embodiment of the present invention (for example, the acquisition module 310, the definition module 320, the code conversion module 330 and the addition module 340 in the conversion device of the array computing expression language). The processor 410 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 420, that is, realizes the conversion method of the array computing expression language mentioned above.
[0125] The memory 420 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 420 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 420 may further include a memory remotely arranged relative to the processor 410, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0126] The input device 430 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the electronic device. The output device 440 may include a display device such as a display screen.
[0127] An embodiment of the present invention further provides a storage medium containing computer executable instructions, wherein the computer executable instructions are used to execute a method for converting an array calculation expression language when executed by a computer processor, the method comprising:
[0128] Get the relationship between the array identifier of the first language and the array identifier of the second language;
[0129] The relationship is defined by setting a function to form a predefined array code snippet;
[0130] Convert the array calculation expression code snippet of the first language into the old version of the array calculation expression code snippet of the second language;
[0131] The predefined array code snippet is added to an old version of an array calculation expression code snippet in a second language to generate a new version of an array calculation expression code snippet in the second language; wherein the array elements contained in the array calculation expression code snippet are marked with array identifiers.
[0132] Of course, the storage medium containing computer executable instructions provided by an embodiment of the present invention is not limited to the method operations described above, and can also execute related operations in the array calculation expression language conversion method provided by any embodiment of the present invention.
[0133] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0134] It is worth noting that in the embodiment of the conversion device of the above-mentioned array calculation expression language, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0135] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for converting an array computing expression language, characterized in that: include: Get the relationship between the array identifier of the first language and the array identifier of the second language; The relationship is defined by setting a function to form a predefined array code snippet; Convert the array calculation expression code snippet of the first language into the old version of the array calculation expression code snippet of the second language; Adding the predefined array code snippet to an old version of an array calculation expression code snippet in a second language to generate a new version of an array calculation expression code snippet in the second language; wherein the array elements contained in the array calculation expression code snippet are marked with array identifiers; The acquiring the relationship between the array identifier of the first language and the array identifier of the second language includes: If the array in the first language is a multidimensional array, determining a value range of the array subscript in the first language and the array subscript in the second language in each dimension; The relationship between the array subscript of the first language and the array subscript of the second language is determined based on the value range.
2. The method according to claim 1, characterized in that Defining the relationship by setting a function includes: If the array in the first language is a multi-dimensional array, a relationship between the array subscript in the first language and the array subscript in the second language in each dimension is defined by setting a function.
3. The method according to claim 2, characterized in that The setting function includes a macro definition function.
4. The method according to claim 1, characterized in that: Also includes: Run the array calculation expression code snippet in the first language to determine a numerical value corresponding to the array calculation expression as a first numerical value; Run the calculation expression code snippet of the new version of the array in the second language, and determine a numerical value corresponding to the calculation expression of the array as a second numerical value; If the first value is the same as the second value, it is determined that the calculation expression code snippet of the array in the second language is correct.
5. The method according to claim 4, characterized in that Also includes: If the first value and the second value are different, determining that the calculation expression code snippet of the new version array of the second language is wrong; Returns an operation that gets the relationship of an array identifier of a first language to an array identifier of a second language.
6. The method according to any one of claims 1 to 5, characterized in that: The first language includes Fortran language, and the second language includes C language.
7. A conversion device for array computing expression language, characterized in that: include: An acquisition module, used for acquiring the relationship between the array identifier of the first language and the array identifier of the second language; A definition module, used for defining the relationship by setting a function to form a predefined array code snippet; A code conversion module, used for converting an array calculation expression code snippet in a first language into an old version of an array calculation expression code snippet in a second language; An adding module is used to add the predefined array code snippet to the old version array calculation expression code snippet in the second language to generate a new version array calculation expression code snippet in the second language; wherein the array elements contained in the array calculation expression code snippet are marked with array identifiers; The acquisition module is specifically used to, if the array in the first language is a multidimensional array, determine the value range of the array subscript in the first language and the array subscript in the second language in each dimension; and determine the relationship between the array subscript in the first language and the array subscript in the second language based on the value range.
8. An electronic device, characterized in that: include: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Code generation method, device, equipment and readable storage medium
CN110399124A
Array variable transformation system employing subscript table mapping to scalar loop indices
US5485619A