Esempio n. 1
0
int main (int argc, char **argv) {
	int key, bd, ret;

	if (argc < 2) {
		printf("Usage: releaser <barrier_key> \n");
		return -1;
	}
	
	key = atoi(argv[1]);
	
	bd = get_barrier(key, 0);
	if (bd == -1) {
		printf("Error: the barrier doesn't exist \n");
		return -1;
	}
	
	ret = release_barrier(bd);
	
	if (ret == -1) {
		printf("Error: impossible to release the barrier\n");
		return -1;
	}
	
	printf("Barrier correctly released \n");
	
	return 0;
}
Esempio n. 2
0
    //----------------------------------------------------------------------------
    void find_barrier()
    {
        hpx::id_type here = hpx::find_here();
        uint64_t rank = hpx::naming::get_locality_id_from_id(here);

        if (rank != 0) {
            hpx::id_type id;
            while(!id)
            {
                id = hpx::agas::resolve_name_sync(HPX_EXAMPLES_MINI_GHOST_BARRIER);
            }
            get_barrier() = hpx::lcos::barrier(id);
        }
    }
Esempio n. 3
0
    void create_barrier()
    {
        hpx::id_type here = hpx::find_here();
        uint64_t rank = hpx::naming::get_locality_id_from_id(here);

        // create a barrier we will use at the start and end of each run to
        // synchronize
        if(0 == rank) {
            uint64_t nranks = hpx::get_num_localities().get();
            hpx::lcos::barrier & b = get_barrier();
            b.create(hpx::find_here(), nranks);
            hpx::agas::register_name_sync(HPX_EXAMPLES_MINI_GHOST_BARRIER, b.get_gid());
        }
    }
Esempio n. 4
0
int main(int argc, char **argv) {
	int key, tag, bd, ret;

	if (argc < 3) {
		printf("Usage: sleeper <barrier_key> <tag> \n");
		return -1;
	}
	key = atoi(argv[1]);
	tag = atoi(argv[2]);
	
	bd = get_barrier(key, O_CREAT);
	
	printf("Yawn, going to sleep on tag %d \n", tag);
	
	ret = sleep_on_barrier(bd, tag);
	if (ret == -1) {
		printf("Error: can't spleep on that barrier with that tag \n");
		return -1;
	}
	
	printf("I'm awake! \n");

	return 0;
}
Esempio n. 5
0
File: orcc.c Progetto: mojaves/orc
int
main (int argc, char *argv[])
{
  char *code;
  int i;
  char *output_file = NULL;
  char *input_file = NULL;
  char *include_file = NULL;
  char *compat_version = VERSION;
  FILE *output;
  OrcParseError **errors = NULL;
  int n_errors = 0;

  orc_init ();

  for(i=1;i<argc;i++) {
    if (strcmp(argv[i], "--header") == 0) {
      mode = MODE_HEADER;
    } else if (strcmp(argv[i], "--implementation") == 0) {
      mode = MODE_IMPL;
    } else if (strcmp(argv[i], "--test") == 0) {
      mode = MODE_TEST;
    } else if (strcmp(argv[i], "--assembly") == 0) {
      mode = MODE_ASSEMBLY;
    } else if (strcmp(argv[i], "--parse-only") == 0) {
      mode = MODE_PARSE;
    } else if (strcmp(argv[i], "--include") == 0) {
      if (i+1 < argc) {
        include_file = argv[i+1];
        i++;
      } else {
        help();
      }
    } else if (strcmp (argv[i], "--output") == 0 ||
        strcmp(argv[i], "-o") == 0) {
      if (i+1 < argc) {
        output_file = argv[i+1];
        i++;
      } else {
        help();
      }
    } else if (strcmp(argv[i], "--target") == 0 ||
        strcmp(argv[i], "-t") == 0) {
      if (i+1 < argc) {
        target = argv[i+1];
        i++;
      } else {
        help();
      }
    } else if (strcmp(argv[i], "--inline") == 0) {
      use_inline = TRUE;
    } else if (strcmp(argv[i], "--no-inline") == 0) {
      use_inline = FALSE;
    } else if (strcmp(argv[i], "--internal") == 0) {
      use_internal = TRUE;
    } else if (strcmp(argv[i], "--no-internal") == 0) {
      use_internal = FALSE;
    } else if (strcmp(argv[i], "--init-function") == 0) {
      if (i+1 < argc) {
        init_function = argv[i+1];
        i++;
      } else {
        help();
      }
    } else if (strcmp(argv[i], "--help") == 0 ||
        strcmp(argv[i], "-h") == 0) {
      help ();
    } else if (strcmp(argv[i], "--verbose") == 0 ||
        strcmp(argv[i], "-v") == 0) {
      verbose = 1;
    } else if (strcmp(argv[i], "--version") == 0) {
      fprintf(stderr, "Orc Compiler " PACKAGE_VERSION "\n");
      exit (0);
    } else if (strcmp(argv[i], "--compat") == 0) {
      if (i+1 < argc) {
        compat_version = argv[i+1];
        i++;
      } else {
        help();
      }
    } else if (strcmp(argv[i], "--lazy-init") == 0) {
      use_lazy_init = TRUE;
    } else if (strcmp(argv[i], "--no-backup") == 0) {
      use_backup = FALSE;
    } else if (strncmp(argv[i], "-", 1) == 0) {
      fprintf(stderr, "Unknown option: %s\n", argv[i]);
      exit (1);
    } else {
      if (input_file == NULL) {
        input_file = argv[i];
      } else {
        fprintf(stderr, "More than one input file specified: %s\n", argv[i]);
        exit (1);
      }
    }
  }

  if (input_file == NULL) {
    fprintf(stderr, "No input file specified\n");
    exit (1);
  }

  if (mode == MODE_ASSEMBLY && orc_target_get_by_name (target) == NULL) {
    fprintf(stderr, "Unknown target \"%s\"\n", target);
    exit (1);
  }

  if (compat_version) {
    int major, minor, micro, nano = 0;
    int n;

    n = sscanf (compat_version, "%d.%d.%d.%d", &major, &minor, &micro, &nano);

    if (n < 3) {
      fprintf(stderr, "Unknown version \"%s\"\n", compat_version);
      exit (1);
    }

    compat = ORC_VERSION(major,minor,micro,nano);
    if (compat < ORC_VERSION(0,4,5,0)) {
      fprintf(stderr, "Compatibility version \"%s\" not supported.  Minimum 0.4.5\n",
          compat_version);
      exit (1);
    }
  }
  if (compat >= ORC_VERSION(0,4,11,1)) {
    use_code = TRUE;
  }

  if (output_file == NULL) {
    switch (mode) {
      case MODE_IMPL:
        output_file = "out.c";
        break;
      case MODE_HEADER:
        output_file = "out.h";
        break;
      case MODE_TEST:
        output_file = "out_test.c";
        break;
      case MODE_ASSEMBLY:
        output_file = "out.s";
        break;
    }
  }

  code = read_file (input_file);
  if (!code) {
    fprintf(stderr, "Could not read input file: %s\n", input_file);
    exit(1);
  }

  orc_parse_code (code, &programs, &n_programs, &errors, &n_errors);
  if (n_errors > 0) {
    int i;
    for (i=0;i<n_errors;i++) {
      fprintf(stderr, "%s @ %i: error: %s\n", errors[i]->source, errors[i]->line_number, errors[i]->text);
    }
    exit (1);
  }

  if (programs == NULL) {
    if (verbose) {
      fprintf(stderr, "no programs found\n");
    }
    exit(1);
  }

  if (verbose) {
    fprintf(stderr, "%i program%s parsed\n",
           n_programs, (n_programs > 1) ?"s" :"");
  }

  if (mode == MODE_PARSE) {
    exit (0);
  }

  if (init_function == NULL) {
    init_function = orc_parse_get_init_function (programs[0]);
  }

  if (init_function == NULL) {
    use_lazy_init = TRUE;
  }

  output = fopen (output_file, "w");
  if (!output) {
    fprintf(stderr, "Could not write output file: %s\n", output_file);
    exit(1);
  }

  fprintf(output, "\n");
  fprintf(output, "/* autogenerated from %s */\n", my_basename(input_file));
  fprintf(output, "\n");

  if (mode == MODE_IMPL) {
    fprintf(output, "#ifdef HAVE_CONFIG_H\n");
    fprintf(output, "#include \"config.h\"\n");
    fprintf(output, "#endif\n");
    if (include_file) {
      fprintf(output, "#include <%s>\n", include_file);
    }
    fprintf(output, "\n");
    fprintf(output, "%s", orc_target_c_get_typedefs ());
    fprintf(output, "\n");
    fprintf(output, "#ifndef DISABLE_ORC\n");
    fprintf(output, "#include <orc/orc.h>\n");
    fprintf(output, "#endif\n");
    for(i=0;i<n_programs;i++){
      output_code_header (programs[i], output);
    }
    if (init_function) {
      fprintf(output, "\n");
      fprintf(output, "void %s (void);\n", init_function);
    }
    fprintf(output, "\n");
    fprintf(output, "%s", orc_target_get_asm_preamble ("c"));
    fprintf(output, "\n");
    for(i=0;i<n_programs;i++){
      output_code (programs[i], output);
    }
    fprintf(output, "\n");
    if (init_function) {
      output_init_function (output);
      fprintf(output, "\n");
    }
  } else if (mode == MODE_HEADER) {
    char *barrier = get_barrier (output_file);

    fprintf(output, "#ifndef _%s_\n", barrier);
    fprintf(output, "#define _%s_\n", barrier);
    free (barrier);
    fprintf(output, "\n");
    if (include_file) {
      fprintf(output, "#include <%s>\n", include_file);
    }
    fprintf(output, "\n");
    fprintf(output, "#ifdef __cplusplus\n");
    fprintf(output, "extern \"C\" {\n");
    fprintf(output, "#endif\n");
    fprintf(output, "\n");
    if (init_function) {
      fprintf(output, "void %s (void);\n", init_function);
      fprintf(output, "\n");
    }
    fprintf(output, "\n");
    if (!use_inline) {
      fprintf(output, "\n");
      fprintf(output, "%s", orc_target_c_get_typedefs ());
      for(i=0;i<n_programs;i++){
        output_code_header (programs[i], output);
      }
    } else {
      fprintf(output, "\n");
      fprintf(output, "#include <orc/orc.h>\n");
      fprintf(output, "\n");
      for(i=0;i<n_programs;i++){
        output_code_execute (programs[i], output, TRUE);
      }
    }
    fprintf(output, "\n");
    fprintf(output, "#ifdef __cplusplus\n");
    fprintf(output, "}\n");
    fprintf(output, "#endif\n");
    fprintf(output, "\n");
    fprintf(output, "#endif\n");
    fprintf(output, "\n");
  } else if (mode == MODE_TEST) {
    fprintf(output, "#include <stdio.h>\n");
    fprintf(output, "#include <string.h>\n");
    fprintf(output, "#include <stdlib.h>\n");
    fprintf(output, "#include <math.h>\n");
    if (include_file) {
      fprintf(output, "#include <%s>\n", include_file);
    }
    fprintf(output, "\n");
    fprintf(output, "%s", orc_target_c_get_typedefs ());
    fprintf(output, "#include <orc/orc.h>\n");
    fprintf(output, "#include <orc-test/orctest.h>\n");
    fprintf(output, "%s", orc_target_get_asm_preamble ("c"));
    fprintf(output, "\n");
    if (use_backup) {
      for(i=0;i<n_programs;i++){
        fprintf(output, "/* %s */\n", programs[i]->name);
        output_code_backup (programs[i], output);
      }
    }
    fprintf(output, "\n");
    fprintf(output, "static int quiet = 0;\n");
    fprintf(output, "static int benchmark = 0;\n");
    fprintf(output, "\n");
    fprintf(output, "static void help (const char *argv0)\n");
    fprintf(output, "{\n");
    fprintf(output, "  fprintf(stderr, \"Usage:\\n\");\n");
    fprintf(output, "  fprintf(stderr, \"  %%s [OPTION]\\n\", argv0);\n");
    fprintf(output, "  fprintf(stderr, \"Help Options:\\n\");\n");
    fprintf(output, "  fprintf(stderr, \"  -h, --help          Show help options\\n\");\n");
    fprintf(output, "  fprintf(stderr, \"Application Options:\\n\");\n");
    fprintf(output, "  fprintf(stderr, \"  -b, --benchmark     Run benchmark and show results\\n\");\n");
    fprintf(output, "  fprintf(stderr, \"  -q, --quiet         Don't output anything except on failures\\n\");\n");
    fprintf(output, "\n");
    fprintf(output, "  exit(0);\n");
    fprintf(output, "}\n");
    fprintf(output, "\n");
    fprintf(output, "int\n");
    fprintf(output, "main (int argc, char *argv[])\n");
    fprintf(output, "{\n");
    fprintf(output, "  int error = FALSE;\n");
    fprintf(output, "  int i;\n");
    fprintf(output, "\n");
    fprintf(output, "  orc_test_init ();\n");
    fprintf(output, "\n");
    fprintf(output, "  for(i=1;i<argc;i++) {\n");
    fprintf(output, "    if (strcmp(argv[i], \"--help\") == 0 ||\n");
    fprintf(output, "      strcmp(argv[i], \"-h\") == 0) {\n");
    fprintf(output, "      help(argv[0]);\n");
    fprintf(output, "    } else if (strcmp(argv[i], \"--quiet\") == 0 ||\n");
    fprintf(output, "      strcmp(argv[i], \"-q\") == 0) {\n");
    fprintf(output, "      quiet = 1;\n");
    fprintf(output, "      benchmark = 0;\n");
    fprintf(output, "    } else if (strcmp(argv[i], \"--benchmark\") == 0 ||\n");
    fprintf(output, "      strcmp(argv[i], \"-b\") == 0) {\n");
    fprintf(output, "      benchmark = 1;\n");
    fprintf(output, "      quiet = 0;\n");
    fprintf(output, "    }\n");
    fprintf(output, "  }\n");
    fprintf(output, "\n");
    for(i=0;i<n_programs;i++){
      output_code_test (programs[i], output);
    }
    fprintf(output, "\n");
    fprintf(output, "  if (error) {\n");
    fprintf(output, "    return 1;\n");
    fprintf(output, "  };\n");
    fprintf(output, "  return 0;\n");
    fprintf(output, "}\n");
  } else if (mode == MODE_ASSEMBLY) {
    fprintf(output, "%s", orc_target_get_asm_preamble (target));
    for(i=0;i<n_programs;i++){
      output_code_assembly (programs[i], output);
    }
  }

  fclose (output);

  if (error) {
    remove (output_file);
    exit(1);
  }

  return 0;
}
Esempio n. 6
0
 void barrier_wait()
 {
     HPX_ASSERT(get_barrier().get_gid());
     get_barrier().wait();
 }