I wrote a program to do some float caculation and cast the result to int; When I submit the job to the cluster multiple times, I got different result even when I provided same parameters;
// compiled with gcc8.3, centos float* x = ....; float* y = ....; // simply use [+ * - /] to caculate cos simlilarity float similarity = cos_similiarity(x, y, dim); similarity = similarity * 100; int result = std::round(similarity);
I cast a float (range 0 - 1) to int (with multiplier 100); Sometimes I get unstable result, like 50 and 49; I guess the float represention of cos_sim function result maybe 49.50...01 and 49.499...9 when running on different machines, so the round function rounds to different int;And I have following question:
- Is my guess right? Same binary(asm code) can have different float math result running on different machines/platforms/libc versions..?
- If so, how to make my result consistent?