Simulacron-3

Simulacron-3 (1964) (also published as Counterfeit World), by Daniel F. Galouye, is an American science fiction novel featuring an early literary description of a simulated reality.

Plot summary
Simulacron-3 is the story of a virtual city (total environment simulator) for marketing research, developed by a scientist to reduce the need for opinion polls. The computer-generated city simulation is so well-programmed, that, although the inhabitants have their own consciousness, they are almost entirely unaware that they are models in a computer simulation.

The simulator's lead scientist, Hannon Fuller, dies mysteriously, and a co-worker, Morton Lynch, vanishes. The protagonist, Douglas Hall, is with Lynch when he vanishes, and Hall subsequently struggles to suppress his inchoate madness. As time and events unwind, he progressively grasps that his own world is probably not "real" and might be only a computer-generated simulation.

Similar works
In writing, the Frederik Pohl short story "The Tunnel under the World" (1955) deals with similar philosophic themes and satirical criticism of marketing research, although in Pohl's story the described simulated reality is mechanical, an intricate scale-model whose inhabitants’ consciousnesses reside in a computer, rather than being solely electronic. The Philip K. Dick story Time Out of Joint (1959) presents a man who is unaware that he is living his life in a physically simulated town until changes in his (apparent) reality begin to manifest themselves.

The Matrix (1999) described a world whose population is unaware that the world containing their minds is a virtual reality simulacrum.

"The Plagiarist" (2011) by Hugh Howey is a short novel which deals with similar themes and ideas.

The Doctor Who episode "Extremis" has a similar plot.

Adaptations
The novel has been adapted several times into other media, including as the two-part German television film World on a Wire (Welt am Draht, 1973), by Rainer Werner Fassbinder, "staying reasonably faithful to Galouye's book," as the film The Thirteenth Floor (1999) produced by Roland Emmerich and directed by Josef Rusnak, and as a play World of Wires (2012) directed by Jay Scheib.