implement the global counter by sparse matrix