A method for programming a magnetic device comprising a plurality of self-referenced magnetic logical unit, MLU, cells; each including a magnetic tunnel junction comprising a ferromagnetic storage layer having a storage magnetization that is pinned at a low threshold temperature (T L) and freely orientable at a high threshold temperature (T H), a ferromagnetic sense layer having a sense magnetization, and a tunnel barrier layer between the storage layer and the sense layer; a field line physically separated from each of said plurality of MLU cells by an electrically non-conductive layer such that no current can pass directly from the field line to the magnetic tunnel junction, and configured for passing a programming current pulse for programming any one of said plurality of MLU cells; the method comprising: passing the programming current pulse in the field line for heating the magnetic tunnel junction of each of said plurality of MLU cells at the high threshold temperature (T H) such as to unpin the ferromagnetic storage magnetization; the programming current pulse is further adapted for generating a programming magnetic field adapted for switching the storage magnetization of each of said plurality of MLU cells in a programmed direction; wherein said passing the programming current pulse comprises: passing a first pulse portion during a first time period, the first current having a first intensity adapted for inducing the write magnetic field capable of switching the storage magnetization such that the storage magnetization is aligned with the programming magnetic field, and heating the magnetic tunnel junction at the high threshold temperature (T H); and passing a second pulse portion during a second time period having a second intensity lower than the first intensity such as to induce the write magnetic field capable of switching the storage magnetization before the magnetic tunnel junction reaches the low threshold temperature (T L), such that the storage magnetization is aligned with the programming magnetic field, and cool the magnetic tunnel junction at the low threshold temperature (T L). passing the programming current pulse in the field line for heating the magnetic tunnel junction of each of said plurality of MLU cells at the high threshold temperature (T H) such as to unpin the ferromagnetic storage magnetization; the programming current pulse is further adapted for generating a programming magnetic field adapted for switching the storage magnetization of each of said plurality of MLU cells in a programmed direction; wherein said passing the programming current pulse comprises: passing a first pulse portion during a first time period, the first current having a first intensity adapted for inducing the write magnetic field capable of switching the storage magnetization such that the storage magnetization is aligned with the programming magnetic field, and heating the magnetic tunnel junction at the high threshold temperature (T H); and passing a second pulse portion during a second time period having a second intensity lower than the first intensity such as to induce the write magnetic field capable of switching the storage magnetization before the magnetic tunnel junction reaches the low threshold temperature (T L), such that the storage magnetization is aligned with the programming magnetic field, and cool the magnetic tunnel junction at the low threshold temperature (T L). passing a first pulse portion during a first time period, the first current having a first intensity adapted for inducing the write magnetic field capable of switching the storage magnetization such that the storage magnetization is aligned with the programming magnetic field, and heating the magnetic tunnel junction at the high threshold temperature (T H); and passing a second pulse portion during a second time period having a second intensity lower than the first intensity such as to induce the write magnetic field capable of switching the storage magnetization before the magnetic tunnel junction reaches the low threshold temperature (T L), such that the storage magnetization is aligned with the programming magnetic field, and cool the magnetic tunnel junction at the low threshold temperature (T L).