Thursday, June 17, 2010

C Programming Notes

0 comments
[source: http://www.eskimo.com/~scs/cclass/notes/]


Introductory C Programming Class Notes, Chapter 1

Steve Summit

These notes are part of the UW Experimental College course on Introductory C Programming. They are based on notes prepared (beginning in Spring, 1995) to supplement the book The C Programming Language, by Brian Kernighan and Dennis Ritchie, or K&R as the book and its authors are affectionately known. (The second edition was published in 1988 by Prentice-Hall, ISBN 0-13-110362-8.) These notes are now (as of Winter, 1995-6) intended to be stand-alone, although the sections are still cross-referenced to those of K&R, for the reader who wants to pursue a more in-depth exposition.


Chapter 1: Introduction

Chapter 2: Basic Data Types and Operators

Chapter 3: Statements and Control Flow

Chapter 4: More about Declarations (and Initialization)

Chapter 5: Functions and Program Structure

Chapter 6: Basic I/O

Chapter 7: More Operators

Chapter 8: Strings

Chapter 9: The C Preprocessor

Chapter 10: Pointers

Chapter 11: Memory Allocation

Chapter 12: Input and Output

Chapter 13: Reading the Command Line

Chapter 14: What's Next?


Read Sequentially

Memory Allocation

0 comments

[source: http://www.eskimo.com/~scs/cclass/notes/sx11.html]

In this chapter, we'll meet malloc, C's dynamic memory allocation function, and we'll cover dynamic memory allocation in some detail.

As we begin doing dynamic memory allocation, we'll begin to see (if we haven't seen it already) what pointers can really be good for. Many of the pointer examples in the previous chapter (those which used pointers to access arrays) didn't do all that much for us that we couldn't have done using arrays. However, when we begin doing dynamic memory allocation, pointers are the only way to go, because what malloc returns is a pointer to the memory it gives us. (Due to the equivalence between pointers and arrays, though, we will still be able to think of dynamically allocated regions of storage as if they were arrays, and even to use array-like subscripting notation on them.)

You have to be careful with dynamic memory allocation. malloc operates at a pretty ``low level''; you will often find yourself having to do a certain amount of work to manage the memory it gives you. If you don't keep accurate track of the memory which malloc has given you, and the pointers of yours which point to it, it's all too easy to accidentally use a pointer which points ``nowhere'', with generally unpleasant results. (The basic problem is that if you assign a value to the location pointed to by a pointer:

 *p = 0; 
and if the pointer p points ``nowhere'', well actually it can be construed to point somewhere, just not where you wanted it to, and that ``somewhere'' is where the 0 gets written. If the ``somewhere'' is memory which is in use by some other part of your program, or even worse, if the operating system has not protected itself from you and ``somewhere'' is in fact in use by the operating system, things could get ugly.)

11.1 Allocating Memory with malloc

11.2 Freeing Memory

11.3 Reallocating Memory Blocks

11.4 Pointer Safety

Friday, June 11, 2010

Simulating the Jasper software with sim-mpfast

0 comments
The Jasper has been simulated by using the sim-mpfast tool from Dr. Manjikian

The image for the simulation was the goldenears.bmp [128*96, 36.05KB]


----------------------
Ouput from sim-mpfast
----------------------
[Bo@queen-6207ba776 ~...src/appl]$ /home/nmanjiki/RESEARCH/ARCHITECTURE/SIMULATORS/SIMPLE_SCALAR/mp_simplesim/sim-mpfast ./jasper --input /home/bo/gol
denears.bmp --output /home/bo/test2.jp2
sim-mpfast: Version 2.0 of July, 1997.
Copyright (c) 1994-1997 by Todd M. Austin. All Rights Reserved.


sim: simulation started @ Fri Jun 11 13:01:38 2010, options follow:

sim-mpfast: This program implements a fast functional simulator for
multiprocessor execution by cycling through one or more active processes.
By default, this simulator performs no instruction error checking. As a
result, instruction errors are likely to cause simulator execution errors,
possibly even a core dump.

Multiprocessor enhancements made by Naraig Manjikian, Queen's University

# -config # load configuration from a file
# -dumpconfig # dump configuration to a file
# -h false # print help message
# -v false # verbose operation
# -d false # enable debug message
-seed 1 # random number generator seed (0 for timer seed)
# -q false # initialize and terminate immediately

sim: ** starting *fast* multiprocessor functional simulation **
THE BMP FORMAT IS NOT FULLY SUPPORTED!
THAT IS, THE JASPER SOFTWARE CANNOT DECODE ALL TYPES OF BMP DATA.
IF YOU HAVE ANY PROBLEMS, PLEASE TRY CONVERTING YOUR IMAGE DATA
TO THE PNM FORMAT, AND USING THIS FORMAT INSTEAD.

sim: ** simulation statistics **
sim_num_cycles 73327984 # total number of execution cycles
sim_num_instructions # instructions executed per process
pid 0 73327984

sim_elapsed_time 1 # total simulation time in seconds
ld_text_base 0x00400000 # program text (code) segment base
ld_text_size 569984 # program text (code) size in bytes
ld_data_base 0x10000000 # program initialized data segment base
ld_data_size 66964 # program init'ed `.data' and uninit'ed `.bss' size in bytes
ld_stack_base 0x7fffc000 # program stack segment base (highest address in stack)
ld_stack_size 16384 # program initial stack size
ld_prog_entry 0x00400140 # program entry point (initial PC)
ld_environ_base 0x7fff8000 # program environment base address address
ld_target_big_endian 0 # target executable endian-ness, non-zero if big endian
mem_brk_point 0x1016b000 # data segment break point
mem_stack_min 0x7fff7510 # lowest address accessed in stack segment
mem_total_data 66k # total bytes used in init/uninit data segment
mem_total_heap 1387k # total bytes used in program heap segment
mem_total_stack 19k # total bytes used in stack segment
mem_total_mem 1472k # total bytes used in data, heap, and stack segments
sim_total_instructions 73327984 # total of all instructions executed
sim_inst_rate 73327984 # simulation speed (in insts/sec)

[Bo@queen-6207ba776 ~...src/appl]$


Friday, June 4, 2010

Creatine

0 comments
What Training Protocol Is Most Effective With Creatine?

Creatine has a very specific effect with very specific training protocols. Arbitrarily adding creatine supplementation without considering training is a huge mistake. Most studies show that a single bout of maximal or sub-maximal effort is not sufficient to elicit a response from creatine supplementation. Creatine has been shown to delay the onset of muscular fatigue during repeated bouts of work A single bout of work appears to have no improvement with creatine supplementation.

This is more than likely due to the role that creatine plays with ATP resynthesis. A single bout of work will deplete ATP stores, yet it is the regeneration of ATP that creatine supplementation affects. Creatine also increases the amount of time that maximal output can be performed - for example, it may increase the duration of a heavy lift, which means more repetitions at the same weight. All of these factors tend to indicate that two major elements are required to benefit from creatine supplementation:

Intensity, in other words, maximal or sub-maximal output duration and repetition - in other words, multiple bouts of work more than likely, these factors are what provided the success of one study, which concluded that enhanced performance and increase of lean mass were due to "higher quality training sessions." These sessions would include moderate to high intensity weights, and moderate to high volume with multiple sets.


Is Creatine Supplementation For Everyone?

Creatine supplementation may not be effective for everyone. There are possible safety concerns with creatine supplementation that will be discussed later. Due to the mechanisms by which creatine supplementation works, it may not be effective for endurance athletes to supplement with creatine. A significant percentage of the general population appears to have no response to creatine.

People on vegetarian diets seem to have a greater response to creatine, theoretically due to the lack of dietary creatine intake. From this, it can be inferred that individuals who consume large amounts of protein on a daily basis, especially red meat, will have a less significant response to creatine supplementation to the amount being ingested through typical dietary means.

It is interesting to note that most creatine research uses the standard protocol of 5 g / d for "maintenance". Anecdotal evidence suggests a high rate of success with creatine supplementation. This same evidence indicates that doses in the field are much higher than the established research protocol or recommended label amounts.

This may account for a higher anecdotal rate of success and perceived effect in the field as opposed to what is suggested in the literature. Anecdotal evidence is not a substitute for scientific research, but should be taken into account. What happens in "the real world" is much more important than what occurs in isolated, scientific trials when trying to make a "real world" application of creatine supplementation.


So What Is The Ideal Creatine Cycle?

Based on the information provided here, I propose the following cycle. The length of an ideal cycle would be relatively short. Many studies suggest that the main response to creatine supplementation occurs during the first week, with subsequent weeks of supplementation rendering no significant increase of performance or mass.

Research is very limited with regard to extended cycles at high doses, however. The cessation of ergogenic effects seems to correlate to the end of the "loading" phase. It is therefore suggested that an extended loading phase may prolong the ergogenic effects. It is also important to cycle off of the product for a prolonged period of time, due to the high dose of the cycle and the potential for contaminants in the product

Supplement Cycle

First, the cycle will be short, only 4 weeks in duration. It will involve a rapid "ramp-up" with a corresponding "ramp-down" of creatine and incorporate glutamine supplementation. Nutrition will be manipulated to favor hypertrophy during the first 3 weeks, then take advantage of super compensation and unloading for the final week.

  • First, determine a baseline creatine dose.
  • For the average individual, this is proposed to be 0.3 g / kg lean mass.
  • For vegetarians, consider 0.4 g / kg lean mass.
  • For those with predominant protein (35% of total calories or higher) in the diet, and those who consume at least 1 portion of red meat daily, consider 0.2 g / kg lean mass.
  • A discussion of glutamine is outside the scope of this article. The proposed dose is 0.3 g / kg lean mass.

An example individual weighs 180 pounds at 12% body fat. Lean mass is determined to be 158 pounds, or 72 kg. The individual has predominant protein in their diet and consumes red meat frequently. Therefore, the baseline creatine dose is computed to be 72 kg * 0.2 g / kg = 14 grams. Glutamine dose is set at 72 kg * 0.3 g / kg = 22 grams.

Glutamine will be divided into 3 doses: pre-workout, post-workout, and pre-bedtime. This equates to 7 grams pre-workout, 7 grams post-workout, and 8 grams pre-bedtime.

Creatine will be "ramped up". The first week will be 50% of the baseline. Second week is 100% of the baseline, and third week is 150% of the baseline. The unloading week is 50% of the baseline. The creatine will be consumed post-workout (75%) and pre-bedtime (25%). To summarize dosing:

    Week 1:

    Creatine: 5g post-workout, 2g before bed.
    Glutamine: 7g pre-workout, 7g post-workout, 8g before bed.

    Week 2:

    Creatine: 11g post-workout, 3g before bed.
    Glutamine: 7g pre-workout, 7g post-workout, 8g before bed.

    Week 3:

    Creatine: 16g post-workout, 5g before bed.
    Glutamine: 7g pre-workout, 7g post-workout, 8g before bed.

    Week 4:

    Creatine: 5g post-workout, 2g before bed.
    Glutamine: 7g pre-workout, 7g post-workout, 8g before bed.

    Week 5:

    All supplementation ceases (cycle is complete).


Training Cycle

In order to take advantage of various systems of muscular energetics, a holistic approach is recommended. This approach would involve a series of "mega-sets" (Dr. Fred Hatfield's "Holistic sets" or "ABC training") designed to recruit a broad spectrum of muscle fiber types for each muscle group. An example mega-set for chest might be:

    6 reps 90% intensity - explosive
    10 reps 70% intensity - moderate
    40 reps 55% intensity - slow

Intensity is expressed as a percentage of one rep max. If the subject can bench 200 pounds for a single rep, then the mega-set would be:

    6 reps at 180 pounds - explosive tempo (accelerate as quickly as possible)
    10 reps at 140 pounds - steady tempo (1 second down, 1 second up)
    40 reps at 110 pounds - slow tempo (3 seconds down, 2 seconds up).

The mega-set is performed with minimal rest - only enough time to strip the weight between mini-sets. After a mega-set, rest no more than 1 minute and repeat the mega-set for a total of three (3) times. Note that these reps are general guidelines. A person with predominantly slow-twitch (endurance) fiber in their chest would have higher reps and may only perform 2 sets, as opposed to another individual with explosive fiber in their chest.

Holistic sets are very taxing on the central nervous system. For this reason, a moderate workout should be used to extend recovery while preventing atrophy. An example schedule for this program: