A novel D2D–MEC method for enhanced computation capability in cellular networks

Device-to-device (D2D) communications and mobile edge computing (MEC) used to resolve traffic overload problems is a trend in the cellular network. By jointly considering the computation capability and the maximum delay, resource-constrained terminals offload parts of their computation-intensive tasks to one nearby device via a D2D connection or an edge server deployed at a base station via a cellular connection. In this paper, a novel method of cellular D2D–MEC system is proposed, which enables task offloading and resource allocation meanwhile improving the execution efficiency of each device with a low latency. We consider the partial offloading strategy and divide the task into local and remote computing, both of which can be executed in parallel through different computational modes. Instead of allocating system resources from a macroscopic view, we innovatively study both the task offloading strategy and the computing efficiency of each device from a microscopic perspective. By taking both task offloading policy and computation resource allocation into consideration, the optimization problem is formulated as that of maximized computing efficiency. As the formulated problem is a mixed-integer non-linear problem, we thus propose a two-phase heuristic algorithm by jointly considering helper selection and computation resources allocation. In the first phase, we obtain the suboptimal helper selection policy. In the second phase, the MEC computation resources allocation strategy is achieved. The proposed low complexity dichotomy algorithm (LCDA) is used to match the subtask-helper pair. The simulation results demonstrate the superiority of the proposed D2D-enhanced MEC system over some traditional D2D–MEC algorithms.

www.nature.com/scientificreports/ independent devices in the D2D-MEC system has not been considered. Besides, a binary offloading strategy is considered in most studies to execute tasks in the system. In the studies of partial offloading, either the highperformance helpers with a few tasks are ignored or the computing resources of devices and the edge server are neglected. Inspired by this, we integrate D2D communication with the MEC system and propose a novel D2D-MEC method. To facilitate our analysis, we make the following reasonable assumptions throughout this paper.
1. All devices in the network are linked to and can communicate with the edge server. Besides, devices can communicate with each other. Once the devices complete their tasks within the time limit, the remaining computing resources can be used to continue helping other devices, which is similar to 14 . Only if the devices fail to complete the tasks on time will they offload the tasks to the helper or the edge server. 2. Each device has a computationally intensive and time-sensitive task that needs to be completed within a certain time, which can be segmented. As the works in 41 , the task can be executed locally, offloaded to one of the helper devices nearby or executed by offloading to the edge server. When a task arrives, each device will first predict whether the local computing resources are sufficient to complete it within a specified delay based on its computational capability. If so, the task can be executed locally. Otherwise, according to the proposed algorithm, the incomplete part will be offloaded to the helper device or the edge server.

Ref. Purpose
Year Advantages Shortcomings 5 Minimizing the response delay of requests. 2020 A multi-server system is taken into consideration Regardless of the allocation of bandwidth 10 Maximizing the supported links. 2020 Considering resource allocation and power control together HetNet is not considered 14 Minimizing the time and financial cost for the users 2019 Taking into consideration the precedence-constrained subtasks The BS does not participate in the computing process 15 Reduce the computation cost. 2018 Facilitate flexible choices of task execution approaches Extra resources are needed to maintain socially motivated cooperation 16 Decrease the task execution delay and the energy consumption. 2018 The offloading scheme can meet a Nash equilibrium of the formulated game Only one mobile user updates its offloading decision in each decision slot 19 Maximizing the system utility by the improvement in QoE. 2017 Improve the QoE of each mobile device Without considering the maximize time latency 20 Minimizing the computation delay of local users. 2018 A device can offload its tasks to several nearby end devices Only one user is considered. 21 Achieve higher efficiency 2018 A new four levels of heterogeneous cloud is proposed. The new heterogeneous cloud is hard to deploy 23 Minimizing the overall energy consumption 2020 The tasks of each device can be offloaded to multihelper The network control factor is not explicitly formulated 25 Maximizing the number of executed tasks. 2019 The number of access devices has improved Only one BS is taken into consideration 27 Minimizing the energy cost 2020 MEC with cache-enabled D2D communications is proposed The complexity of the algorithm is high 28 Minimizing the energy consumption. 2018 Applying computation prediction at edge devices The adaptive offloading of computation tasks is not practical 29 Minimizing the energy consumption of equipments. 2017 Deals with the D2D crowd task assignment problem The energy-efficiency of the D2D clusters is not considered. 30 Minimizing the energy consumption of mobiledevices 2016 Computation resources of mobile devices can be shared through devices The network control factor is not explicitly formulated in the scheme 31 Minimizing the energy consumption for mobile devices 2019 Handle the continuous arrival tasks of mobile devices Communication overhead is neglected 32 Minimizing the energy consumption of the task execution 2020 The scheme is designed for devices with delay-sensitive tasks or low energy The fairness among devices is not considered 33 Minimizing energy consumption 2020 The long-term energy consumption in continuous time is minimized Only idle users can be helpers 34 Maximizing reductions in task completion time and energy consumption 2019 Users can improve the efficiency of task execution The performance discrepancy between multi-server is not considered 37 Minimizing execution latency and energy consumption 2018 The optimal tradeoff between execution latency and energy consumption The task execution relationship between devices is not considered 38 Minimizing the task computation latency and the energy consumption 2019 Social-motivated computation is used in the D2D-MEC system Did not specifically evaluate security metrics 40 Maximizing a utility defined based on delay and energy consumption 2019 Integrate caching into D2D-aided computing Networks Caching is conducted in an offline manner 41 Maximizing the computing profits of task publishers 2019 Utilizing the computing resources of idle devices to enhance computing capability Ignore the profits of the helper device 42 Improving energy efficiency in mobile computing 2018 A novel four-slot protocol is propose The simple evaluation topology included only two user equipment 43 Lowering www.nature.com/scientificreports/ 3. As the works in 39 , in the task execution process, the maximum time required by all devices is constant and equal, i.e., synchronous execution. Only when a task is completed and can the next be continued in execution simultaneously among devices. Asynchronous task processing deserves further investigation.
We adopt a partial offloading strategy and make full use of the computing resources within a specified delay, so as to improve the number of supported devices and their computing efficiency in the system. Since users tend to execute tasks through their own devices, a clustering algorithm is adopted to divide a task into two subtasks considering the users' computing capability. One subtask is executed locally, and the other is offloaded to a helper device or an edge server. LCDA is proposed to match the subtask-helper pair. Then, the system limitations are analyzed in terms of the size of the task, the tolerance time and the number of access devices. Besides, task execution, task offloading and computation resource allocation can be completed within the time constraints. Computing efficiency can be increased through the D2D-assisted MEC system effectively, and the computation resources in both the edge server and the devices are highly utilized in the system. The main contributions to this work are summarized as follows.
1. To improve the network capability and computing capability, we propose a collaborative D2D-assisted MEC system that supports multi-level task offloading and resource allocation. In particular, we divide the task into two subtasks through partial offloading, which can be separately executed locally and remotely, followed by the offloading decision of each device from the microscopic point of view instead of the previous task assignment from the macroscopic view. Finally, the computation resource allocation of the MEC server is given. The problem is proposed as a mixed-integer non-linear problem, which is resolved through a twophase heuristic algorithm. 2. To increase the number of access devices and achieve the maximum task execution capability, the LCDA algorithm is proposed to match the subtask-helper pair in the system. The MEC server guarantees that the remaining subtasks can be completed. The simulation results show that in different profiles (such as the number of devices, time constraints and the size of the intensive tasks), the algorithm has a superior performance with a lower time and space complexity, which effectively improves the computing capacity of the D2D-MEC system with time constraints. 3. To verify the practicability of the proposed model and the heuristic algorithm, we use improved greedy algorithm 41 , initial task assignment algorithm 25 , bipartite graph matching algorithm 14 and efficient delayaware offloading scheme 32 as the benchmark comparisons of the proposed algorithm. Compared with the four traditional D2D-MEC algorithms, the results corroborate the superior performance of the proposed scheme in the scenario with strict time constraints.
The remainders of this paper are organized as follows. The system model, problem formulation and problem solution are introduced in "Method" section. Simulation results are given in "Simulation results" section, and conclusions are given in "Conclusions" section.

Method
In this section, we introduce the D2D-enhanced MEC system, followed by the communication and computation model. The computation model is structured in the following three modes: Local execution mode, Local+D2D execution mode and Local+D2D+Edge execution mode. Then, depending on these three modes, we propose the optimization problem to find the solution to maximize the computational efficiency of the devices. Finally, three algorithms are utilized to solve this problem. Fig. 1, the D2D-MEC system consists of a base station(BS) equipped with an edge server and N mobile devices owned by some users. The devices are denoted by the set N = {1, 2, ..., N} , which contains Cluster 1 and Cluster 2. The devices represented by Cluster1 can complete tasks locally within the time constraints and provide help to other devices. Cluster2 represents a group of devices that can not complete tasks locally within the time delay and need to offload part of their tasks remotely. They require extra computing resources from other devices via a D2D connection or the MEC server via a cellular connection. Among them, the set of devices in Cluster1 and Cluster2 are defined as

D2D-MEC system model. As shown in
In Cluster1, Dev_a represents devices that cannot provide services to nearby devices via D2D connection, and Dev_b represents devices that assist adjacent devices in Cluster2, i.e., Dev_b is a helper. In Cluster2, Dev_c refers to devices in N 2 which need additional computing resources for task execution through D2D connection, and Dev_d refers to devices in N 3 that fail to match neighboring helpers but need to offload their tasks to the edge server. In this process, like the work in 39 , BS can get task size sequence information that the device (Cluster1) can provide through feedback and send the sequence information to the device(Cluster2) that needs help. Besides, BS can acquire the channel state information (CSI) of all devices via feedback, and the orthogonal frequency-division multiple access (OFDMA) method for channel access is adopted.
Communication model. Each device in N 2 ∪ N 3 is allocated one sub-channel for the cellular link or D2D link. Then we can denote B and N 0 as the bandwidth and the power of additive white Gaussian noise for each sub-channel respectively. If Device n chooses to offload its task remotely, using Shannon's formula, the maximum achievable transmission rate of the D2D connection or cellular link can be expressed as where P com n is the transmission power of one device to its nearby helper or the edge server, h is the channel gain, which is assumed to be known in each device and remains constant but may change from the boundary of each offloading period 45,46 . In addition, this paper considers that there are no objects and large buildings blocking radio waves in the first Fresnel region, so the LOS channel model is adopted. The notations used in this paper are summarized in Table 2.
(1) r = Blog 2 1 + P com n h N 0 The set/number of local computing devices The set/number of D2D computing devices The set/number of edge computing devices www.nature.com/scientificreports/ Computation model. For the computation model, we consider that each device n(n ∈ N ) has a computation task characterized by I n = {D n , App n ,t max n } . Here D n (in bits) is the data size of the task, App n is the processing density (in CPU cycles/bit), which depends on the computational complexity of the application, C n is the total number of CPU cycles required for computing D n which can be characterized by C n =D n App n and t max n is the maximum tolerable latency(in second). Device n can obtain the information about D n and App n , and they remain the same value within the time range t max n . Each device can execute its computation task locally or offload part of the task to one nearby helper device or the edge server. We denote A n = x n , y n , z n as the offloading decision of device n. Specifically, we have A n ={1, 0, 0} if device n can complete its task locally. We have A n ={1, 1, 0} if device n offloads some tasks to a D2D helper, and we have A n ={1, 0, 1} if device n chooses the edge server for remote execution. We can get 1 ≤ x n + y n + z n ≤ 2 , with x n , y n ∈ {0, 1}.
As depicted in Fig. 2, Dev_a, Dev_b, Dev_c and Dev_d correspond to Dev_a, Dev_b, Dev_c and Dev_d in Fig. 1 respectively. From the perspective of the utilization of computing resources, Dev_b in Fig. 2a provides additional computing resources for Dev_c in Fig. 2b, which increases the utilization of resources in Dev_b and enables the task of Dev_c to be completed within the required time. Besides, we use D dev b,c to represent the subtask that Dev_b would execute for Dev_c. The edge server in Fig. 2c provides additional computing resources for Dev_d in Fig. 2b. The edge server can handle a large number of tasks, which are also a factor affecting the processing of the edge server.
We next discuss the overhead of Local computing, Local+D2D computing and Local+D2D+Edge computing in terms of three aspects (delay analysis, energy consumption and computing efficiency).
Local computing. Local computing means that a device completes the task locally with its inherent computing capability within a specified time. The time taken by a local computing device is expressed as where f loc n represents the local computing capability of device n (in CPU cycles/s), and we use P loc n to represent the local processing power of device n (in watt). Energy consumption brought in task processing is mainly studied, so the inherent energy consumption brought by the chip structure is not considered here. The energy consumption can then be expressed as We define the computing efficiency(CE) of device n during t max n as the proportion of the task handled by the device to the task that could be executed with the inherent computation capacity of the device within this time range. In this way, the local CE can be expressed as Our goal is to enhance the CE of local execution devices, namely Dev_a and Dev_b in Cluster1 in Fig. 1. When a device executes some tasks as a helper during t max n , the CE of the device increases.
(2) T loc n = C loc n f loc n , n ∈ N www.nature.com/scientificreports/ Local + D2D computing. A device that can't entirely execute a task within its computation capability needs to request computing resources from nearby devices. When the device finds an adjacent device that can assist in processing partial tasks, the execution mode is changed to Local+D2D mode, and the auxiliary device is a helper. Device n1 represents the helper, and device n2 represents the neighboring device that needs help from device n1, and device n2 offloads the task of size D dev n1,n2 to device n1. The delay caused by the D2D communication consists of two parts, the transmission delay of the subtask that needs to be executed by the helper device and the processing delay in the helper. The delay for device n2 and its helper n1 and the energy consumption for device n2 can be expressed as where f dev n1 represents the computation capability of the helper, P com n1,n2 represents the transmission power of D2D communication link, P idl n2 represents idle power of device n2 (in watt). Besides, we define represents the processing delay in the helper device. After the device executes a partial task as a helper, its energy consumption increases and is expressed as After executing the additional task as a helper, the computing efficiency of this helper device improves and can be expressed as Local + D2D + edge computing. Devices that did not choose to offload the subtasks to nearby helper devices would offload their subtasks to the edge server for task execution. The execution mode is modified into Local+D2D+Edge mode. Similar to Local+D2D mode, the delay is also composed of the transmission part and processing part. The delay and energy consumption can be expressed as where P com n,e represents the transmission power of the cellular link. In this paper, the consumption (time and energy) is considered from the perspective of devices using battery power, so it is necessary to consider consumption for the devices. Generally, the edge server with cable power always has enough power to complete the tasks, so the calculation energy consumption of the MEC server is omitted here, similar to the work in 47 . Just like the studies in 48,49 , the transfer of calculated results of time and energy consumption from edge server is neglected in this work, as the calculation results are generally much smaller than the calculated input data. It's also fit for D2D computing.
Finally, we can get the total time delay and total energy consumption of device n in the current time frame expressed as The total delay for each device can be represented by Eq. (12). T n is the largest one of the time consumed by local execution, D2D execution and the edge server execution.
Problem formulation. In this section, we propose an integrated framework of computing offloading and computation resource allocation in D2D-MEC wireless cellular networks. We set n = [T loc n , T dev ′ n , T edg n ] , µ n = [D loc n , D dev n , D edg n ] , and give the optimization formulation of the problem as follows Considering the changing trend of T loc n /t max n , T dev n /t max n and T edg n /t max n are opposite, we prefer the proportion of the former two to be as high as possible, and the latter is vice versa. Thus, we introduce the negative value to represent the weight of T edg n . Constraints C1 and C2 guarantee the offloading decisions which meet some conditions. Constraint C3 bounds the maximum delay time of each device. Constraint C4 ensures that all tasks can completely be executed. Constraint C5 is the total computation resource limitation of the edge server. Constraint C6 ensures that each device offloads its task to the edge server and can be allocated to some computation resources. We can observe that P 1 is a mixed-integer non-linear problem consists of both combinational variables {A n } and continuous variables {µ n , f edg n } which is hard to resolve. In the next section, we will decompose it into two phases and solve them by heuristic algorithms.
Problem decomposition and solution. The main challenge in solving P 1 is that both combinational variables {A n } and continuous variables {µ n , f edg n } are involved. However, by analyzing the problem, we can successfully divide it into two phases and then solve them individually.
By analyzing these six constraints, we can find that constraints C1 and C2 are about task offloading, constraints C5 and C6 are about the resource allocation of the edge server and constraints C3 and C4 are aimed at the whole task process. The offloading decisions x n , y n , z n satisfy 1 ≤ x n + y n + z n ≤ 2 . We know that task executed via D2D connection is also executed on another helper device and 1 ≤ x n + y n ≤ 2 holds. It has nothing to do with the edge server, which means constraints C2 and C4 can be divided. Based on this, we decompose the task into two parts, executing on the device through D2D communication and executing on the edge server.
Task assignment and offloading decision. Since our goal is to maximize the weighted sum of the computing efficiency and the proportion of edge server execution time to the total time of all devices, the main limitations of P 1 include the task offloading strategy and the limited computation resources of the edge server. In the first phase, we decompose the task offloading strategy and device computing efficiency acquired from P 1 and its mathematical formula can be expressed as According to Eq. (9), the computing efficiency obtained from the task execution is C loc n f loc n t max n + C dev n,n2 f dev n t max n , according to Eq. (2), the local execution time is T loc n = C loc n f loc n , and we know T dev ′ n = C dev n,n2 f dev n . It is easy to find that CE total n = T loc n /t max n + T dev ′ n /t max n , they are formulated from two aspects, i.e., computation resources occupation and time occupation. www.nature.com/scientificreports/ We transform the constraint (C3)∼(C4) into (C3) 1 ∼ (C4) 1 , because the device that needs help belongs to N 2 . Only the device that requires additional resources via D2D connection is considered, and its task is executed locally or executed through a helper. The total delay of these devices is the largest one of the local execution delay, the delay of the device that executes D2D computing and the helper execution delay, namely constraint (C3) 1 .
According to whether the devices can complete their tasks within the required time, we divide the devices into two clusters: local computing and remote computing. The proposed clustering method for the task-assigned algorithm (CTAA) is described in Algorithm 1. Local computing devices may have excess computing resources to provide for another device, while remote computing devices have reached the maximum computing efficiency when performing local computing. Then, the low complexity dichotomy algorithm (LCDA) described in Algorithm 2 is used to get the set of devices that execute the remaining tasks in the nearby helper devices and the edge server respectively. www.nature.com/scientificreports/ In Algorithm 2, the choice of the adjacent helper is reflected in using LCDA to match the computation resources required by the device and provided by the helper device to achieve the best matching. The device with enormous task requirements can match the corresponding helper device and vice versa. It's the sub-optimal but best solution because the optimal solution requires a perfect match, which is bound to incur a lot of extra costs.
Computation resource allocation. The second phase considers the allocation of computing resources at the edge server to minimize computing time. We can express the problem as We convert (C3)∼(C4) to (C3) 2 ∼ (C4) 2 . The devices offloaded to the edge server are in N 3 , which does not involve helper execution, so this conversion is reasonable. In this round of task execution, the maximum delay of all devices offloaded to the edge server is the same, i.e., T max n . We need to ensure the execution time of each device is not over the maximum time delay, namely constraint (C3) 2 . We set the computing resources allocated to the devices that execute tasks at the edge server as {f Finally, we can get the computing resources allocated to each device executing the task on the edge server. The specific algorithm is described in Algorithm 3.

Simulation results
In this section, simulation results of the proposed D2D-MEC system are presented to verify the performance enhancement. The channel power gain in the D2D-MEC system is modeled as h = 10 −3 d −ζ φ , where d ∼ u(0.2, 30)(in m) represents the distance between the two communication terminals, ζ represents the pathloss exponent and is assumed to be 2.5 23 , and φ is small-scale fading and φ ∼ CN(0, 1) is an independent and identically distributed circularly symmetric complex Gaussian vector with zero mean and covariance one 27 . The major simulation parameters employed in the simulations, unless otherwise stated, are summarized in Table 3.

Task execution result.
The simulation is carried out to verify the rationality of the proposed algorithm from two aspects, i.e., task execution time and task execution energy consumption of each device, as shown in Figs. 3 and 4. In Fig. 3, the number and the access ratio of devices executed locally, offloaded to a helper via D2D connection and offloaded to the edge server via cellular connection are (24, 10, 6), (0.6, 0.25, 0.15) respectively. The number of devices executed locally is significantly higher than that executed remotely and the tasks' execution time at the edge server is relatively less because they are not heavy. In addition, all tasks are completed within the maximum tolerance time. Task execution delay and consumption are two important factors affecting the performance of a model. As shown in Fig. 4, the energy consumption of each device and the incremental energy consumption of helper devices are given. The average energy consumption of local computing devices is lower than that of remote computing devices. Devices have fluctuated time and consumption to execute tasks locally, which depends on their performance and the size of the assigned tasks. The results show that the proposed resource allocation model and task offloading algorithm can ensure that each device could complete the assigned task with less energy consumption within the specified time delay.

Task mode comparison.
To increase the computing efficiency and the access rate of the devices, improve the completion rate of the tasks in the system, three task execution modes are adopted, namely local computing, D2D computing and edge server computing. We measure the effectiveness of the proposed algorithm in terms of the number of devices existing on the system, the task size assigned to a single device and the task execution delay, then carry out the comparison of the three modes. The results are averaged over 1000 independent experiments to ensure the scientific nature of the simulation.     We set the number of devices to 40 and 80 respectively. When the number of devices is the same and the maximum delay ranges from 0.8 to 1.5 s, we conduct a statistical simulation of device access in the three modes. As Fig. 5 shows, the trend is the same. We analyze the situation when the total number of devices is 40. When the delay is the minimum one (i.e., 0.8 s), the number of devices that execute tasks locally reaches the minimum value. The number of devices that offload tasks to helpers via D2D connection is relatively smooth cause only the devices with high performance allocated relatively small tasks are likely to execute additional tasks as helpers and these devices are relatively constant. In addition, the number of devices that execute tasks remotely is the maximum at this time, so is that of offload tasks to the edge server. With the increase of time delay, the number of devices that can complete tasks locally increase slowly, while that of offload tasks remotely decrease. The utilization of computing resource at the edge server is reduced, so is the number of devices executed on it. The remaining computing resources on the edge server can be used in other parts of the cellular network.
The introduction of D2D communication improves the computing efficiency of the device and relieves the computing pressure of the edge server effectively. In addition, if the latency is too small, most of the devices can not complete their tasks locally, which causes the congestion of the connected links and the resources allocated by the edge server may not be sufficient to complete the task.
As shown in Fig. 6, with the number of devices ranging from 10 to 80 in the system under the three modes, we conduct a statistical analysis on the access rate of devices. The performance configuration of the devices is shown in Table 3. When the total number of devices is less than 20, the number of local computing devices is larger. As the devices' number increases and ranges from 20 to 50, D2D mode and the edge mode change in opposite directions. At this time, the number of devices accessing D2D mode increases steadily. When the number of devices is 40, the corresponding access rate of the three modes is (0.58, 0.3, 0.13) respectively, which  www.nature.com/scientificreports/ has the same conclusion obtained in Fig. 3. When the total number of devices is greater than 50, the device access rate tends to be stable in the three modes. Besides, some insightful results can be obtained via simulation parameters from Table 3. The ranges of D n and App n are [0.1, 2] Mbits and [500, 2000] CPU Cycles/bit respectively, the tolerance time is 1.1s and the computation resource of a device fn is [0.5, 2] CPU cycles/s. For convenience of description, the lower and upper limits of Dn and Appn are denoted by D l n and D h n , App l n and App h n respectively. The joint distribution of D n and App n , namely the task assigned to each device is uniformly distributed on the rectangle S = x, y |D l n ≤ x ≤ D h n , App l n ≤ y ≤ App h n . When x, y ∈ S , the joint probability density is f x, y = 1 D h n − D l n App h n − App l n , when x, y / ∈ S , f x, y = 0 . Since the range of task which can be executed locally by the device follows the uniform distribution of [Tsk l n , Tsk h n ] , where Tsk l n = 0.5 * 1.1 * 10 9 and Tsk h n = 2 * 1.1 * 10 9 . By solving the probability We can get the ratio of the devices that execute tasks locally to be 0.65 accordingly. When the total number of devices is 40 and 80, the theoretical optimal value of the local execution devices should be 26 and 52 respectively. As shown in Fig. 5, the actual measured value is 24 and 49 respectively, and the matching degree reaches 93.27%, which is within the tolerance and consistent with our conclusion. We extended the task size range from [0.1, 1] to [0.1, 3] Mbits to conduct statistical analysis on the number of devices in the three modes. Different task size will also affect the task execution process of each device. As shown in Fig. 7, when the task size is small, local mode and D2D mode can finish all tasks in the system. As the maximum task cap increased, some devices need to execute larger tasks, the performance of local devices limits the number of devices that can execute tasks locally. The increasing number of devices that can't execute tasks locally affects the devices' number that execute tasks through D2D mode. The number of devices executing tasks in D2D mode increases slightly and remains relatively stable overall. At this time, D2D mode can no longer improve the overall performance of the system. The number of devices executed on the edge server is increasing to relieve system stress. Compared with traditional D2D communication, Local + D2D + MEC mode has more significant advantages in processing tasks.
Task algorithm optimization. The mode selection algorithm we proposed in the D2D-MEC system is the low complexity dichotomy algorithm (LCDA), which we compared with two baseline algorithms, namely the maximum task assignment method (MTAM) and the random task assignment method (RTAM). The MTAM algorithm allows a device to select one neighboring device as a helper to provide the largest computation capability, which causes the device that selects previously has a higher hit rate, while that of selects afterward has a lower probability to offload its task. The RTAM algorithm randomly selects one adjacent device as a helper to match the device, i.e., the device that can provide sufficient computing capability. Fig. 8 shows how the proposed algo-  Table 4 shows the number of helper devices and the average CE rate under the three algorithms in the six situations mentioned above. When the devices' number is fixed, taken 40 as an example, the CE of the device which needs to be offloaded reaches the maximum value, so only the local execution devices are analyzed in the figure. As the delay increases, the total number of local execution devices also increases. The number of devices in Fig. 8a-c is (16,24,30). For the convenience of observation, the CE depicted in the figure removes the local CE. It represents the incremental CE of helpers. The number of nodes in the figure represents the number of helpers, and the amplitude represents the increased value of CE. The overall improvement in the proposed algorithm is superior to the other two algorithms. Table 4 shows the number of helper devices and the percentage of improved efficiency under the three algorithms when the total number of devices is 40   Model comparison results. The above simulation results comprehensively analyze the performance of the D2D-MEC system and show that the proposed algorithm can effectively improve the computing efficiency of the devices, enhance the capacity and increase the number of access devices for the system. To further verify the performance of the algorithm, we compare the proposed algorithm with the traditional D2D-MEC algorithm, including the improved greedy algorithm 41 , the initial task assignment algorithm (ITA) 25 , bipartite graph matching algorithm (BGMA) 14 , and energy-efficient and delay-aware offloading scheme (EEDOS) 32 . Besides, the comparison is under our proposed scenarios. The completed tasks of the five algorithms under different execution modes are illustrated in Figs. 9 and 10. Since each device is assigned a task, the devices number of the system is equal to the number of tasks. The devices number in Figs. 9 and 10 is 40 and 80 respectively and the maximum delay is 0.8-1.5 s and 0.8-1.4 s respectively.
As an example, Fig. 9 compares the total number of devices executed through local computing and D2D computing with the number of devices executed on the edge server under different time delays. As shown in the figure, the LCDA algorithm, which gives priority to local computing and D2D computing, can complete all tasks within the specified time delay, while the other four algorithms cannot. When the delay is short, the LCDA   www.nature.com/scientificreports/ algorithm requires more computing resources from the edge server and the EEDOS algorithm has the same trend, while the other algorithms have no significant change in demand for the edge server. The number of completed tasks of the five algorithms is compared. The number of devices is set to 40 and 80, and the delay constraint is set to 0-1.4 s respectively. Accordingly, we can acquire the total number of tasks completed by the five algorithms in each time delay. Figures 11 and 12 shows that the proposed LCDA algorithm is better than the other four algorithms. With the increase of time delay, the total number of completed tasks of the LCDA algorithm is significantly larger than the other four algorithms. When the delay time reaches 0.8s, all devices under the LCDA algorithm can complete their tasks and remain stable in the following time delay, while at this point, the other four algorithms still can't complete all tasks.
In conclusion, compared with some traditional D2D-MEC resource allocation algorithms, the LCDA algorithm is superior under the proposed scenarios. The reason for the better performance of the proposed algorithm is that the local and edge server computation resources are considered together and the partial offloading strategy is used in the model. Compared with the proposed algorithm, the improved greedy algorithm only considers binary offloading and idle helper devices, the ITA algorithm ignores the partial offloading strategy, the BGMA algorithm does not take the computing resources of the BS into account, and the EEDOS algorithm only considers the help from idle devices but ignores the high-performance devices with little tasks to be handled.  www.nature.com/scientificreports/ Complexity analysis. In this section, we briefly analyze the complexity of the proposed algorithm in two phases, i.e., the computation offloading strategy and D2D computing efficiency acquired in Phase P 2 and edge server resource allocation in Phase P 3 , where we examine the complexity of solutions to the two phases respectively. In addition, in the proposed scheme, Problem P 2 can be divided into two sub-problems. The devices are divided into two clusters through Algorithm 1, the time complexity is O(N), where N represents the number of devices involved in resource allocation. The goal of Algorithm LCDA is to select the helper device and calculate its CE. The time complexity of LCDA is O(log N 1 ), where N 1 is the number of devices that have been matched in the system, and in the best and the worst case, the complexity is O(N 1 ) and O(iterator N 1 ) respectively. According to the fifth line of Algorithm 2, the iterations to find the matching device is set to iterator, and N 1 is the number of matched devices. When devices can complete their tasks on time but can only provide fewer resources, those that need help need a lot of resources in this period, in this extreme case, the worst computational complexity is attained. The problem of resource allocation of the edge server is solved in P 3 , which can be completed in polynomial time. Accordingly, the overall computational complexity is O(N). Compared with the other four traditional D2D-MEC algorithms, the time complexity of the greedy algorithm is O(N 2 ), that of ITA algorithm is O(N N+2 ) and that of BGMA algorithm is O(TN 3 ), which are related to the time delay, and EEDOS algorithm is in a long polynomial. Therefore, the scheme proposed in this paper has a low computational complexity.

Conclusions
This paper proposes a multi-user D2D-MEC system to improve the computing efficiency of devices, where each device includes a task with a variable length to execute within a specified delay. The devices choose to execute tasks locally unless they are unable to complete them on time and offload some tasks to nearby devices with ample computing resources via D2D execution or an edge server. Firstly, a mixed-integer non-linear problem is presented to maximize the computing efficiency of the system. Then, we resolve it by dividing it into two phases. Specifically, according to the local computation priority, the first phase is to divide a task into local execution and remote execution according to Algorithm 1. The nearby helpers are first selected by the remote executing devices to offload their tasks through Algorithm 2, then an offloading strategy can be obtained by solving the problem. The assignment of computing resources in the edge server is considered in the second phase, and the assignment scheme is obtained through Algorithm 3. Numerical simulation results show that, compared with some traditional D2D-MEC algorithms, the number of access devices and completed tasks can be effectively improved through the proposed algorithm. Further, the task execution efficiency is improved, and a superior performance is achieve with a lower complexity.
Through the combination of D2D communication technology and MEC, computing and spectrum resources are expanded and a large-scale access of devices is increased. This is an application scenario of 5G, providing lowlatency service for computation-intensive tasks of mobile terminals, which belongs to the technical field of task offloading in the D2D-MEC system. In addition, ICT technology, as the integration of IT(MEC) and CT(D2D) technology, can be used for infrastructure construction in the smart city of 6G. In future work, ICT, digital twin and blockchain technologies will be applied to the Internet of Vehicles field, which can further promote the research on resource management and task offloading area in multi-link cooperative transmission and secure transmission. Our works have theoretical guiding significance for the subsequent research.