Consider a distributed system N in which each agent has an input value and each communication link has a weight. Given a global function, that is, a function f whose value depends on the whole network, the goal is for every agent to eventually compute the value f (N ). We call this problem global function computation. Various solutions for instances of this problem, such as Boolean function computation, leader election, (minimum) spanning tree construction, and network determination, have been proposed, each under particular assumptions about what processors know about the system and how this knowledge can be acquired. We give a necessary and sufficient condition for the problem to be solvable that generalizes a number of well-known results (Attyia et al. in J ACM 35(4):845-875, 1988; Yamashita and Kameda in IEEE Trans Parallel Distrib Syst 7(1):69-89, 1996; Yamashita and Kameda in IEEE Trans Parallel Distrib Syst 10(9):878-887, 1999). We then provide a knowledge-based (kb) program (like those of Fagin et al. (Reasoning about knowledge, MIT Press,