CN108681486B - Optimal thread number calculation method and device - Google Patents

Optimal thread number calculation method and device Download PDF

Info

Publication number
CN108681486B
CN108681486B CN201810478395.4A CN201810478395A CN108681486B CN 108681486 B CN108681486 B CN 108681486B CN 201810478395 A CN201810478395 A CN 201810478395A CN 108681486 B CN108681486 B CN 108681486B
Authority
CN
China
Prior art keywords
thread
optimal
steps
time
obtaining
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810478395.4A
Other languages
Chinese (zh)
Other versions
CN108681486A (en
Inventor
何晓晔
熊皓辉
何山
袁术鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Communications Construction Co Ltd
Original Assignee
Chongqing Communications Construction Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chongqing Communications Construction Co Ltd filed Critical Chongqing Communications Construction Co Ltd
Priority to CN201810478395.4A priority Critical patent/CN108681486B/en
Publication of CN108681486A publication Critical patent/CN108681486A/en
Application granted granted Critical
Publication of CN108681486B publication Critical patent/CN108681486B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5061Partitioning or combining of resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Complex Calculations (AREA)

Abstract

The embodiment of the invention provides a method and a device for solving the optimal thread quantity, and relates to the technical field of data processing. The method is applied to optimizing the number of threads, and comprises the following steps: obtaining thread switch penalty for each stepConsumption ci(ii) a According to the thread loss c of each stepiTime spent by a single thread tiCalculating the relation with the total step time consumption T to obtain the optimal thread number n of each stepi. According to the thread loss c of each stepiTime spent by a single thread tiThe optimal thread number of each step is obtained according to the relation with the total step time consumption T, so that the thread number can be automatically distributed, the running time of each step is reduced, the conversion time consumption is reduced, and the efficiency is improved.

Description

Optimal thread number calculation method and device
Technical Field
The invention relates to the technical field of data processing, in particular to a method and a device for solving the optimal thread quantity.
Background
In the prior art, when data is processed, a plurality of conversion processes are included, each conversion process includes a plurality of steps, the steps are generally executed in sequence through certain logic, each step can independently enable one thread by default, each step is executed simultaneously, and if a part of data processed by a first step is directly transmitted to a next step for processing. During processing conversion, single-thread processing can be performed on each step or the number of threads can be manually added, but the resource is unreasonably used due to different complexity of the steps, and the whole process is blocked due to the complex steps.
Disclosure of Invention
In view of this, an object of the embodiments of the present invention is to provide a method and an apparatus for obtaining an optimal thread number, so as to achieve the purpose of reducing the time consumption of the conversion process by optimizing the thread number of the steps.
The technical scheme adopted by the invention is as follows:
the embodiment of the invention provides a method for solving the optimal thread quantity, which is applied to the optimal thread quantity and comprises the following steps: obtaining thread switching loss c of each stepi(ii) a According to the thread loss c of each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure GDA0002572735760000021
calculating to obtain the optimal thread number n of each stepi. Wherein i is more than or equal to 1, and m is the total number of the steps. Wherein the obtaining of the thread switching loss c of each stepiComprises the following steps: randomly changing the number of threads of each step, and operating and acquiring the operation time consumption of the steps;
repeating the random change of the number of the threads of the steps, and acquiring multiple groups of running time-consuming data with different thread numbers of each step;
obtaining the thread switching consumption c of each step by carrying out linear regression calculation on multiple groups of running time consumption data with different thread quantities of each stepi
Further, the method further comprises: acquiring step time t of single-thread operation of each stepi
Further, the method further comprises: are respectively paired with niRounding up or down and substituting into the equation
Figure GDA0002572735760000022
And (4) calculating, wherein when the obtained T is minimum, the corresponding rounding value is the optimal thread number.
The invention provides a device for solving the optimal thread quantity, which comprises: an obtaining module for obtaining the thread switching loss c of each stepi(ii) a A calculation module for calculating the thread loss c according to each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure GDA0002572735760000023
calculating to obtain the optimal thread number n of each stepi. Wherein i is more than or equal to 1, and m is the total number of the steps.
The acquisition module includes: a configuration unit for randomly changing the number of threads of each step and operating the steps; the timing unit is used for acquiring the running time of the step; the configuration unit is further configured to repeat the number of threads of the randomly changed steps, and the timing unit is configured to obtain multiple sets of running time-consuming data of different thread numbers of each step.
Further, the obtaining module further comprises a first calculating unit, and the first calculating unit is configured to obtain the thread switching consumption c of each step by performing linear regression calculation on multiple sets of running time consumption data of different thread quantities of each stepi
Further, the timing unit is further configured to obtain a step time consumption t of single-thread operation of each stepi
Further, the calculating module comprises a second calculating unit for respectively calculating niRounding up or down and substituting into the equation
Figure GDA0002572735760000031
And (4) performing middle calculation, wherein the rounding value corresponding to the minimum T is the optimal thread number.
Compared with the prior art, the invention has the following beneficial effects:
the embodiment of the invention provides a method and a device for solving the optimal thread quantity, wherein the method is applied to the optimal thread quantity and comprises the following steps: obtaining thread switching loss c of each stepi(ii) a According to the thread loss c of each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure GDA0002572735760000032
calculating to obtain the optimal thread number n of each stepi. According to the thread loss c of each stepiTime spent by a single thread tiThe optimal thread number of each step is obtained according to the relation with the total step time consumption T, so that the thread number can be automatically distributed, the running time of each step is reduced, the conversion time consumption is reduced, and the efficiency is improved.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
Fig. 1 shows a schematic diagram of an electronic device provided by the present invention.
Fig. 2 shows a flowchart of the optimal thread number finding method.
Fig. 3 shows a flow chart of sub-steps of step S20.
Fig. 4 is a functional block diagram of an optimal thread number calculating device according to an embodiment of the present invention.
Fig. 5 shows a functional unit diagram of the acquisition module.
Fig. 6 shows a functional unit diagram of the derivation module.
Icon: 100-an electronic device; 101-a memory; 102-a memory controller; 103-a processor; 104-peripheral interfaces; 105-a display unit; 106-input-output unit; 200-an optimal thread number solving device; 210-an obtaining module; 211-a timing unit; 212-a configuration unit; 213-a first calculation unit; 220-an obtaining module; 221-a second calculation unit; 222-third calculation unit.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
In the description of the present invention, it should also be noted that relational terms such as first and second, and the like, may be used solely herein to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. The terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element. The specific meanings of the above terms in the present invention can be understood in specific cases to those skilled in the art.
Some embodiments of the invention are described in detail below with reference to the accompanying drawings. The embodiments described below and the features of the embodiments can be combined with each other without conflict.
Fig. 1 is a block diagram of an electronic device 100 according to a preferred embodiment of the invention. The electronic device 100 may be a desktop computer, a notebook computer, a tablet computer, a smart phone, a Personal Digital Assistant (PDA), or the like. The electronic device 100 includes an optimal thread number obtaining device 200, a memory 101, a memory controller 102, a processor 103, a peripheral interface 104, a display unit 105, and an input/output unit 106.
The memory 101, the memory controller 102, the processor 103, the peripheral interface 104, the display unit 105, and the input/output unit 106 are electrically connected to each other directly or indirectly to implement data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines. The optimal thread number obtaining device 200 and the multiplicative watermark extracting device 300 each include at least one software functional module that can be stored in the memory 101 in the form of software or firmware (firmware) or solidified in an Operating System (OS) of the electronic device 100. The processor 103 is configured to execute an executable module stored in the memory 101, such as a software functional module or a computer program included in the optimal thread count determination apparatus 200.
The Memory 101 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like. The memory 101 is used for storing a program, and the processor 103 executes the program after receiving an execution instruction, and the method executed by the process-defined server disclosed by any embodiment of the invention can be applied to the processor 103, or implemented by the processor 103.
The processor 103 may be an integrated circuit chip having signal processing capabilities. The Processor 103 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor 103 may be any conventional processor 103 or the like.
The peripheral interface 104 couples various input/output devices to the processor 103 as well as to the memory 101. In some embodiments, the peripheral interface 104, the processor 103, and the memory controller 102 may be implemented in a single chip. In other examples, they may be implemented separately from the individual chips.
The display unit 105 provides an interactive interface (e.g., a user interface) between the electronic device 100 and a user or for displaying image data to a user reference. In this embodiment, the display unit 105 may be a liquid crystal display or a touch display. In the case of a touch display, the display can be a capacitive touch screen or a resistive touch screen, which supports single-point and multi-point touch operations. Supporting single-point and multi-point touch operations means that the touch display can sense touch operations simultaneously generated from one or more positions on the touch display, and the sensed touch operations are sent to the processor 103 for calculation and processing.
The input/output unit 106 is used for providing input data for a user to realize the interaction of the user with the electronic device 100. For example, the number of threads per step is set in advance, or the number of steps is set to acquire a plurality of sets of data, or the like. The input/output unit 106 may be, but is not limited to, a mouse, a keyboard, etc., and the keyboard may be a virtual keyboard.
First embodiment
This embodiment provides a method for determining the optimal number of threads, which is determined by the thread loss c of each stepiTime spent by a single thread tiAnd the optimal thread number of each step is obtained according to the relation with the total step time consumption T, so that the total step time consumption T is minimum, and the conversion time consumption can be reduced.
Referring to fig. 2, fig. 2 is a flowchart illustrating a method for determining an optimal thread count according to the present embodiment. The optimal thread number calculation method includes steps S10-S30.
Step S10: acquiring step time t of single-thread operation of each stepi
And (4) running each step in a single thread mode, running each step of the whole conversion, and setting each step to be run in a single thread mode. Recording the operation starting time of each step and the operation ending time of each step, and according to the operation of each stepAcquiring step time t of each step operation according to the line starting time and the operation ending timei
Step S20: obtaining the thread loss c of each stepi
The steps are set to be in multi-thread operation, each time one thread is operated, the other thread needs to be switched, and the thread operation time is changed into thread loss. When a step includes multiple threads, thread wear includes wear of multiple thread switches.
According to the number m of the steps of conversion, the single thread time consumption t of each stepiPer step switching thread loss ciThe number of threads n after each step is optimizediAnd the optimized theoretical total time T has the following relation:
Figure GDA0002572735760000091
wherein i is more than or equal to 1
After conversion, the following can be obtained:
Figure GDA0002572735760000092
namely:
Figure GDA0002572735760000093
that is, the thread switching loss time is the theoretical total time consumption — the time consumption after the theoretical optimization. The above equation can be regarded as a function of a multiple linear regression, which can be solved by a least square equation. The formula is as follows:
Figure GDA0002572735760000101
wherein the content of the first and second substances,
Figure GDA0002572735760000102
then c isiCorresponding to b in the formulap
Figure GDA0002572735760000103
Corresponding to x in the formula, and is,
Figure GDA0002572735760000104
corresponding to y in the formula.
In this embodiment, c is solved by the least square methodiReferring to fig. 3, step S20 includes the following sub-steps: step S201 to step S203.
Step S201: and randomly changing the number of threads of each step, and running and acquiring the running time of the steps.
Step S202: and repeating the random change of the number of the threads of the steps, and acquiring multiple groups of running time-consuming data with different thread numbers of each step. The number of data sets needs to be greater than the number of steps.
Step S203: obtaining the thread switching consumption c of each step by carrying out linear regression calculation on multiple groups of running time consumption data with different thread quantities of each stepi
And converting the number of threads of each step in the multiple groups of data into a two-dimensional array A [ i ] [ j ], wherein the number of dimensions i is the number of groups of data, the number of dimensions j is the number of steps, and the sequence of each row of data corresponds to the sequence of each step. And (3) subtracting the quotient of the single-thread running time and the thread number in each step from the actual running time to convert the quotient into a two-dimensional array B [ i ] [ j ], wherein the number of i dimensions is the number of samples, and the number of j dimensions is equal to 1.
Operations that replace matrices with two-dimensional arrays of programs, such as: 1) a
Figure GDA0002572735760000112
The transpose of the matrix can be regarded as the dimension conversion of the two-dimensional array A.
Firstly, traversing the row number for (int i ═ 0; i < a.length; i + +) of the array A, then traversing the column number for (int j ═ 0; j < a [ i ]. length; j + +), and finally assigning the value of the array A [ i ] [ j ] to a new array C [ i ] [ j ], namely C [ j ] [ i ] }.
Multiplication of two matrices
Figure GDA0002572735760000113
It can be seen that the array C is multiplied by the array A, and the row for of the array C is traversed first (int i ═ 0; i;, i;)<C, length; i + +, and then traversing the array A row number for (int j equals 0; j is a function of<A[0]Length; j + +, then traverse the column number for of array C (int k ═ 0; k is a radical of<C[0]Length; k + +, the value of i row and j column of the new array D is the sum of i row and j column of the array C multiplied by j column and j column of the array A, i.e. D [ i +)][j]+=C[i][k]*A[k][j]。
The array is operated by a least square method formula, and finally the thread switching loss c of each step can be calculated1、c2、c3…cm
Step S30: according to the thread loss c of each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure GDA0002572735760000111
calculating to obtain the optimal thread number n of each stepi
For a conversion comprising multiple steps, the total time consumption of the conversion is the sum of the time consumption of each step. Therefore, the time consumption of each step is only required to be minimum, and the aim of minimizing the time consumption of the whole conversion can be fulfilled.
For a single step, the total time consumption is T, the single thread time consumption is T, the thread consumption of the step is c, and the number of threads is n. The total time consumption T is related to the time consumption of a single thread as T, the thread consumption c of the step and the number of threads n as follows:
Figure GDA0002572735760000121
the derivation of the above formula can be obtained,
Figure GDA0002572735760000122
that is, when
Figure GDA0002572735760000123
T has a minimum value. That is, for a single step, when
Figure GDA0002572735760000124
Time consumption of step TiWith a minimum value, each step takes the least time, at which point the transition takes the least time.
Step S40: are respectively paired with niRounding up or down and substituting into the equation
Figure GDA0002572735760000125
And (4) calculating, wherein when the obtained T is minimum, the corresponding rounding value is the optimal thread number.
Figure GDA0002572735760000126
When T has a minimum value, but niIs the number of threads, the value of which is positive integer, and the n obtainediThe value is rounded up or down, and the rounded value is substituted into the formula
Figure GDA0002572735760000131
And (4) calculating, wherein when the obtained T is minimum, the corresponding integer value is the optimal thread number.
Second embodiment
The present embodiment provides an optimal thread number obtaining device 200, and the optimal thread number obtaining device 200 is applied to the electronic device, and is used for implementing the optimal thread number obtaining method described in the first embodiment.
It should be noted that the basic principle of the optimal thread number obtaining device 200 provided in the present embodiment is substantially the same as that of the optimal thread number obtaining method provided in the first embodiment, and for a brief description, the present embodiment does not describe this in detail, and the present embodiment does not describe details, please refer to relevant contents in the first embodiment.
Referring to fig. 4, fig. 4 is a schematic diagram illustrating functional modules of the apparatus 200 for determining an optimal thread count according to the present embodiment.
The optimal thread number calculation device 200 includes an obtaining module 210 and a calculating module 220.
Wherein the obtaining module 210 is configured to obtain thread switching of each stepLoss ciAnd the single-thread running time t of each stepi
Preferably, referring to fig. 5, the obtaining module 210 includes a timing unit 211, a configuration unit 212, and a first calculating unit 213.
The timing unit 211 is further configured to obtain a step time t of single-thread operation of each stepi. And (4) running each step in a single thread mode, running each step of the whole conversion, and setting each step to be run in a single thread mode. Recording the operation starting time of each step and the operation ending time of each step, and acquiring the step consumed time t of the operation of each step according to the operation starting time and the operation ending time of each stepi
A timing unit 211, configured to obtain operation time consumption of the step; the configuration unit 212 is further configured to repeat the thread number of the step randomly, and the timing unit 211 is configured to obtain multiple sets of running time consumption data of different thread numbers of each step. The steps are set to be in multi-thread operation, each time one thread is operated, the other thread needs to be switched, and the thread operation time is changed into thread loss. When a step includes multiple threads, thread wear includes wear of multiple thread switches.
The first calculating unit 213 is configured to obtain the thread switching consumption c of each step by performing linear regression calculation on multiple sets of running time consumption data of different thread quantities of each stepi
The calculating module 220 is used for calculating the thread loss c according to each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure GDA0002572735760000141
calculating to obtain the optimal thread number n of each stepi
Referring to fig. 6, the obtaining module 220 includes a second calculating unit 221 and a third calculating unit 222, wherein the third calculating unit 222 is used for calculating the thread loss c according to each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure GDA0002572735760000142
calculating to obtain the optimal thread number n of each stepi
The second calculating units 221 are used for respectively corresponding to niRounding up or down and substituting into the equation
Figure GDA0002572735760000151
And (4) performing middle calculation, wherein the rounding value corresponding to the minimum T is the optimal thread number.
The second calculation units 221 respectively perform the calculation on the obtained niValues rounded up or down and substituted into the equation
Figure GDA0002572735760000152
And (4) calculating, wherein when the obtained T is minimum, the corresponding rounding value is the optimal thread number.
Figure GDA0002572735760000153
When T has a minimum value, but niIs the number of threads, the value of which is positive integer, and the n obtainediThe value is rounded up or down, and the rounded value is substituted into the formula
Figure GDA0002572735760000154
And (4) calculating, wherein when the obtained T is minimum, the corresponding integer value is the optimal thread number.
In summary, an embodiment of the present invention provides a method and an apparatus for calculating an optimal thread number, where the method is applied to optimize the thread number, and the method includes: obtaining thread switching loss c of each stepi(ii) a According to the thread loss c of each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure GDA0002572735760000155
calculating to obtain the optimal thread number n of each stepi. According to the thread loss c of each stepiTime spent by a single thread tiAnd step (a) areThe optimal thread number of each step is obtained through the relation of the time consumption T, so that the thread number can be automatically distributed, the running time of each step is reduced, the time consumption of conversion is reduced, and the conversion efficiency is improved.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (6)

1. An optimal thread number obtaining method is applied to optimizing the thread number, and the method comprises the following steps:
obtaining thread switching loss c of each stepi
According to the thread loss c of each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure FDA0002572735750000011
calculating to obtain the optimal thread number n of each stepi(ii) a Wherein i is more than or equal to 1, and m is the total number of the steps;
wherein the obtaining of the thread switching loss c of each stepiComprises the following steps: randomly changing the number of threads of each step, and operating and acquiring the operation time consumption of the steps;
repeating the random change of the number of the threads of the steps, and acquiring multiple groups of running time-consuming data with different thread numbers of each step;
obtaining the thread switching consumption c of each step by carrying out linear regression calculation on multiple groups of running time consumption data with different thread quantities of each stepi
2. The method of claim 1, wherein the method further comprises:
acquiring step time t of single-thread operation of each stepi
3. The method of claim 1, wherein the method further comprises:
are respectively paired with niRounding up or down and substituting into the equation
Figure FDA0002572735750000021
And (4) calculating, wherein when the obtained T is minimum, the corresponding rounding value is the optimal thread number.
4. An optimal thread number calculation device, wherein the device is configured to implement the optimal thread number calculation method according to any one of claims 1 to 3, and the device comprises:
an obtaining module for obtaining the thread switching loss c of each stepi
A calculation module for calculating the thread loss c according to each stepiTime spent by a single thread tiRelation to total step elapsed time T:
Figure FDA0002572735750000022
calculating to obtain the optimal thread number n of each stepi(ii) a Wherein i is more than or equal to 1, and m is the total number of the steps;
the acquisition module includes:
a configuration unit for randomly changing the number of threads of each step and operating the steps;
the timing unit is used for acquiring the running time of the step;
the configuration unit is further used for repeatedly and randomly changing the number of threads of the steps, and the timing unit is used for acquiring multiple groups of running time-consuming data of different thread numbers of each step;
the obtaining module further comprises a first calculating unit, and the first calculating unit is used for obtaining the thread switching consumption c of each step by performing linear regression calculation on multiple groups of running time consumption data with different thread quantities of each stepi
5. The optimal thread count calculation apparatus according to claim 4, wherein the timing unit is further configured to obtain a step time t of single-threaded operation of each stepi
6. The optimal thread count derivation apparatus according to claim 4, wherein said derivation module comprisesA second calculation unit for respectively pairing niRounding up or down and substituting into the equation
Figure FDA0002572735750000031
And (4) performing middle calculation, wherein the rounding value corresponding to the minimum T is the optimal thread number.
CN201810478395.4A 2018-05-17 2018-05-17 Optimal thread number calculation method and device Active CN108681486B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810478395.4A CN108681486B (en) 2018-05-17 2018-05-17 Optimal thread number calculation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810478395.4A CN108681486B (en) 2018-05-17 2018-05-17 Optimal thread number calculation method and device

Publications (2)

Publication Number Publication Date
CN108681486A CN108681486A (en) 2018-10-19
CN108681486B true CN108681486B (en) 2020-08-28

Family

ID=63806903

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810478395.4A Active CN108681486B (en) 2018-05-17 2018-05-17 Optimal thread number calculation method and device

Country Status (1)

Country Link
CN (1) CN108681486B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11321123B2 (en) * 2019-11-21 2022-05-03 International Business Machines Corporation Determining an optimum number of threads to make available per core in a multi-core processor complex to executive tasks
CN116263707A (en) * 2021-12-15 2023-06-16 北京字跳网络技术有限公司 Task execution method, device, equipment and medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104794006A (en) * 2010-02-23 2015-07-22 富士通株式会社 Multi-core processor system, interrupt routine and interrupt method

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7774784B2 (en) * 2005-03-17 2010-08-10 Microsoft Corporation Determining an actual amount of time a processor consumes in executing a portion of code
US9465632B2 (en) * 2012-02-04 2016-10-11 Global Supercomputing Corporation Parallel hardware hypervisor for virtualizing application-specific supercomputers
CN104657219B (en) * 2015-02-27 2017-10-20 西安交通大学 A kind of application program threads number dynamic adjusting method being used under isomery many-core system

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104794006A (en) * 2010-02-23 2015-07-22 富士通株式会社 Multi-core processor system, interrupt routine and interrupt method

Also Published As

Publication number Publication date
CN108681486A (en) 2018-10-19

Similar Documents

Publication Publication Date Title
US8502785B2 (en) Generating gestures tailored to a hand resting on a surface
Slagter et al. An improved partitioning mechanism for optimizing massive data analysis using MapReduce
CN108681486B (en) Optimal thread number calculation method and device
KR20130029797A (en) Selecting alternate keyboard characters via motion input
CN107391090B (en) Multithreading execution method and device
CN108038894B (en) Animation creation method, animation creation device, electronic equipment and computer-readable storage medium
CN104765560A (en) Display control method
US20160139803A1 (en) Regional zooming virtual keyboards for accurate typing on small displays
US9753583B2 (en) Method of scanning touch panel and touch integrated circuit for performing the same
US20140137053A1 (en) Information Processing Method And Information Processing Device
US9513740B2 (en) Chip architecture in improve the sensing latency time in projected capacitance touch
US8887077B2 (en) Synchronized graphical and tabular performance data display
CN107037948B (en) Method and system for realizing list sliding
US20160048979A1 (en) Desktop management method and electronic device with desktop management function
US9529530B2 (en) Electronic device and gesture input method of item selection
TWI598748B (en) Electronic Device And Method For Correcting Character
CN112463227A (en) BIOS control method and system based on touch screen and touch screen control panel
Porter et al. Compiler-assisted scheduling for multi-instance GPUs
JP6496044B2 (en) Method and apparatus for displaying text input of a terminal device and terminal device
CN105373499B (en) The method and computer system of removal external equipment and non-transient readable medium
JP3236927U (en) Reciprocal multiplication key and electronic desk calculator
CN108491548A (en) Setting-out processing method based on map and device
CN107179873B (en) One-hand operation method and device based on application program interface
TWI511067B (en) Electronic apparatus and method for displaying product information thereof
US20150121379A1 (en) Information processing method and electronic apparatus

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant