Mobile edge computing (MEC) is a promising solution to support emerging delay-sensitive mobile applications, such as self-driving, augment/virtual reality, and various Internet of Things (IoT) applications. By deploying MEC servers at network edge, e.g., close to cellular base stations (BSs), the computational tasks generated by these applications can be offloaded to edge nodes (ENs) and be quickly executed there. At the same time, with the projected large number of IoT devices, the communication and computational resources allocated to each user can be quite limited, making it challenging to provide low-latency MEC services. In this paper, we investigate the problem of task partitioning and user association in an MEC system, aiming to minimize the average latency of all users. We assume that each task can be partitioned into multiple subtasks that can be executed on local devices (e.g., vehicles), MEC servers, and/or cloud servers; each user can be associated with one of the nearby ENs. The subtasks can be independent of or dependent on each other. For each case, we formulate the joint optimization of task partitioning ratios and user association as a mixed integer programming problem. Each problem is solved by decomposing it into two subproblems. The lower-level subproblem is task partitioning under a given user association, which can be solved optimally. The higher-level subproblem is user association, we propose a dual decomposition-based approach and a matching-based approach to derive near-optimal solutions. Simulation results show that compared to benchmark schemes, the proposed schemes reduce the average latency by about 50% and 40% for the cases of independent and dependent subtasks, respectively.