Verify matrix calculation before write in C++