# Map: One Thread, One Value

*Task 1 of 6 · [Thinking in Parallel](https://gpu.rocks/learn/thinking-in-parallel-c3876efb.md) · GPU.js Learn*

Nearly every GPU program you'll ever write is built from a handful of patterns,
and the first one has a name: **map**. Each output cell is a pure function of
the input cell *at the same index* — no neighbors, no shared state, no
"first do cell 3, then cell 4". That independence is exactly what lets the GPU run all
the cells at once.

Here `celsius` holds 64 temperature readings. Converting them to Fahrenheit
is a textbook map: reading 7 becomes output 7, and nothing else matters to thread 7.

## Goal

**Goal:** map every Celsius reading to Fahrenheit —
`°F = °C × 9/5 + 32` — one thread per reading.

## Requirements

- Read only *this thread's* element: `celsius[this.thread.x]`
- Apply the formula `c * 9 / 5 + 32`
- No loops over the array — the grid of threads *is* the loop

## Hint 1 — the shape of a map

A map kernel touches exactly one input cell and one output cell, both at
index `this.thread.x`. If you find yourself reading any other index,
it's not a map any more.

## Hint 2 — the one-liner

```js
return celsius[this.thread.x] * 9 / 5 + 32;
```

## Same idea elsewhere

Map is the hello-world of every GPU API: a CUDA grid where each thread transforms
one element of a device array, a WebGPU compute shader dispatched once per buffer entry, a
Metal compute encoder doing the same. If a problem is a pure map, it parallelizes for free.

## Starter code

```js
// Map: output[i] depends ONLY on input[i]. One thread per reading.
const gpu = new GPU({ mode });

const toFahrenheit = gpu.createKernel(function (celsius) {
  // TODO: convert THIS thread's reading — °F = °C × 9/5 + 32
  return celsius[this.thread.x];
}, { output: [64] });

const result = await toFahrenheit(celsius);
console.log('first reading:', celsius[0], '°C →', result[0], '°F');
```

---

Interactive version: https://gpu.rocks/learn/thinking-in-parallel-c3876efb/1

[Next task](https://gpu.rocks/learn/thinking-in-parallel-c3876efb/2.md)
