The primary nerve fibers to the penis are from the dorsal nerve of the penis, a branch of the pudendal nerve. The cavernosal nerves are a part of the autonomic nervous system and incorporate both sympathetic and parasympathetic fibers. They travel posterolaterally along the prostate and enter the corpora cavernosa and corpus spongiosum to regulate blood flow during erection and detumescence. The dorsal somatic nerves are also branches of the pudendal nerves. They are primarily responsible for penile sensation. 
Exercise and lifestyle modifications may improve erectile function. Weight loss may help by decreasing inflammation, increasing testosterone, and improving self-esteem. Patients should be educated to increase activity, reduce weight, and stop smoking, as these efforts can improve or restore erectile function in men without comorbidities. Precise glycemic control in diabetic patients and pharmacologic treatment of hypertension may be important in preventing or reducing sexual dysfunction. 
There are many effective treatments for impotence. The most popular is a class of drugs called phosphodiesterase type 5 (PDE5) inhibitors. These include sildenafil (Viagra), vardenafil (Levitra), tadalafil (Cialis) and avanafil (STENDRA). These drugs are taken in pill form. They work in most men. But they are less effective in men with neurological causes of impotence.
There are two kinds of surgery for ED: one involves implantation of a penile prosthesis; the other attempts vascular reconstruction. Expert opinion about surgical implants has changed during recent years; today, surgery is no longer so widely recommended. There are many less-invasive and less-expensive options, and surgery should be considered only as a last resort.
According to a review of all randomized controlled trials evaluating sildenafil by the American Urological Association (AUA) Consensus Panel on Erectile Dysfunction, 36% to 76% of patients receiving the drug were "able to achieve intercourse" during treatment. For tadalafil, four randomized controlled trials revealed that 11% to 47% of patients were "able to achieve intercourse." Similar efficacy has been observed with vardenafil, although studies are fewer.19 A meta-analysis published in 2013 clearly demonstrated increased efficacy over placebo for all PDE5 inhibitors.24 Head-to-head comparison suggested that tadalafil outperforms sildenafil on validated measures of erectile dysfunction, including the international index of erectile function and sexual encounter profile-2 and -3.