Targeting multiple tiles¶
In the previous example, the code targeted only a
single tile. Most real applications will instead target two or more tiles. It is
not possible to target multiple tiles using a single C application as the tiles
are complete, separate processors. Instead each tile runs its own application,
and each tile’s application can communicate with other tiles using the channels
documented previously. To aid development of multi-tile applications, the XMOS
tools allow the use of a special ‘mapping file’ which can be used to specify an
entry-point for each tile in a network. This is instead of specifying a main
function in C - which is not allowed when a mapping file is used.
Warning
For historical reasons, the format of the mapping is C-like. However, this format should not be treated as C-source and is likely to be deprecated in future versions of the tools and replaced with a purely declarative format. Developers are therefore recommended to avoid any procedural code within a mapfile.
Using a mapfile¶
To map code onto both of the tiles on a XCORE-200-EXPLORER, it is necessary
to describe that mapping in a file which we will call mapfile.xc
. An
example is shown below:
#include <platform.h>
extern "C" {
void main_tile0();
void main_tile1();
}
int main(void)
{
par {
on tile[0]: main_tile0();
on tile[1]: main_tile1();
}
return 0;
}
This mapfile references the two functions in main.c
:
#include <stdio.h>
void main_tile0()
{
printf("Hello from tile 0\n");
}
void main_tile1()
{
printf("Hello from tile 1\n");
}
Now build and execute this multi-tile application on real hardware to see the printed output:
$ xcc -target=XCORE-200-EXPLORER mapfile.xc main.c
$ xrun --io a.xe
Hello from tile 0
Hello from tile 1
Summary¶
In this example, you have written a mapfile using the declarative components of XC language to deploy two C functions onto the two tiles of an XCORE-200-EXPLORER.
See also
At this point, you might proceed to the next topic, or you might chose to explore this example further: