<commit_before>/*************************************************************************************/
/*      Copyright 2010 Barcelona Supercomputing Center                               */
/*      Copyright 2009 Barcelona Supercomputing Center                               */
/*                                                                                   */
/*      This file is part of the NANOS++ library.                                    */
/*                                                                                   */
/*      NANOS++ is free software: you can redistribute it and/or modify              */
/*      it under the terms of the GNU Lesser General Public License as published by  */
/*      the Free Software Foundation, either version 3 of the License, or            */
/*      (at your option) any later version.                                          */
/*                                                                                   */
/*      NANOS++ is distributed in the hope that it will be useful,                   */
/*      but WITHOUT ANY WARRANTY; without even the implied warranty of               */
/*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                */
/*      GNU Lesser General Public License for more details.                          */
/*                                                                                   */
/*      You should have received a copy of the GNU Lesser General Public License     */
/*      along with NANOS++.  If not, see <http://www.gnu.org/licenses/>.             */
/*************************************************************************************/

#include <assert.h>

#include "system.hpp"
#include "basethread.hpp"
#include "schedule.hpp"
#include "smpdd.hpp"
#include "chpl_nanos.h"

// // TODO: include chpl headers?
// typedef char * chpl_string;
// typedef bool chpl_bool;
// typedef void (*chpl_fn_p) (void *);
// typedef void * chpl_task_list_p;
// typedef int chpl_fn_int_t;
// typedef int chpl_taskID_t;

extern chpl_fn_p chpl_ftable[];

static uint64_t taskCallStackSize;

using namespace nanos;
using namespace nanos::ext;

static bool chapel_hooked = false;

void nanos_chapel_pre_init ( void * dummy )
{
   sys.setDelayedStart(true);
   chapel_hooked = true;
}

//
// Used for debugging purposes only
//
static int32_t chpl_localeID = -1;

#define PRINTF_DEF printf

