What does it mean for a submodule of a module over a PID to have invariant factors $1$ or $0$? I will take a particular example for simplicity: suppose $D$ is a PID and $M$ is finitely generated submodule of $D^5$, say, with set of generators $x_i, i=1,2,3,4,5$. Suppose also that the smith normal form of matrix $A = (a_{i,j}) $ defined by $x_i = \sum_{j=1}^5 a_{i,j} e_j$, where $e_j$ is the canonical base for $D^5$ is given by
$PAQ = \text{diag}(1,1,1,0,0)$
where $P$, $Q$ are $5\times 5 $ invertible matrices over $D$. Does this then mean that $M$ is isomorphic to $D^3$ or $D^2$? I have read the proof of the decomposition theorem for finitely generated modules over a PID in Jacobson's Basic Algebra, and thus the two $0$ in the smith form imply that the free part of $M$ is $2$ but, reading some examples in this website it seems that it is the other way, so, I am confused ( here is one of the examples I am talking about)
 A: So let us unpack this. You have a map $\mu_A: D^5\to D^5$, given by left multiplication by the matrix $A$, whose image is $M$. Now as $P$ is invertible, left-multiplication by $P$ is an automorphism of $D^5$, so we can write
$$
M\cong\mu_P(M)=\{PAx\mid x\in D^5\}=\{PAQx\mid x\in D^5\}=\{\operatorname{diag}(1,1,1,0,0)x\mid x\in D^5\}=\{(x_1,x_2,x_3,0,0)\mid x_1,x_2,x_3\in D\}\cong D^3.
$$
Here is where your confusion may stem from: what you started with, was a description of a generator set of $M$ in the coordinates of $D^5$, and as statet above, this is equivalent of being given a map $\varphi:D^5\to D^5$ whose image you would like to describe (in our case $\varphi$ is left multiplication by $A$).
But the Smith Normal Form is also often used in the following setup: suppose you are given an abstract module $N$ together with some surjection $\pi: D^5\to N$. Suppose also that you know that $\ker\pi$ is given by the image of a map $\varphi: D^5\to D^5$, given by left multiplication with a matrix $A$. This is neatly stated by saying that the sequence
$$
D^5\overset{\varphi=\mu_A}\longrightarrow D^5\overset{\pi}\longrightarrow N\longrightarrow 0
$$
is exact (this is what is called a presentation of $N$). If $n_1,\ldots,n_5$ are the images of the canonical basis $e_1,\ldots,e_5$ under $\pi$, then the above data is often stated by saying that the generators $n_1,\ldots,n_5$ satisfy the relations
$$
A^t\cdot (n_1,\ldots,n_5)^t=0.
$$
Notice the transpose! This comes from the fact that the image of $A$ is the kernel of $\pi$, so its the columns of $A$ who are mapped to $0$ inside $N$, and who give you the relations among $n_1,\ldots,n_5$.
In this case, when we want to find the isomorphism class of $N$ knowing that $PAQ=\operatorname{diag}(1,1,1,0,0)$, we have that $N\cong D^2$, because this time we are interested in the cokernel of $A$, while for $M$ we were interesred in the image of $A$.
So to summarize:

*

*If you want to describe the image of a matrix using its Smith normal form, then the columns of the diagonal matirx form a generator set for a module isomorphic to the image. So the number of $0$'s on the diagonal tells you by how many copies of $D$ you lose (in our case there are $2$).

*if you want to describe the image of a matrix using its Smith normal form, then the number of $0$'s on the diagonal tells you how many free copies of $D$ you get.

I'm telling you all this because it occurs far more often that you are given a presentation of a module. Your sitaution is far less common. And the answer to your question depends on the situation!
