If you aren't lucky enough to be told in the question, the first thing we have to do is know when we should you integration by parts.
Well, like most things in maths this should become second nature to you with enough practice but as a general rule of thumb if we can't see a way past the problem after just looking at it and integration by substitution isn't a viable option, then this is when we should think about using intergration by parts.
Typical problems where this technique is suitable are where we have two quite different functions multiplied together, where one of those functions is differentiable infinitely many times.
For example: integrate xsin(3x) with respect to x
Our formula for integration by parts is as follows:
integral(V(du/dx)) = UV - integral(U(dv/dx))
In order to use this we must decide what is V and what is (du/dx), in short we want to label V as the function in the multiplication that will disappear after being differentiated a number of times which in most cases is a simple polynomial, this is because to use the formula we must solve the integral, integral(U*(dv/dx)), in this case we pick V = x and (du/dx) = sin(3x)
Note: if we picked sin(3x) to be V, then we would need to solve integral(U*[-cos(3x)/3]), which doesn't simplify the problem since U will only increase in order, in this case U = x2/2
So using our formula and the values of V and (du/dx) determined earlier, V = x and(du/dx)= sin(3x)
This gives us integral(xsin(3x)) = -[xcos(3x)]/3 - integral(-[cos(3x)]/3)) which has now been reduced to a simple integral which is equal to:
-[x*cos(3x)]/3 - [sin(3x)]/9 + C
If there are no bounds don't forget the +C