Run Your First Program
Run a program in the Code Playground and watch the Signaloid Cloud Compute Engine carry distributions through its output.
In this tutorial you run a small C program on a C0 core and watch it compute with probability distributions in place of single numbers. You do not need to install anything or write any code. The Code Playground opens with a ready-to-run example.
The Code Playground has three panels. The Editor is where you write code, the Results Panel is where output appears, and the Variable Viewer traces variables on Reference cores. This tutorial uses the first two. For a full tour of the interface, see the Code Playground reference.
Look at the example program
When you first log in, the Editor already contains a small program. It reads a
resistance R and a voltage V from a file, computes the power dissipation
P = V² / R, and prints all three. It reads its input from your Signaloid
Cloud Storage, mounted by default at sd0/. To change what is mounted, see
How to Upload Input Files and Read Them from Your Application.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/*
* Minimal example that demonstrates the effect of distributions in
* resistance and circuit voltage on the power dissipation of a resistor.
*/
int
main(int argc, char * argv[])
{
double R; /* Resistance (Ohms) */
double V; /* Voltage (Volts) */
double P; /* Power (Watts) */
FILE * fp;
const char * fileLocation = "sd0/Signaloid/example-loadDistFromFile/example.csd";
/*
* Load the resistance R and the circuit voltage V from a file.
*
* The file 'example.csd' is a comma-separated distribution (.csd) file that
* contains two distributions represented as comma-separated Ux hexadecimal strings.
* You can find more details about the Ux hexadecimal data format at
* https://docs.signaloid.io/docs/hardware-api/ux-data-format.
*
* The first Ux hexadecimal string in 'example.csd' initializes the resistance R as
* a uniform distribution with a nominal resistance value of 1000 Ω and a gold band
* tolerance of ±5%.
*
* The second Ux hexadecimal string in 'example.csd' initializes the circuit voltage
* V as a Gaussian distribution with a nominal voltage value of 3.3 V and a standard
* deviation of 0.01 V.
*/
fp = fopen(fileLocation, "r");
if (fp == NULL)
{
fprintf(stderr, "Could not open %s.\n", fileLocation);
exit(EXIT_FAILURE);
}
fscanf(fp, "%lf, %lf\n", &R, &V);
printf("R = %lf Ω\n", R);
printf("V = %lf V\n", V);
/*
* The power dissipation equation, P = V^2 / R.
*
* The Signaloid Cloud Compute Engine computes the distribution of
* P by deterministic computation on the distributions of V and R.
*/
P = pow(V, 2) / R;
printf("P = %lf W\n", P);
return 0;
}
Can you identify the lines that open the file and read the distributions
from it?
fopen (line 35) opens example.csd from the data source. fscanf (line 42)
parses the two comma-separated Ux distributions
in the file into the resistance R and supply voltage V. The first value is a
uniform distribution for R (nominal 1000 Ω, ±5% gold-band tolerance). The
second is a Gaussian distribution for V (nominal 3.3 V, standard deviation
0.01 V). The expression P = pow(V, 2) / R then computes the power dissipation
as a deterministic function of those two distributions.
How should the Signaloid Cloud Storage be mounted for this program to work?
The program reads the data file at
sd0/Signaloid/example-loadDistFromFile/example.csd. In the Signaloid Cloud
Storage tree, Signaloid is a top-level directory, so mounting the Signaloid
Cloud Storage at sd0 makes the mount path match what the program reads. This
is the platform default, so the example runs without any change.
Run the program
Click Run. This starts a Build, one compilation of your source code, then a Task, one execution of the compiled binary, once the Build completes. The status row shows a Build ID and a Task ID, each with its status and its own Cancel. See Builds and Tasks for the full status lifecycle.
When the Task status reaches Completed, the program has finished.
Completed. The Result Panel then shows the four tabs of program output, with distributional values underlined. Hovering reveals the plot, and the Show Plots checkbox renders all plots inline.Read the output
The program prints R, V, and P. Any printed value that carries a
distribution appears underlined. Hover over one to open a histogram of its
distribution, or toggle the Show Plots checkbox to render every histogram
inline.
Notice that P is a distribution too. You wrote P = pow(V, 2) / R as ordinary
arithmetic, and the Compute Engine computed the distribution of P from the
distributions of R and V for you. The
Results Panel reference
describes each of its four tabs: stdout, stderr, Build, and Runtime
Information.
Next steps
- Set command-line arguments and compilation flags, change the editor layout, or switch the theme from the toolbar.
- Run a larger project straight from GitHub with How to Run Code from a GitHub Repository.
- Trace the distribution behind individual variables with How to Run a Reference Execution.