<repo_name>Sakawa/cilkscreen-atom<file_sep>/examples/simple-race/simple-race.c
/*
 * simple-race.cilk
 *
 * Copyright (C) 2009-2011 Intel Corporation. All Rights Reserved.
 *
 * The source code contained or described herein and all
 * documents related to the source code ("Material") are owned by
 * Intel Corporation or its suppliers or licensors. Title to the
 * Material remains with Intel Corporation or its suppliers and
 * licensors. The Material is protected by worldwide copyright
 * laws and treaty provisions.  No part of the Material may be
 * used, copied, reproduced, modified, published, uploaded,
 * posted, transmitted, distributed,  or disclosed in any way
 * except as expressly provided in the license provided with the
 * Materials.  No license under any patent, copyright, trade
 * secret or other intellectual property right is granted to or
 * conferred upon you by disclosure or delivery of the Materials,
 * either expressly, by implication, inducement, estoppel or
 * otherwise, except as expressly provided in the license
 * provided with the Materials.
 *
 * This file implements a simple Intel Cilk Plus program with a known race
 * condition to demonstrate the Cilkscreen race detector.
 */

#include <stdlib.h>
#include <stdio.h>
#include <cilk/cilk.h>
#include <unistd.h>

int x;
void race(void) {
  x = 0;
}

void race1(void) {
  x = 1;
}

void race2(void) {
  x = 2;
}

void race3(void) {
  x = 3;
}

void test(void) {
  cilk_spawn race();
  cilk_spawn race1();
}

void test1(void) {
  cilk_for (int i = 0; i < 10; i++) {
    x = i;
  }
}

void test2(void) {
  cilk_spawn race2();
  cilk_spawn race3();
}

int main(int argc, char *argv[]) {
  for (int i = 0; i < 100000; i++) {
   test();
  }

  sleep(2); // artificially add sleep time

  test1();
  test2();

  printf("done: x = %d\n", x);
  return 0;
}
<file_sep>/examples/simple-race/Makefile
#
# Makefile for the simple-race example.
#

CXX = clang
CXXFLAGS = -O3 -ftapir
DFLAGS = -O0 -ftapir -g -fsanitize=cilk

TARGET = simple-race
SRC = simple-race.c

.PHONY: all
all: $(TARGET)

$(TARGET): $(SRC)
	$(CXX) -o $@ $(CXXFLAGS) $^

.PHONY: cilksan
cilksan: $(SRC)
	$(CXX) -o cilksan $(DFLAGS) $^
	./cilksan

.PHONY: clean
clean:
	rm -f $(TARGET) cilkscreen
<file_sep>/README.md
# Cilkpride package (beta)

This package is designed to help programmers using the Cilk threading library keep track of their code as they are writing code in Atom. Currently, the plugin automatically runs cilksan in the background and report the results to the users, notifying them if race conditions appear. Results are refreshed every time a file is modified, so that users are told immediately if race conditions exist, and can take the appropriate steps to correct the error.

There are also some added features designed for MIT's 6.172 class, allowing students to edit code locally but evaluate their applications remotely on Athena.

## Setting up the package
In order to notify the package that you are writing a project with Cilk, you must place a configuration file `cilkpride-conf.json` in the top-level directory of the project. The configuration file should have a few settings:
```JSON
{
  "username": "Username for SSH login, usually your Athena login",
  "remoteBaseDir": "full directory path of the project directory on the remote instance",
  "cilksanCommand": "Enter a Make command that will compile (with cilksan enabled) and run the executable.",

  "sshEnabled": true,
  "hostname": "Hostname for running cilk on a remote server - usually athena.dialup.mit.edu",
  "port": 22,
  "launchInstance": "boolean: only true if you want to use 6.172's Azure VM",
  "localBaseDir": "Full directory path of the project directory on your local computer (ie C:/Users/me/Desktop/my-project)",
  "remoteBaseDir": "Full directory path of the project directory on the remote instance (ie /afs/athena.mit.edu/user/g/c/gchau/my-project)",
  "syncIgnoreFile": ["/cilkpride-conf.json", "other files to ignore"],
  "syncIgnoreDir": ["/.git", "/log.awsrun", "/log.cqrun", "other directories to ignore"]
}
```
You can automatically generate a template configuration file in a folder by pressing "Register Cilk project" on the status bar, located to the bottom-left of the Atom window. Once this is done, the package will periodically run cilksan on the executable generated by the command specified in `cilksanCommand` - make sure that this command both makes an cilksan-enabled executable and runs it. The status bar icon will show the package status for the current file open.

Note: If you are using SSH (which you probably are), every time a file is modified, the plugin will upload it to the remote server and try to recompile it. You can also sync local -> remote by pressing CTRL+ALT+G, while syncing remote -> local can be done by pressing CTRL+ALT+J. Beware as these commands will overwrite your files and there is no confirmation before doing so.