#ifndef BRAD_DEBUGGING
#define NANOX_SANITY_CHECK(routine)
#else
#define NANOX_SANITY_CHECK(routine) \
  if (nanos::myThread == NULL) { fprintf(stderr, "[%d:%ld] non-Nanox thread detected in chpl_task_%s()\n", chpl_localeID, pthread_self(), #routine); } \
  else { fprintf(stderr, "[%d:%d:%ld] thread in chpl_task_%s()\n", chpl_localeID, (nanos::myThread)->getId(), pthread_self(), #routine); }
#endif

//
// interface function with begin-statement
//
void chpl_task_begin(chpl_fn_p fp,
                     void* a,
                     chpl_bool ignore_serial,  // always add task to pool
                     chpl_bool serial_state,
                     chpl_task_list_p ltask) 
{
  NANOX_SANITY_CHECK(begin);
   assert(!ltask);

   WD * wd = NEW WD( NEW SMPDD( fp ), 0, 0, a );
   sys.submit(*wd);
}

// Tasks

void nanos_chpl_task_init(int32_t maxThreadsPerLocale, uint64_t callStackSize, 
                          int32_t init_chpl_localeID) {
   NANOX_SANITY_CHECK(init);

   fatal_cond0(!chapel_hooked, "Chapel layer has not been correctly initialized");

   sys.setInitialMode( System::POOL );
   sys.setUntieMaster(true);
   sys.setNumPEs(maxThreadsPerLocale);
   sys.start();

   NANOX_SANITY_CHECK(init);

   //
   // TODO: Should verify that callStackSize is a reasonable value and
   // use it to set Nanos++'s task callstack size.
   //
   taskCallStackSize = callStackSize;

   chpl_localeID = init_chpl_localeID;

/*  tp = chpl_alloc(sizeof(thread_private_data_t), CHPL_RT_MD_THREAD_PRIVATE_DATA, 0, 0);
  threadlayer_set_thread_private_data(tp);
  tp->serial_state = false;*/
}


void chpl_task_callMain(void (*chpl_main)(void)) {
  NANOX_SANITY_CHECK(callMain);
  chpl_main();
}

void chpl_task_exit()<commit_msg>Hard-coding the number of Nanos++ tasks to 4 for the time being<commit_after>/*************************************************************************************/
/*      Copyright 2010 Barcelona Supercomputing Center                               */
/*      Copyright 2009 Barcelona Supercomputing Center                               */
/*                                                                                   */
/*      This file is part of the NANOS++ library.                                    */
/*                                                                                   */
/*      NANOS++ is free software: you can redistribute it and/or modify              */
/*      it under the terms of the GNU Lesser General Public License as published by  */
/*      the Free Software Foundation, either version 3 of the License, or            */
/*      (at your option) any later version.                                          */
/*                                                                                   */
/*      NANOS++ is distributed in the hope that it will be useful,                   */
/*      but WITHOUT ANY WARRANTY; without even the implied warranty of               */
/*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                */
/*      GNU Lesser General Public License for more details.                          */
/*                                                                                   */
/*      You should have received a copy of the GNU Lesser General Public License     */
/*      along with NANOS++.  If not, see <http://www.gnu.org/licenses/>.             */
/*************************************************************************************/

#include <assert.h>

#include "system.hpp"
#include "basethread.hpp"
#include "schedule.hpp"
#include "smpdd.hpp"
#include "chpl_nanos.h"

// // TODO: include chpl headers?
// typedef char * chpl_string;
// typedef bool chpl_bool;
// typedef void (*chpl_fn_p) (void *);
// typedef void * chpl_task_list_p;
// typedef int chpl_fn_int_t;
// typedef int chpl_taskID_t;

extern chpl_fn_p chpl_ftable[];

static uint64_t taskCallStackSize;

using namespace nanos;
using namespace nanos::ext;

static bool chapel_hooked = false;

void nanos_chapel_pre_init ( void * dummy )
{
   sys.setDelayedStart(true);
   chapel_hooked = true;
}

//
// Used for debugging purposes only
//
static int32_t chpl_localeID = -1;

#define PRINTF_DEF printf

#ifndef BRAD_DEBUGGING
#define NANOX_SANITY_CHECK(routine)
#else
#define NANOX_SANITY_CHECK(routine) \
  if (nanos::myThread == NULL) { fprintf(stderr, "[%d:%ld] non-Nanox thread detected in chpl_task_%s()\n", chpl_localeID, pthread_self(), #routine); } \
  else { fprintf(stderr, "[%d:%d:%ld] thread in chpl_task_%s()\n", chpl_localeID, (nanos::myThread)->getId(), pthread_self(), #routine); }
#endif

//
// interface function with begin-statement
//
void chpl_task_begin(chpl_fn_p fp,
                     void* a,
                     chpl_bool ignore_serial,  // always add task to pool
                     chpl_bool serial_state,
                     chpl_task_list_p ltask) 
{
  NANOX_SANITY_CHECK(begin);
   assert(!ltask);

   WD * wd = NEW WD( NEW SMPDD( fp ), 0, 0, a );
   sys.submit(*wd);
}

// Tasks

void nanos_chpl_task_init(int32_t maxThreadsPerLocale, uint64_t callStackSize, 
                          int32_t init_chpl_localeID) {
   NANOX_SANITY_CHECK(init);

   fatal_cond0(!chapel_hooked, "Chapel layer has not been correctly initialized");

   sys.setInitialMode( System::POOL );
   sys.setUntieMaster(true);
   sys.setNumPEs(4);
   sys.start();

   NANOX_SANITY_CHECK(init);

   //
   // TODO: Should verify that callStackSize is a reasonable value and
   // use it to set Nanos++'s task callstack size.
   //
   taskCallStackSize = callStackSize;

   chpl_localeID = init_chpl_localeID;

/*  tp = chpl_alloc(sizeof(thread_private_data_t), CHPL_RT_MD_THREAD_PRIVATE_DATA, 0, 0);
  threadlayer_set_thread_private_data(tp);
  tp->serial_state = false;*/
}


void chpl_task_callMain(void (*chpl_main)(void)) {
  NANOX_SANITY_CHECK(callMain);
  chpl_main();
}

void chpl_task_exit()
{'fraction_non_alphanumeric': 0.13752997601918465, 'fraction_numerical': 0.006235011990407674, 'mean_word_length': 2.040831206707984, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1790405', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2339, 'n_words': 634}