--- title: "tile_static Keyword | Microsoft Docs" ms.custom: "" ms.date: "11/04/2016" ms.reviewer: "" ms.suite: "" ms.technology: - "cpp-language" ms.tgt_pltfrm: "" ms.topic: "language-reference" f1_keywords: - "tile_static_CPP" dev_langs: - "C++" helpviewer_keywords: - "tile_static keyword" ms.assetid: d78384d4-65d9-45cf-b3df-7e904f489d06 caps.latest.revision: 12 author: "mikeblome" ms.author: "mblome" manager: "ghogen" translation.priority.ht: - "cs-cz" - "de-de" - "es-es" - "fr-fr" - "it-it" - "ja-jp" - "ko-kr" - "pl-pl" - "pt-br" - "ru-ru" - "tr-tr" - "zh-cn" - "zh-tw" --- # tile_static Keyword The `tile_static` keyword is used to declare a variable that can be accessed by all threads in a tile of threads. The lifetime of the variable starts when execution reaches the point of declaration and ends when the kernel function returns. For more information on using tiles, see [Using Tiles](../parallel/amp/using-tiles.md). The `tile_static` keyword has the following limitations: - It can be used only on variables that are in a function that has the `restrict(amp)` modifier. - It cannot be used on variables that are pointer or reference types. - A `tile_static` variable cannot have an initializer. Default constructors and destructors are not invoked automatically. - The value of an uninitialized `tile_static` variable is undefined. - If a `tile_static` variable is declared in a call graph that is rooted by a non-tiled call to `parallel_for_each`, a warning is generated and the behavior of the variable is undefined. ## Example The following example shows how a `tile_static` variable can be used to accumulate data across several threads in a tile. ```cpp // Sample data: int sampledata[] = { 2, 2, 9, 7, 1, 4, 4, 4, 8, 8, 3, 4, 1, 5, 1, 2, 5, 2, 6, 8, 3, 2, 7, 2}; // The tiles: // 2 2 9 7 1 4 // 4 4 8 8 3 4 // // 1 5 1 2 5 2 // 6 8 3 2 7 2 // Averages: int averagedata[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; array_view sample(4, 6, sampledata); array_view average(4, 6, averagedata); parallel_for_each( // Create threads for sample.extent and divide the extent into 2 x 2 tiles. sample.extent.tile<2,2>(), [=](tiled_index<2,2> idx) restrict(amp) { // Create a 2 x 2 array to hold the values in this tile. tile_static int nums[2][2]; // Copy the values for the tile into the 2 x 2 array. nums[idx.local[1]][idx.local[0]] = sample[idx.global]; // When all the threads have executed and the 2 x 2 array is complete, find the average. idx.barrier.wait(); int sum = nums[0][0] + nums[0][1] + nums[1][0] + nums[1][1]; // Copy the average into the array_view. average[idx.global] = sum / 4; } ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 6; j++) { std::cout << average(i,j) << " "; } std::cout << "\n"; } // Output: // 3 3 8 8 3 3 // 3 3 8 8 3 3 // 5 5 2 2 4 4 // 5 5 2 2 4 4 // Sample data. int sampledata[] = { 2, 2, 9, 7, 1, 4, 4, 4, 8, 8, 3, 4, 1, 5, 1, 2, 5, 2, 6, 8, 3, 2, 7, 2}; // The tiles are: // 2 2 9 7 1 4 // 4 4 8 8 3 4 // // 1 5 1 2 5 2 // 6 8 3 2 7 2 // Averages. int averagedata[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; array_view sample(4, 6, sampledata); array_view average(4, 6, averagedata); parallel_for_each( // Create threads for sample.grid and divide the grid into 2 x 2 tiles. sample.extent.tile<2,2>(), [=](tiled_index<2,2> idx) restrict(amp) { // Create a 2 x 2 array to hold the values in this tile. tile_static int nums[2][2]; // Copy the values for the tile into the 2 x 2 array. nums[idx.local[1]][idx.local[0]] = sample[idx.global]; // When all the threads have executed and the 2 x 2 array is complete, find the average. idx.barrier.wait(); int sum = nums[0][0] + nums[0][1] + nums[1][0] + nums[1][1]; // Copy the average into the array_view. average[idx.global] = sum / 4; } ); for (int i = 0; i < 4; i++) { for (int j = 0; j < 6; j++) { std::cout << average(i,j) << " "; } std::cout << "\n"; } // Output. // 3 3 8 8 3 3 // 3 3 8 8 3 3 // 5 5 2 2 4 4 // 5 5 2 2 4 4 ``` ## See Also [Microsoft-Specific Modifiers](../cpp/microsoft-specific-modifiers.md) [C++ AMP Overview](../parallel/amp/cpp-amp-overview.md) [parallel_for_each Function (C++ AMP)](../parallel/amp/reference/concurrency-namespace-functions-amp.md#parallel_for_each) [Walkthrough: Matrix Multiplication](../parallel/amp/walkthrough-matrix-multiplication.md)